@flyyer/better-url
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

@flyyer/better-url

This is not efficient but is practical for our needs.

Wrapper of URL class with additional formatting features but it is not a drop-in replacement because it has non-standard construction.

Implements the URL class definition but preserves base's path and optionally queryparams when resolving URLs.

yarn add @flyyer/better-url

We recommend using it in conjunction with https://github.com/sindresorhus/normalize-url

Usage

import { BetterURL } from "@flyyer/better-url";

const url = new BetterURL("/subpath?q=bye&title=title", "https://example.com/path?q=hello&desc=desc", undefined, { keepBaseSearch: true });
console.log(url.format({ protocol: true, hostname: true, pathname: true, search: true }));
// https://example.com/path/subpath?q=bye&title=title&desc=desc

/** Compared to native URL class: */
const url = new URL("/subpath?q=bye&title=title", "https://example.com/path?q=hello&desc=desc");
console.log(url.href);
// 'https://example.com/subpath?q=bye&title=title

Readme

Keywords

none

Package Sidebar

Install

npm i @flyyer/better-url

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

55.8 kB

Total Files

12

Last publish

Collaborators

  • lopezjurip
  • francomendez