url-query-formatter
v2.0.3
Published
A utility function to append a query string to a URL.
Downloads
4
Maintainers
Readme
url-query-formatter
A simple utility function to append a query string to a URL.
Installation
You can install the package using npm:
npm install url-query-formatter
Usage
CommonJS
const { formatter } = require("url-query-formatter");
const url = "https://example.com";
const params = { key1: "value1", key2: "value2" };
const fullUrl = formatter(url, params);
console.log(fullUrl); // Output: https://example.com?key1=value1&key2=value2
ES Modules
import formatter from "url-query-formatter";
const url = "https://example.com";
const params = { key1: "value1", key2: "value2" };
const fullUrl = formatter(url, params);
console.log(fullUrl); // Output: https://example.com?key1=value1&key2=value2
Parameters
formatter(url, params)
- url (
string
): The base URL to which the query string will be appended. It should be a valid URL format. - params (
Object
): An object containing key-value pairs that will be converted into query string parameters. Each key in the object represents a query parameter, and the associated value represents the parameter's value.