Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.1 KB

README.md

File metadata and controls

51 lines (38 loc) · 1.1 KB

Auto-URL

Utility to quickly build WHATWG URL from an Object payload (with custom transformation supported)

Requirements

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