UNPKG

build-url-params

Version:
61 lines (41 loc) โ€ข 1.14 kB
# build-url-params A lightweight utility to build URLs with query parameters, automatically filtering out empty (`""`), `null`, and `undefined` values. ## ๐Ÿ“ฆ Installation Install the package using npm: ```sh npm install build-url-params ``` Or with Yarn: ```sh yarn add build-url-params ``` ## ๐Ÿš€ Usage Import the function: ```js import { buildUrlWithParams } from "build-url-params"; const url = "https://example.com"; const params = { search: "query", page: 1, filter: null, sort: undefined, }; const result = buildUrlWithParams(url, params); console.log(result); // "https://example.com?search=query&page=1" ``` ## โœ… Features - Automatically removes null, undefined, and empty string values - Supports basic query parameter encoding - Tiny, fast, and dependency-free ## ๐Ÿงช Examples ```js buildUrlWithParams("https://api.site.com", { name: "Dwash_Karma", role: "admin", }); // Output: "https://api.site.com?name=Dwash_Karma&role=admin" ``` ## ๐Ÿ“„ License MIT ## ๐Ÿค Contributing Contributions, issues, and feature requests are welcome!