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

1.0.1 • Public • Published

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @openally/auto-url

      Weekly Downloads

      555

      Version

      1.0.1

      License

      MIT

      Unpacked Size

      5.89 kB

      Total Files

      6

      Last publish

      Collaborators

      • pierred
      • fraxken