Skip to content

Is this value a WHATWG-standard URL object?

License

Notifications You must be signed in to change notification settings

inspect-js/is-whatwg-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

is-whatwg-url Version Badge

github actions coverage License Downloads

npm badge

Is this value a WHATWG-standard URL object?

Example

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);

native engine version support matrix

Engine ✅ toString and/or getters brand check ⚠️ non-standard URLContext Symbol property
(no brand check)
⚠️ no methods
(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

Caveats:

  • 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
  • prior to node v10.0, URL was not a global, but is accessible with require('url').URL

Tests

Simply clone the repo, npm install, and run npm test

About

Is this value a WHATWG-standard URL object?

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published