
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
URL library that implements a reference resolution algorithm for WHATWG URLs
An URL manipulation library that supports URL records, relative URLs, reference resolution and a number of other elementary operations on URLs in a way that is compatible with the WHATWG URL Standard.
This library serves as a reference implementation for this URL Specification, which is an alternative URL specification that rephrases and generalises the WHATWG URL Standard to add support for relative URLs, reference resolution and a number of other elementary operations, as wel as restoring a formal grammar.
Always feel free to ask questions. If you wish, you may file an issue for a question.
The URLReference project is now available! This project provides an URLReference class that supports relative URLs whilst maintaining an API that is similar to the WHATWG URL class.
An other alternative is my reurl library, which wraps around spec-url to provide an API for working with immutable URL objects.
In this implementation an URL is modeled as a plain JavaScript object with the following optional attributes:
If present, dirs is an non-empty array of strings; host is a Host (see below) and all other attributes are strings. The string valued attributes are subject to the constraints as described in my URL Specification.
A Host is either an URLIPv6Address, an URLDomainName, an URLIPv4Address, or an opaque host string.
The URL Specification models URLs as ordered sequences of components, "with at most one component per type, except for dir componens, of which it may have any amount". Futhermore, the username, password, host and port are nested inside an authority component.
In this this library URLs are modeled as plain JavaScript objects. The dir components, if present, are collected into a single dirs array, and the authority, if present, is expanded by setting any of its user, pass, host and port constituents directly on the url object itself.
There is a one-to-one correspondence between this representation and sequences of components as defined in the URL specification.
The rebase function is the preferred method for composing URLs. It can be thought of as a resolve function for relative URLs. The rebase function does not attempt to parse opaque hosts as a domain, and does not enforce additional requirements on the authority.
The resolve function is similar to rebase but it always produces an absolute URL, or throws an error if it is unable to do so. It coerces special URLs to have an authority, and parses their hosts as a domain. It enforces that file URLs do not have a user, pass nor port. NB this converts the first non-empty path segment of a web-URL to an authority if this is needed.
Towards a simple API without modes; towards loosening the constraints on the model a bit, and enforcing them in the resolution operation:
FAQs
URL library that implements a reference resolution algorithm for WHATWG URLs
The npm package spec-url receives a total of 1,713 weekly downloads. As such, spec-url popularity was classified as popular.
We found that spec-url demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.