• Stars
    star
    363
  • Rank 117,374 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An implementation of the WHATWG URL Standard in JavaScript

whatwg-url

whatwg-url is a full implementation of the WHATWG URL Standard. It can be used standalone, but it also exposes a lot of the internal algorithms that are useful for integrating a URL parser into a project like jsdom.

Specification conformance

whatwg-url is currently up to date with the URL spec up to commit eee49fd.

For file: URLs, whose origin is left unspecified, whatwg-url chooses to use a new opaque origin (which serializes to "null").

whatwg-url does not yet implement any encoding handling beyond UTF-8. That is, the encoding override parameter does not exist in our API.

API

The URL and URLSearchParams classes

The main API is provided by the URL and URLSearchParams exports, which follows the spec's behavior in all ways (including e.g. USVString conversion). Most consumers of this library will want to use these.

Low-level URL Standard API

The following methods are exported for use by places like jsdom that need to implement things like HTMLHyperlinkElementUtils. They mostly operate on or return an "internal URL" or "URL record" type.

The stateOverride parameter is one of the following strings:

The URL record type has the following API:

These properties should be treated with care, as in general changing them will cause the URL record to be in an inconsistent state until the appropriate invocation of basicURLParse is used to fix it up. You can see examples of this in the URL Standard, where there are many step sequences like "4. Set context object’s url’s fragment to the empty string. 5. Basic URL parse input with context object’s url as url and fragment state as state override." In between those two steps, a URL record is in an unusable state.

The return value of "failure" in the spec is represented by null. That is, functions like parseURL and basicURLParse can return either a URL record or null.

whatwg-url/webidl2js-wrapper module

This module exports the URL and URLSearchParams interface wrappers API generated by webidl2js.

Development instructions

First, install Node.js. Then, fetch the dependencies of whatwg-url, by running from this directory:

npm install

To run tests:

npm test

To generate a coverage report:

npm run coverage

To build and run the live viewer:

npm run prepare
npm run build-live-viewer

Serve the contents of the live-viewer directory using any web server.

Supporting whatwg-url

The jsdom project (including whatwg-url) is a community-driven project maintained by a team of volunteers. You could support us by:

  • Getting professional support for whatwg-url as part of a Tidelift subscription. Tidelift helps making open source sustainable for us while giving teams assurances for maintenance, licensing, and security.
  • Contributing directly to the project.

More Repositories

1

jsdom

A JavaScript implementation of various web standards, for use with Node.js
JavaScript
20,347
star
2

cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
JavaScript
107
star
3

js-symbol-tree

Turn any collection of objects into its own efficient tree or linked list using Symbol
JavaScript
103
star
4

abab

Perfectly spec-compliant atob and btoa implementations
93
star
5

whatwg-mimetype

Parses, serializes, and manipulates MIME types, according to the WHATWG MIME Sniffing Standard
JavaScript
81
star
6

webidl2js

Auto-generate JS class structures for Web IDL specifications
JavaScript
79
star
7

data-urls

Parse data: URLs
JavaScript
71
star
8

jsdom-devtools-formatter

Make jsdom elements look like real DOM elements in Chrome Devtools console
JavaScript
54
star
9

tr46

An implementation of the Unicode UTS #46: Unicode IDNA Compatibility Processing.
JavaScript
32
star
10

webidl-conversions

Implements the Web IDL algorithms for converting to and from JavaScript values
JavaScript
31
star
11

whatwg-encoding

Decode strings according to the WHATWG Encoding Standard
JavaScript
23
star
12

w3c-xmlserializer

An XML serializer that follows the W3C specification.
JavaScript
21
star
13

domexception

An implementation of the DOMException class from browsers
21
star
14

html-encoding-sniffer

Sniff the encoding from a HTML byte stream
JavaScript
19
star
15

xml-name-validator

Validates whether a string matches the production for an XML name or qualified name
JavaScript
15
star
16

w3c-hr-time

An implementation of the W3C High Resolution Time Level 2 specification.
11
star
17

.github

Miscellaneous GitHub configurations
2
star