iso-url

2019-08-16

Isomorphic/Universal WHATWG URL API with some support legacy node URL API

iso-url NPM VersionNPM DownloadsNPM LicenseBuild Statuscodecov

Isomorphic/Univeral WHATWG URL API with some support legacy node URL API

This package is a universal wrapper for node urland browser window.URL with support for legacy url.parseproperties in the URL instance and defaults for base to support relative urls like url.parse. Node URL docs.

Caveats

No support for querystring objects. Use URLSearchParams.

Install

$ npm install iso-url

Usage

const { URL, URLSearchParams, format, relative } = require('iso-url');

const url = new isoUrl('http://localhost/unicorns');
const newSearchParams = new URLSearchParams(url.searchParams);

API

new URL(url, [base])

input

Type: string

The absolute or relative input URL to parse. If input is relative, then base is required. If input is absolute, the base is ignored.

base

Type: string|URL
Default: https://localhostin node and self.location.protocol + '//' + self.location.hostin the browser.

The base URL to resolve against if the input is not absolute.

format(url, [options])

Same as https://nodejs.org/api/url.html#url_url_format_url_options

relative(url, [location], [protocalMap], [defaultProtocol])

Same as https://github.com/dominictarr/relative-urlbut doesn't support this syntax '//:9999'

License

MIT © Hugo Dias

Repository

hugomrdias/iso-url


上一篇:just-kebab-case
下一篇:iso-stream-http
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部