@gjsify/querystring 0.4.33 → 0.4.35

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/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{NodeURIError as e}from"./error.js";import{Buffer as t}from"node:buffer";const n=Array.from({length:256});for(let e=0;e<256;++e)n[e]=`%`+((e<16?`0`:``)+e.toString(16)).toUpperCase();function encodeStr(e,t,n){let r=e.length;if(r===0)return``;let i=``,a=0;for(let o=0;o<r;o++){let s=e.charCodeAt(o);if(s<128){if(t[s]===1)continue;a<o&&(i+=e.slice(a,o)),a=o+1,i+=n[s];continue}if(a<o&&(i+=e.slice(a,o)),s<2048){a=o+1,i+=n[192|s>>6]+n[128|s&63];continue}if(s<55296||s>=57344){a=o+1,i+=n[224|s>>12]+n[128|s>>6&63]+n[128|s&63];continue}if(++o,o>=r)throw new ERR_INVALID_URI;let c=e.charCodeAt(o)&1023;a=o+1,s=65536+((s&1023)<<10|c),i+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|s&63]}return a===0?e:a<r?i+e.slice(a):i}var ERR_INVALID_URI=class extends e{constructor(){super(`ERR_INVALID_URI`,`URI malformed`)}};const r=parse,i=stringify;function qsEscape(e){return typeof e!=`string`&&(typeof e==`object`?e=String(e):e+=``),encodeStr(e,s,n)}const a=qsEscape,o=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function charCodes(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t}function addKeyVal(e,t,n,r,i,a){if(t.length>0&&r)try{t=a(t)}catch{}if(n.length>0&&i)try{n=a(n)}catch{}if(e[t]===void 0)e[t]=n;else{let r=e[t];r.pop?r[r.length]=n:e[t]=[r,n]}}function parse(e,t=`&`,n=`=`,{decodeURIComponent:r=l,maxKeys:i=1e3}={}){let a=Object.create(null);if(typeof e!=`string`||e.length===0)return a;let s=t?charCodes(String(t)):[38],c=n?charCodes(String(n)):[61],u=s.length,d=c.length,f=1e3;typeof i==`number`&&(f=i>0?i:-1);let p=l;r&&(p=r);let m=p!==l,h=0,g=0,_=0,v=``,y=``,b=m,x=m,S=m?`%20`:` `,C=0;for(let t=0;t<e.length;++t){let n=e.charCodeAt(t);if(n===s[g]){if(++g===u){let n=t-g+1;if(_<d){if(h<n)v+=e.slice(h,n);else if(v.length===0){if(--f===0)return a;h=t+1,g=_=0;continue}}else h<n&&(y+=e.slice(h,n));if(addKeyVal(a,v,y,b,x,p),--f===0)return a;v=y=``,C=0,h=t+1,g=_=0}}else{if(g=0,_<d){if(n===c[_]){if(++_===d){let n=t-_+1;h<n&&(v+=e.slice(h,n)),C=0,h=t+1}continue}else if(_=0,!b){if(n===37){C=1;continue}else if(C>0)if(o[n]===1){++C===3&&(b=!0);continue}else C=0}if(n===43){h<t&&(v+=e.slice(h,t)),v+=S,h=t+1;continue}}n===43?(h<t&&(y+=e.slice(h,t)),y+=S,h=t+1):x||(n===37?C=1:C>0&&(o[n]===1?++C===3&&(x=!0):C=0))}}if(h<e.length)_<d?v+=e.slice(h):g<u&&(y+=e.slice(h));else if(_===0&&v.length===0)return a;return addKeyVal(a,v,y,b,x,p),a}const s=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0]);function stringifyPrimitive(e){return typeof e==`string`?e:typeof e==`number`&&isFinite(e)||typeof e==`bigint`?``+e:typeof e==`boolean`?e?`true`:`false`:``}function encodeStringifiedCustom(e,t){return t(stringifyPrimitive(e))}function encodeStringified(e,t){return typeof e==`string`?e.length?t(e):``:typeof e==`number`&&isFinite(e)?Math.abs(e)<1e21?``+e:t(``+e):typeof e==`bigint`?``+e:typeof e==`boolean`?e?`true`:`false`:``}function stringify(e,t,n,r){t||=`&`,n||=`=`;let i=r?r.encodeURIComponent:qsEscape,a=r?encodeStringifiedCustom:encodeStringified;if(typeof e==`object`&&e){let r=Object.keys(e),o=r.length,s=``;for(let c=0;c<o;++c){let o=r[c],l=e[o],u=a(o,i);if(u+=n,Array.isArray(l)){let e=l.length;if(e===0)continue;s&&(s+=t);for(let n=0;n<e;++n)n&&(s+=t),s+=u,s+=a(l[n],i)}else s&&(s+=t),s+=u,s+=a(l,i)}return s}return``}const c=new Int8Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);function unescapeBuffer(e,n=!1){let r=new t(e.length),i=0,a=0,o,s,l,u,d=e.length-2,f=!1;for(;i<e.length;){if(o=e.charCodeAt(i),o===43&&n){r[a++]=32,i++;continue}if(o===37&&i<d)if(o=e.charCodeAt(++i),l=c[o],l>=0)s=e.charCodeAt(++i),u=c[s],u>=0?(f=!0,o=l*16+u):(r[a++]=37,i--);else{r[a++]=37;continue}r[a++]=o,i++}return f?r.slice(0,a):r}function qsUnescape(e){try{return decodeURIComponent(e)}catch{return unescapeBuffer(e).toString()}}const l=qsUnescape;var u={parse,stringify,decode:r,encode:i,unescape:l,escape:a,unescapeBuffer};export{ERR_INVALID_URI,r as decode,u as default,i as encode,a as escape,parse,stringify,l as unescape,unescapeBuffer};
1
+ import{ERR_INVALID_URI as e,qsEscape as t}from"./internal/encode.js";import{qsUnescape as n,unescapeBuffer as r}from"./internal/decode.js";import{parse as i}from"./internal/parse.js";import{stringify as a}from"./internal/stringify.js";const o=i,s=a,c=t,l=n;var u={parse:i,stringify:a,decode:o,encode:s,unescape:l,escape:c,unescapeBuffer:r};export{e as ERR_INVALID_URI,o as decode,u as default,s as encode,c as escape,i as parse,a as stringify,l as unescape,r as unescapeBuffer};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{unhexTable as e}from"./tables.js";import{Buffer as t}from"node:buffer";function unescapeBuffer(n,r=!1){let i=new t(n.length),a=0,o=0,s,c,l,u,d=n.length-2,f=!1;for(;a<n.length;){if(s=n.charCodeAt(a),s===43&&r){i[o++]=32,a++;continue}if(s===37&&a<d)if(s=n.charCodeAt(++a),l=e[s],l>=0)c=n.charCodeAt(++a),u=e[c],u>=0?(f=!0,s=l*16+u):(i[o++]=37,a--);else{i[o++]=37;continue}i[o++]=s,a++}return f?i.slice(0,o):i}function qsUnescape(e){try{return decodeURIComponent(e)}catch{return unescapeBuffer(e).toString()}}export{qsUnescape,unescapeBuffer};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{NodeURIError as e}from"../error.js";import{hexTable as t,noEscape as n}from"./tables.js";var ERR_INVALID_URI=class extends e{constructor(){super(`ERR_INVALID_URI`,`URI malformed`)}};function encodeStr(e,t,n){let r=e.length;if(r===0)return``;let i=``,a=0;for(let o=0;o<r;o++){let s=e.charCodeAt(o);if(s<128){if(t[s]===1)continue;a<o&&(i+=e.slice(a,o)),a=o+1,i+=n[s];continue}if(a<o&&(i+=e.slice(a,o)),s<2048){a=o+1,i+=n[192|s>>6]+n[128|s&63];continue}if(s<55296||s>=57344){a=o+1,i+=n[224|s>>12]+n[128|s>>6&63]+n[128|s&63];continue}if(++o,o>=r)throw new ERR_INVALID_URI;let c=e.charCodeAt(o)&1023;a=o+1,s=65536+((s&1023)<<10|c),i+=n[240|s>>18]+n[128|s>>12&63]+n[128|s>>6&63]+n[128|s&63]}return a===0?e:a<r?i+e.slice(a):i}function qsEscape(e){return typeof e!=`string`&&(typeof e==`object`?e=String(e):e+=``),encodeStr(e,n,t)}export{ERR_INVALID_URI,encodeStr,qsEscape};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{isHexTable as e}from"./tables.js";import{qsUnescape as t}from"./decode.js";function charCodes(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;++n)t[n]=e.charCodeAt(n);return t}function addKeyVal(e,t,n,r,i,a){if(t.length>0&&r)try{t=a(t)}catch{}if(n.length>0&&i)try{n=a(n)}catch{}if(e[t]===void 0)e[t]=n;else{let r=e[t];r.pop?r[r.length]=n:e[t]=[r,n]}}function parse(n,r=`&`,i=`=`,{decodeURIComponent:a=t,maxKeys:o=1e3}={}){let s=Object.create(null);if(typeof n!=`string`||n.length===0)return s;let c=r?charCodes(String(r)):[38],l=i?charCodes(String(i)):[61],u=c.length,d=l.length,f=1e3;typeof o==`number`&&(f=o>0?o:-1);let p=t;a&&(p=a);let m=p!==t,h=0,g=0,_=0,v=``,y=``,b=m,x=m,S=m?`%20`:` `,C=0;for(let t=0;t<n.length;++t){let r=n.charCodeAt(t);if(r===c[g]){if(++g===u){let e=t-g+1;if(_<d){if(h<e)v+=n.slice(h,e);else if(v.length===0){if(--f===0)return s;h=t+1,g=_=0;continue}}else h<e&&(y+=n.slice(h,e));if(addKeyVal(s,v,y,b,x,p),--f===0)return s;v=y=``,C=0,h=t+1,g=_=0}}else{if(g=0,_<d){if(r===l[_]){if(++_===d){let e=t-_+1;h<e&&(v+=n.slice(h,e)),C=0,h=t+1}continue}else if(_=0,!b){if(r===37){C=1;continue}else if(C>0)if(e[r]===1){++C===3&&(b=!0);continue}else C=0}if(r===43){h<t&&(v+=n.slice(h,t)),v+=S,h=t+1;continue}}r===43?(h<t&&(y+=n.slice(h,t)),y+=S,h=t+1):x||(r===37?C=1:C>0&&(e[r]===1?++C===3&&(x=!0):C=0))}}if(h<n.length)_<d?v+=n.slice(h):g<u&&(y+=n.slice(h));else if(_===0&&v.length===0)return s;return addKeyVal(s,v,y,b,x,p),s}export{parse};
@@ -0,0 +1 @@
1
+ import"../_virtual/_rolldown/runtime.js";import{qsEscape as e}from"./encode.js";function stringifyPrimitive(e){return typeof e==`string`?e:typeof e==`number`&&isFinite(e)||typeof e==`bigint`?``+e:typeof e==`boolean`?e?`true`:`false`:``}function encodeStringifiedCustom(e,t){return t(stringifyPrimitive(e))}function encodeStringified(e,t){return typeof e==`string`?e.length?t(e):``:typeof e==`number`&&isFinite(e)?Math.abs(e)<1e21?``+e:t(``+e):typeof e==`bigint`?``+e:typeof e==`boolean`?e?`true`:`false`:``}function stringify(t,n,r,i){n||=`&`,r||=`=`;let a=i?i.encodeURIComponent:e,o=i?encodeStringifiedCustom:encodeStringified;if(typeof t==`object`&&t){let e=Object.keys(t),i=e.length,s=``;for(let c=0;c<i;++c){let i=e[c],l=t[i],u=o(i,a);if(u+=r,Array.isArray(l)){let e=l.length;if(e===0)continue;s&&(s+=n);for(let t=0;t<e;++t)t&&(s+=n),s+=u,s+=o(l[t],a)}else s&&(s+=n),s+=u,s+=o(l,a)}return s}return``}export{stringify};
@@ -0,0 +1 @@
1
+ const e=Array.from({length:256});for(let t=0;t<256;++t)e[t]=`%`+((t<16?`0`:``)+t.toString(16)).toUpperCase();const t=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),n=new Int8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,0]),r=new Int8Array([-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]);export{e as hexTable,t as isHexTable,n as noEscape,r as unhexTable};
@@ -1,9 +1,13 @@
1
1
  import type { ParsedUrlQuery } from 'node:querystring';
