URL Encoder/Decoder

Encoding

Encode and decode URL components, build and parse query strings effortlessly.

Import

Import
import { url } from 'toolmetry';

API Reference

FunctionParametersReturnsDescription
url.encodeinput: stringstringURL-encode a string
url.decodeinput: stringstringDecode a URL-encoded string
url.buildQueryparams: Record<string, string|number|boolean>stringBuild a query string from an object
url.parseQueryqs: stringRecord<string, string>Parse a query string into an object

Examples

Encode/Decode
import { url } from 'toolmetry';

const encoded = url.encode('hello world&foo=bar');
// "hello%20world%26foo%3Dbar"

const decoded = url.decode(encoded);
// "hello world&foo=bar"
Build Query String
import { url } from 'toolmetry';

const qs = url.buildQuery({ name: 'John', age: 30, active: true });
// "?name=John&age=30&active=true"
Parse Query String
import { url } from 'toolmetry';

const params = url.parseQuery('?name=John&age=30');
// { name: "John", age: "30" }

Try It Live