Is this value a WHATWG-standard URL object?
const assert = require('assert');
const isURL = require('is-whatwg-url');
const url = new URL('about:blank');
assert.equal(isURL(url), true);
assert.equal(isURL(Object.assign({ constructor: URL, __proto__: URL.prototype }, url)), false);
Engine | ✅ toString and/or getters brand check | (no brand check) |
(no brand check) |
❌ non-constructor URL |
❌ no URL |
---|---|---|---|---|---|
chrome | >= 32 | 23 - 31 | <= 22 | ||
safari | >= 6.2 | <= 6.1 | |||
firefox | >= 26 | 4 - 25 | <= 3.6 | ||
node | >= 20 | 6 - 20 | < 6 |
- firefox 26 - 28: toString does not brand check, but accessors do
- chrome 32-44, firefox 26+, node 20.0 - 20.11: the error message is bad/unclear/inaccurate, but a TypeError is correctly thrown
- node from v6 - 20, inclusive, does not properly brand check, but instead looks for a URLContext object appearing behind a public non-global symbol (
Object.getOwnPropertySymbols(new URL('about:blank'))[0]
). As such, this library uses the most rigorous heuristics possible to determine if something is a URL.- node v6 - v18.16, inclusive, also looks for public non-global symbol (
Object.getOwnPropertySymbols(new URL('about:blank'))[1]
). property that is the same value as.searchParams
on the URL instance
- node v6 - v18.16, inclusive, also looks for public non-global symbol (
- prior to node v10.0,
URL
was not a global, but is accessible withrequire('url').URL
Simply clone the repo, npm install
, and run npm test