2
- import { Buffer } from 'node:buffer';
3
- import { NodeURIError } from './error.js';
4
- export declare class ERR_INVALID_URI extends NodeURIError {
5
- constructor();
6
- }
2
+ import { qsEscape } from './internal/encode.js';
3
+ import { qsUnescape, unescapeBuffer } from './internal/decode.js';
4
+ import { parse } from './internal/parse.js';
5
+ import { stringify } from './internal/stringify.js';
6
+ export type { ParsedUrlQuery };
7
+ export { ERR_INVALID_URI } from './internal/encode.js';
8
+ export { unescapeBuffer } from './internal/decode.js';
9
+ export { parse } from './internal/parse.js';
10
+ export { stringify } from './internal/stringify.js';
7
11
  /**
8
12
  * Alias of querystring.parse()
9
13
  * @legacy
@@ -14,11 +18,6 @@ export declare const decode: typeof parse;
14
18
  * @legacy
15
19
  */
16
20
  export declare const encode: typeof stringify;
17
- /**
18
- * replaces encodeURIComponent()
19
- * @see https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
20
- */
21
- declare function qsEscape(str: unknown): string;
22
21
  /**
23
22
  * Performs URL percent-encoding on the given `str` in a manner that is optimized for the specific requirements of URL query strings.
24
23
  * Used by `querystring.stringify()` and is generally not expected to be used directly.
@@ -27,45 +26,6 @@ declare function qsEscape(str: unknown): string;
27
26
  * @see Tested in `test-querystring-escape.js`
28
27
  */
