@putkoff/abstract-utilities 0.1.236 → 0.1.238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +78 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +71 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +21 -1
- package/dist/types/functions/index.d.ts +1 -0
- package/dist/types/functions/url_utils/index.d.ts +1 -0
- package/dist/types/functions/url_utils/uri_utils.d.ts +19 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1762,6 +1762,76 @@ function roundPercentage(x) {
|
|
|
1762
1762
|
return safeDivide(Math.round(pct), 100);
|
|
1763
1763
|
}
|
|
1764
1764
|
|
|
1765
|
+
// urlTools.ts
|
|
1766
|
+
// Minimal, safe encoders/decoders + helpers to build/parse URLs
|
|
1767
|
+
/** Encode a single query value/key safely */
|
|
1768
|
+
const encode = (v) => encodeURIComponent(String(v !== null && v !== void 0 ? v : ""));
|
|
1769
|
+
/** Decode a single query value/key safely (never throws) */
|
|
1770
|
+
const decodeSafe = (v) => {
|
|
1771
|
+
if (v == null)
|
|
1772
|
+
return "";
|
|
1773
|
+
try {
|
|
1774
|
+
return decodeURIComponent(v);
|
|
1775
|
+
}
|
|
1776
|
+
catch (_a) {
|
|
1777
|
+
// handles bad % sequences or already-decoded strings
|
|
1778
|
+
return v;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
/** Decode strings that might be double-encoded (up to 2 passes) */
|
|
1782
|
+
const decodeMaybeDouble = (v) => {
|
|
1783
|
+
const once = decodeSafe(v);
|
|
1784
|
+
const twice = decodeSafe(once);
|
|
1785
|
+
return twice.length < once.length ? twice : once;
|
|
1786
|
+
};
|
|
1787
|
+
/** Convert + to spaces (legacy www-form behavior) then decode */
|
|
1788
|
+
const decodeFormComponent = (v) => decodeSafe(v.replace(/\+/g, " "));
|
|
1789
|
+
/** Build a URL with query params (skips null/undefined) */
|
|
1790
|
+
const buildUrl = (base, params) => {
|
|
1791
|
+
const u = new URL(base, typeof window !== "undefined" ? window.location.origin : "http://localhost");
|
|
1792
|
+
if (params) {
|
|
1793
|
+
for (const [k, val] of Object.entries(params)) {
|
|
1794
|
+
if (val === null || val === undefined)
|
|
1795
|
+
continue;
|
|
1796
|
+
// arrays -> multiple entries
|
|
1797
|
+
if (Array.isArray(val)) {
|
|
1798
|
+
val.forEach(v => u.searchParams.append(k, String(v)));
|
|
1799
|
+
}
|
|
1800
|
+
else {
|
|
1801
|
+
u.searchParams.set(k, String(val));
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
return u.toString();
|
|
1806
|
+
};
|
|
1807
|
+
/** Parse a query string into an object (first value wins; arrays if repeat=true) */
|
|
1808
|
+
const parseQuery = (qs, opts) => {
|
|
1809
|
+
var _a;
|
|
1810
|
+
const { repeat = false, form = false } = opts || {};
|
|
1811
|
+
const out = {};
|
|
1812
|
+
const s = qs.startsWith("?") ? qs.slice(1) : qs;
|
|
1813
|
+
if (!s)
|
|
1814
|
+
return out;
|
|
1815
|
+
for (const part of s.split("&")) {
|
|
1816
|
+
if (!part)
|
|
1817
|
+
continue;
|
|
1818
|
+
const [kRaw, vRaw = ""] = part.split("=");
|
|
1819
|
+
const K = form ? decodeFormComponent(kRaw) : decodeSafe(kRaw);
|
|
1820
|
+
const V = form ? decodeFormComponent(vRaw) : decodeSafe(vRaw);
|
|
1821
|
+
if (repeat) {
|
|
1822
|
+
((_a = out[K]) !== null && _a !== void 0 ? _a : (out[K] = [])).push(V);
|
|
1823
|
+
}
|
|
1824
|
+
else {
|
|
1825
|
+
out[K] = V;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
return out;
|
|
1829
|
+
};
|
|
1830
|
+
/** Quick helper: percent-encode whole strings for placement in URLs */
|
|
1831
|
+
const encodeTextForUrl = (text) => encode(text);
|
|
1832
|
+
/** Quick helper: decode long blobs coming from share-intents/UTMs */
|
|
1833
|
+
const decodeShareBlob = (blob) => decodeMaybeDouble(blob).replace(/\r\n/g, "\n");
|
|
1834
|
+
|
|
1765
1835
|
Object.defineProperty(exports, "useCallback", {
|
|
1766
1836
|
enumerable: true,
|
|
1767
1837
|
get: function () { return react.useCallback; }
|
|
@@ -1799,6 +1869,7 @@ exports.assure_array = assure_array;
|
|
|
1799
1869
|
exports.assure_list = assure_list;
|
|
1800
1870
|
exports.assure_number = assure_number;
|
|
1801
1871
|
exports.assure_string = assure_string;
|
|
1872
|
+
exports.buildUrl = buildUrl;
|
|
1802
1873
|
exports.callStorage = callStorage;
|
|
1803
1874
|
exports.callWindowMethod = callWindowMethod;
|
|
1804
1875
|
exports.capitalize = capitalize;
|
|
@@ -1809,11 +1880,17 @@ exports.cleanText = cleanText;
|
|
|
1809
1880
|
exports.create_list_string = create_list_string;
|
|
1810
1881
|
exports.currentUsername = currentUsername;
|
|
1811
1882
|
exports.currentUsernames = currentUsernames;
|
|
1883
|
+
exports.decodeFormComponent = decodeFormComponent;
|
|
1812
1884
|
exports.decodeJwt = decodeJwt;
|
|
1885
|
+
exports.decodeMaybeDouble = decodeMaybeDouble;
|
|
1886
|
+
exports.decodeSafe = decodeSafe;
|
|
1887
|
+
exports.decodeShareBlob = decodeShareBlob;
|
|
1813
1888
|
exports.eatAll = eatAll;
|
|
1814
1889
|
exports.eatEnd = eatEnd;
|
|
1815
1890
|
exports.eatInner = eatInner;
|
|
1816
1891
|
exports.eatOuter = eatOuter;
|
|
1892
|
+
exports.encode = encode;
|
|
1893
|
+
exports.encodeTextForUrl = encodeTextForUrl;
|
|
1817
1894
|
exports.ensureArray = ensureArray;
|
|
1818
1895
|
exports.ensureList = ensureList;
|
|
1819
1896
|
exports.ensureNumber = ensureNumber;
|
|
@@ -1900,6 +1977,7 @@ exports.isType = isType;
|
|
|
1900
1977
|
exports.make_path = make_path;
|
|
1901
1978
|
exports.make_sanitized_path = make_sanitized_path;
|
|
1902
1979
|
exports.normalizeUrl = normalizeUrl;
|
|
1980
|
+
exports.parseQuery = parseQuery;
|
|
1903
1981
|
exports.parseResult = parseResult;
|
|
1904
1982
|
exports.path_to_url = path_to_url;
|
|
1905
1983
|
exports.processKeywords = processKeywords;
|