@fastly/as-url
AssemblyScript library to implement the WHATWG URL Standard, similar to the JavaScript URL Web API.
Installation
@fastly/as-url
is available as a npm package. You can install @fastly/as-url
in your AssemblyScript project by running:
npm install --save @fastly/as-url
Quick Start
This package attempts to be an implementation of the JavaScript URL Web API. Thus, the JavaScript URL Web API documentation could also act as a helpful getting started guide. However, while most features are implemented, some features are still in development (e.g URLSearchParams
). Please see the reference documentation in the reference-docs
directory for the full documentation.
import { URL } from '@fastly/as-url';
// Parse a complex absolute URL
const myComplexUrlString = 'https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash';
const url = new URL(myComplexUrlString);
let protocol = url.protocol; // "https:"
let username = url.username; // "user"
let password = url.password; // "pass"
let hostname = url.hostname; // "sub.example.com"
let port = url.port; // "8080"
let host = url.host; // "sub.example.com:8080"
let origin = url.origin // "https://sub.example.com:8080"
let pathname = url.pathname; // "/p/a/t/h"
let search = url.search; // "?query=string"
let hash = url.hash; // "#hash"
let href = url.href; // "https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash"
// Parse a relative URL
const relativeUrl = new URL(
"../../p/a/t/h?query=string#hash",
"https://fastly.com/path1/path2"
);
let relativeUrlHref = relativeUrl.href; // https://fastly.com/p/a/t/h?query=string#hash
Also, feel free to look through the tests for additional examples.
Reference API
The Reference API documentation can be found in the reference-docs/
directory.
Changelog
The changelog can be found here.
Security
If you happen to find any security issues, please see the Fastly Security Reporting Page, or feel free to send an email to: security@fastly.com
We plan to disclose any found security vulnerabilites per the npm security reporting guidelines. Note that communications related to security issues in Fastly-maintained OSS as described here are distinct from Fastly Security Advisories.
Motivation
This library was built to be used as a dependency for @fastly/as-compute
.
This library is based on the WHATWG URL Standard and strives to match the JavaScript URL Web API that Node.js 's URL library implements.
However, the goal of this library is not to be a 1-to-1 implementation of the Node URL API. The goal of this library is to enable sharing very similar, if not identical, URL code between Fastly's Compute@Edge platform and popular JavaScript platforms like Web Browsers and Node.
License
Apache-2.0 WITH LLVM-exception