29
28
  export declare const escape: typeof qsEscape;
30
- export type { ParsedUrlQuery };
31
- interface ParseOptions {
32
- /** The function to use when decoding percent-encoded characters in the query string. */
33
- decodeURIComponent?: (string: string) => string;
34
- /** Specifies the maximum number of keys to parse. */
35
- maxKeys?: number;
36
- }
37
- /**
38
- * Parses a URL query string into a collection of key and value pairs.
39
- * @param str The URL query string to parse
40
- * @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
41
- * @param eq The substring used to delimit keys and values in the query string. Default: '='.
42
- * @param options The parse options
43
- * @param options.decodeURIComponent The function to use when decoding percent-encoded characters in the query string. Default: `querystring.unescape()`.
44
- * @param options.maxKeys Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations. Default: `1000`.
45
- * @legacy
46
- * @see Tested in test-querystring.js
47
- */
48
- export declare function parse(str: string, sep?: string, eq?: string, { decodeURIComponent, maxKeys }?: ParseOptions): ParsedUrlQuery;
49
- interface StringifyOptions {
50
- /** The function to use when converting URL-unsafe characters to percent-encoding in the query string. */
51
- encodeURIComponent: (string: string) => string;
52
- }
53
- /**
54
- * Produces a URL query string from a given obj by iterating through the object's "own properties".
55
- * @param obj The object to serialize into a URL query string.
56
- * @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
57
- * @param eq The substring used to delimit keys and values in the query string. Default: '='.
58
- * @param options The stringify options
59
- * @param options.encodeURIComponent The function to use when converting URL-unsafe characters to percent-encoding in the query string. Default: `querystring.escape()`.
60
- * @legacy
61
- * @see Tested in `test-querystring.js`
62
- */
63
- export declare function stringify(obj: Record<string, unknown>, sep?: string, eq?: string, options?: StringifyOptions): string;
64
- /**
65
- * A safe fast alternative to decodeURIComponent
66
- */
67
- export declare function unescapeBuffer(s: string, decodeSpaces?: boolean): Buffer;
68
- declare function qsUnescape(s: string): string;
69
29
  /**
70
30
  * Performs decoding of URL percent-encoded characters on the given `str`.
71
31
  * Used by `querystring.parse()` and is generally not expected to be used directly.
@@ -0,0 +1,19 @@
1
+ import { Buffer } from 'node:buffer';
2
+ /**
3
+ * A safe fast alternative to `decodeURIComponent`.
4
+ *
5
+ * Walks the input byte-by-byte; `%xx` triples decode to a single byte
6
+ * (invalid hex tails are left literal — matches Node's permissive
7
+ * semantics). `+` decodes to `' '` iff `decodeSpaces` is true.
8
+ *
9
+ * @param s The string to decode.
10
+ * @param decodeSpaces Whether to decode `+` as a space character.
11
+ */
12
+ export declare function unescapeBuffer(s: string, decodeSpaces?: boolean): Buffer;
13
+ /**
14
+ * Decodes a URL-encoded string. Tries `decodeURIComponent()` first; on
15
+ * failure (malformed `%xx` triple), falls back to the permissive
16
+ * `unescapeBuffer()` walker. This matches Node's `querystring.unescape`
17
+ * which is "best-effort": invalid encodings are preserved verbatim.
18
+ */
19
+ export declare function qsUnescape(s: string): string;
@@ -0,0 +1,21 @@
1
+ import { NodeURIError } from '../error.js';
2
+ export declare class ERR_INVALID_URI extends NodeURIError {
3
+ constructor();
4
+ }
5
+ /**
6
+ * Lower-level percent-encode: walks `str` byte by byte, emitting either
7
+ * the character (when `noEscapeTable[c] === 1`) or `hexTable[c]` for
8
+ * each ASCII / multi-byte UTF-8 unit. Surrogate pairs are encoded as a
9
+ * single 4-byte UTF-8 sequence. Throws `ERR_INVALID_URI` on a lone
10
+ * high surrogate.
11
+ *
12
+ * @param str The string to encode.
13
+ * @param noEscapeTable Table of characters that need not be encoded.
14
+ * @param hexTable Pre-computed `'%xx'` percent-encoded byte table.
15
+ */
16
+ export declare function encodeStr(str: string, noEscapeTable: Int8Array, hexTable: string[]): string;
17
+ /**
18
+ * Replaces `encodeURIComponent()`.
19
+ * @see https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
20
+ */
21
+ export declare function qsEscape(str: unknown): string;
@@ -0,0 +1,19 @@
1
+ import type { ParsedUrlQuery } from 'node:querystring';
2
+ export interface ParseOptions {
3
+ /** The function to use when decoding percent-encoded characters in the query string. */
4
+ decodeURIComponent?: (string: string) => string;
5
+ /** Specifies the maximum number of keys to parse. */
6
+ maxKeys?: number;
7
+ }
8
+ /**
9
+ * Parses a URL query string into a collection of key and value pairs.
10
+ * @param str The URL query string to parse
11
+ * @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
12
+ * @param eq The substring used to delimit keys and values in the query string. Default: '='.
13
+ * @param options The parse options
14
+ * @param options.decodeURIComponent The function to use when decoding percent-encoded characters in the query string. Default: `querystring.unescape()`.
15
+ * @param options.maxKeys Specifies the maximum number of keys to parse. Specify `0` to remove key counting limitations. Default: `1000`.
16
+ * @legacy
17
+ * @see Tested in test-querystring.js
18
+ */
19
+ export declare function parse(str: string, sep?: string, eq?: string, { decodeURIComponent, maxKeys }?: ParseOptions): ParsedUrlQuery;
@@ -0,0 +1,15 @@
1
+ export interface StringifyOptions {
2
+ /** The function to use when converting URL-unsafe characters to percent-encoding in the query string. */
3
+ encodeURIComponent: (string: string) => string;
4
+ }
5
+ /**
6
+ * Produces a URL query string from a given obj by iterating through the object's "own properties".
7
+ * @param obj The object to serialize into a URL query string.
8
+ * @param sep The substring used to delimit key and value pairs in the query string. Default: '&'.
9
+ * @param eq The substring used to delimit keys and values in the query string. Default: '='.
10
+ * @param options The stringify options
11
+ * @param options.encodeURIComponent The function to use when converting URL-unsafe characters to percent-encoding in the query string. Default: `querystring.escape()`.
12
+ * @legacy
13
+ * @see Tested in `test-querystring.js`
14
+ */
15
+ export declare function stringify(obj: Record<string, unknown>, sep?: string, eq?: string, options?: StringifyOptions): string;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Pre-computed hex table: `hexTable[c]` is the percent-encoded form
3
+ * of byte `c` (e.g. `hexTable[0x20] === '%20'`).
4
+ */
5
+ export declare const hexTable: string[];
6
+ /**
7
+ * Hex-character lookup table: `isHexTable[c]` is `1` iff `c` is the
8
+ * ASCII code of a `[0-9A-Fa-f]` character; `0` otherwise.
9
+ *
10
+ * Used by `parse()` to detect percent-encoded bytes without invoking
11
+ * the decoder.
12
+ */
13
+ export declare const isHexTable: Int8Array<ArrayBuffer>;
14
+ /**
15
+ * No-escape table for `qsEscape()`: `noEscape[c]` is `1` iff byte `c`
16
+ * does NOT need percent-encoding when generating a query string.
17
+ *
18
+ * These characters do not need escaping when generating query strings:
19
+ * `!` `-` `.` `_` `~` `'` `(` `)` `*` digits alpha (upper + lower).
20
+ */
21
+ export declare const noEscape: Int8Array<ArrayBuffer>;
22
+ /**
23
+ * Hex-decode lookup table: `unhexTable[c]` is the integer value of byte
24
+ * `c` interpreted as a hex digit (`0..15`), or `-1` if `c` is not a hex
25
+ * character.
26
+ */
27
+ export declare const unhexTable: Int8Array<ArrayBuffer>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/querystring",
3
- "version": "0.4.33",
3
+ "version": "0.4.35",
4
4
  "description": "Node.js querystring module for Gjs",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -35,8 +35,8 @@
35
35
  "fs"
36
36
  ],
37
37
  "devDependencies": {
38
- "@gjsify/cli": "^0.4.33",
39
- "@gjsify/unit": "^0.4.33",
38
+ "@gjsify/cli": "^0.4.35",
39
+ "@gjsify/unit": "^0.4.35",
40
40
  "@types/node": "^25.9.1",
41
41
  "typescript": "^6.0.3"
42
42
  },