@openally/auto-url
v1.0.1
Published
Utility to build WHATWG URL from an object payload
Downloads
2,424
Readme
Requirements
- Node.js v18 or higher
Getting Started
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @openally/auto-url
# or
$ yarn add @openally/auto-url
Usage example
import autoURL from "@openally/auto-url";
const myURL = autoURL(
"https://www.google.fr",
{ foo: "bar" },
{ foo: (value) => value.toUpperCase() }
);
// https://google.fr/?foo=BAR
console.log(myURL.href);
API
export type autoURLTransformCallback = (value: string) => string;
export type autoURLTransformConfig<T extends string> = Record<T, autoURLTransformCallback>;
function autoURL<T extends string>(
source: string | URL,
payload?: Record<T, any> | Iterable<[T, any]>,
transformersConfig: autoURLTransformConfig<T>
): URL
License
MIT