UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.urlWithParams = exports.ParamsURL = exports.SearchURL = exports.SearchParamsURL = void 0;
4// This could be it's own module...
5/**
6 * Like `URL`, but accepts a `params` argument that is added to the search parameters/query string.
7 */
8class SearchParamsURL extends URL {
9 constructor(url, params, base) {
10 super(url, base);
11 const iterable = Array.isArray(params) || params instanceof URLSearchParams
12 ? params
13 : typeof params === 'string'
14 ? new URLSearchParams(params)
15 : Object.entries(params !== null && params !== void 0 ? params : {});
16 for (const [k, v] of iterable)
17 this.searchParams.append(k, '' + v);
18 }
19}
20exports.SearchParamsURL = SearchParamsURL;
21exports.SearchURL = SearchParamsURL;
22exports.ParamsURL = SearchParamsURL;
23/** @deprecated Use SearchParamsURL instead */
24const urlWithParams = (...args) => {
25 return new SearchParamsURL(...args).href;
26};
27exports.urlWithParams = urlWithParams;
28//# sourceMappingURL=search-params-url.js.map
\No newline at end of file