@gjsify/querystring 0.0.4 → 0.1.0

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/cjs/index.js DELETED
@@ -1,1035 +0,0 @@
1
- import { Buffer } from "buffer";
2
- import { NodeURIError } from "./error.js";
3
- const hexTable = new Array(256);
4
- for (let i = 0; i < 256; ++i) {
5
- hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase();
6
- }
7
- function encodeStr(str, noEscapeTable, hexTable2) {
8
- const len = str.length;
9
- if (len === 0)
10
- return "";
11
- let out = "";
12
- let lastPos = 0;
13
- for (let i = 0; i < len; i++) {
14
- let c = str.charCodeAt(i);
15
- if (c < 128) {
16
- if (noEscapeTable[c] === 1)
17
- continue;
18
- if (lastPos < i)
19
- out += str.slice(lastPos, i);
20
- lastPos = i + 1;
21
- out += hexTable2[c];
22
- continue;
23
- }
24
- if (lastPos < i)
25
- out += str.slice(lastPos, i);
26
- if (c < 2048) {
27
- lastPos = i + 1;
28
- out += hexTable2[192 | c >> 6] + hexTable2[128 | c & 63];
29
- continue;
30
- }
31
- if (c < 55296 || c >= 57344) {
32
- lastPos = i + 1;
33
- out += hexTable2[224 | c >> 12] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63];
34
- continue;
35
- }
36
- ++i;
37
- if (i >= len)
38
- throw new ERR_INVALID_URI();
39
- const c2 = str.charCodeAt(i) & 1023;
40
- lastPos = i + 1;
41
- c = 65536 + ((c & 1023) << 10 | c2);
42
- out += hexTable2[240 | c >> 18] + hexTable2[128 | c >> 12 & 63] + hexTable2[128 | c >> 6 & 63] + hexTable2[128 | c & 63];
43
- }
44
- if (lastPos === 0)
45
- return str;
46
- if (lastPos < len)
47
- return out + str.slice(lastPos);
48
- return out;
49
- }
50
- class ERR_INVALID_URI extends NodeURIError {
51
- constructor() {
52
- super("ERR_INVALID_URI", `URI malformed`);
53
- }
54
- }
55
- const decode = parse;
56
- const encode = stringify;
57
- function qsEscape(str) {
58
- if (typeof str !== "string") {
59
- if (typeof str === "object") {
60
- str = String(str);
61
- } else {
62
- str += "";
63
- }
64
- }
65
- return encodeStr(str, noEscape, hexTable);
66
- }
67
- const escape = qsEscape;
68
- const isHexTable = new Int8Array([
69
- 0,
70
- 0,
71
- 0,
72
- 0,
73
- 0,
74
- 0,
75
- 0,
76
- 0,
77
- 0,
78
- 0,
79
- 0,
80
- 0,
81
- 0,
82
- 0,
83
- 0,
84
- 0,
85
- // 0 - 15
86
- 0,
87
- 0,
88
- 0,
89
- 0,
90
- 0,
91
- 0,
92
- 0,
93
- 0,
94
- 0,
95
- 0,
96
- 0,
97
- 0,
98
- 0,
99
- 0,
100
- 0,
101
- 0,
102
- // 16 - 31
103
- 0,
104
- 0,
105
- 0,
106
- 0,
107
- 0,
108
- 0,
109
- 0,
110
- 0,
111
- 0,
112
- 0,
113
- 0,
114
- 0,
115
- 0,
116
- 0,
117
- 0,
118
- 0,
119
- // 32 - 47
120
- 1,
121
- 1,
122
- 1,
123
- 1,
124
- 1,
125
- 1,
126
- 1,
127
- 1,
128
- 1,
129
- 1,
130
- 0,
131
- 0,
132
- 0,
133
- 0,
134
- 0,
135
- 0,
136
- // 48 - 63
137
- 0,
138
- 1,
139
- 1,
140
- 1,
141
- 1,
142
- 1,
143
- 1,
144
- 0,
145
- 0,
146
- 0,
147
- 0,
148
- 0,
149
- 0,
150
- 0,
151
- 0,
152
- 0,
153
- // 64 - 79
154
- 0,
155
- 0,
156
- 0,
157
- 0,
158
- 0,
159
- 0,
160
- 0,
161
- 0,
162
- 0,
163
- 0,
164
- 0,
165
- 0,
166
- 0,
167
- 0,
168
- 0,
169
- 0,
170
- // 80 - 95
171
- 0,
172
- 1,
173
- 1,
174
- 1,
175
- 1,
176
- 1,
177
- 1,
178
- 0,
179
- 0,
180
- 0,
181
- 0,
182
- 0,
183
- 0,
184
- 0,
185
- 0,
186
- 0,
187
- // 96 - 111
188
- 0,
189
- 0,
190
- 0,
191
- 0,
192
- 0,
193
- 0,
194
- 0,
195
- 0,
196
- 0,
197
- 0,
198
- 0,
199
- 0,
200
- 0,
201
- 0,
202
- 0,
203
- 0,
204
- // 112 - 127
205
- 0,
206
- 0,
207
- 0,
208
- 0,
209
- 0,
210
- 0,
211
- 0,
212
- 0,
213
- 0,
214
- 0,
215
- 0,
216
- 0,
217
- 0,
218
- 0,
219
- 0,
220
- 0,
221
- // 128 ...
222
- 0,
223
- 0,
224
- 0,
225
- 0,
226
- 0,
227
- 0,
228
- 0,
229
- 0,
230
- 0,
231
- 0,
232
- 0,
233
- 0,
234
- 0,
235
- 0,
236
- 0,
237
- 0,
238
- 0,
239
- 0,
240
- 0,
241
- 0,
242
- 0,
243
- 0,
244
- 0,
245
- 0,
246
- 0,
247
- 0,
248
- 0,
249
- 0,
250
- 0,
251
- 0,
252
- 0,
253
- 0,
254
- 0,
255
- 0,
256
- 0,
257
- 0,
258
- 0,
259
- 0,
260
- 0,
261
- 0,
262
- 0,
263
- 0,
264
- 0,
265
- 0,
266
- 0,
267
- 0,
268
- 0,
269
- 0,
270
- 0,
271
- 0,
272
- 0,
273
- 0,
274
- 0,
275
- 0,
276
- 0,
277
- 0,
278
- 0,
279
- 0,
280
- 0,
281
- 0,
282
- 0,
283
- 0,
284
- 0,
285
- 0,
286
- 0,
287
- 0,
288
- 0,
289
- 0,
290
- 0,
291
- 0,
292
- 0,
293
- 0,
294
- 0,
295
- 0,
296
- 0,
297
- 0,
298
- 0,
299
- 0,
300
- 0,
301
- 0,
302
- 0,
303
- 0,
304
- 0,
305
- 0,
306
- 0,
307
- 0,
308
- 0,
309
- 0,
310
- 0,
311
- 0,
312
- 0,
313
- 0,
314
- 0,
315
- 0,
316
- 0,
317
- 0,
318
- 0,
319
- 0,
320
- 0,
321
- 0,
322
- 0,
323
- 0,
324
- 0,
325
- 0,
326
- 0,
327
- 0,
328
- 0,
329
- 0,
330
- 0,
331
- 0,
332
- 0,
333
- 0
334
- // ... 256
335
- ]);
336
- function charCodes(str) {
337
- const ret = new Array(str.length);
338
- for (let i = 0; i < str.length; ++i) {
339
- ret[i] = str.charCodeAt(i);
340
- }
341
- return ret;
342
- }
343
- function addKeyVal(obj, key, value, keyEncoded, valEncoded, decode2) {
344
- if (key.length > 0 && keyEncoded) {
345
- key = decode2(key);
346
- }
347
- if (value.length > 0 && valEncoded) {
348
- value = decode2(value);
349
- }
350
- if (obj[key] === void 0) {
351
- obj[key] = value;
352
- } else {
353
- const curValue = obj[key];
354
- if (curValue.pop) {
355
- curValue[curValue.length] = value;
356
- } else {
357
- obj[key] = [curValue, value];
358
- }
359
- }
360
- }
361
- function parse(str, sep = "&", eq = "=", { decodeURIComponent: decodeURIComponent2 = unescape, maxKeys = 1e3 } = {}) {
362
- const obj = /* @__PURE__ */ Object.create(null);
363
- if (typeof str !== "string" || str.length === 0) {
364
- return obj;
365
- }
366
- const sepCodes = !sep ? [38] : charCodes(String(sep));
367
- const eqCodes = !eq ? [61] : charCodes(String(eq));
368
- const sepLen = sepCodes.length;
369
- const eqLen = eqCodes.length;
370
- let pairs = 1e3;
371
- if (typeof maxKeys === "number") {
372
- pairs = maxKeys > 0 ? maxKeys : -1;
373
- }
374
- let decode2 = unescape;
375
- if (decodeURIComponent2) {
376
- decode2 = decodeURIComponent2;
377
- }
378
- const customDecode = decode2 !== unescape;
379
- let lastPos = 0;
380
- let sepIdx = 0;
381
- let eqIdx = 0;
382
- let key = "";
383
- let value = "";
384
- let keyEncoded = customDecode;
385
- let valEncoded = customDecode;
386
- const plusChar = customDecode ? "%20" : " ";
387
- let encodeCheck = 0;
388
- for (let i = 0; i < str.length; ++i) {
389
- const code = str.charCodeAt(i);
390
- if (code === sepCodes[sepIdx]) {
391
- if (++sepIdx === sepLen) {
392
- const end = i - sepIdx + 1;
393
- if (eqIdx < eqLen) {
394
- if (lastPos < end) {
395
- key += str.slice(lastPos, end);
396
- } else if (key.length === 0) {
397
- if (--pairs === 0) {
398
- return obj;
399
- }
400
- lastPos = i + 1;
401
- sepIdx = eqIdx = 0;
402
- continue;
403
- }
404
- } else if (lastPos < end) {
405
- value += str.slice(lastPos, end);
406
- }
407
- addKeyVal(obj, key, value, keyEncoded, valEncoded, decode2);
408
- if (--pairs === 0) {
409
- return obj;
410
- }
411
- key = value = "";
412
- encodeCheck = 0;
413
- lastPos = i + 1;
414
- sepIdx = eqIdx = 0;
415
- }
416
- } else {
417
- sepIdx = 0;
418
- if (eqIdx < eqLen) {
419
- if (code === eqCodes[eqIdx]) {
420
- if (++eqIdx === eqLen) {
421
- const end = i - eqIdx + 1;
422
- if (lastPos < end) {
423
- key += str.slice(lastPos, end);
424
- }
425
- encodeCheck = 0;
426
- lastPos = i + 1;
427
- }
428
- continue;
429
- } else {
430
- eqIdx = 0;
431
- if (!keyEncoded) {
432
- if (code === 37) {
433
- encodeCheck = 1;
434
- continue;
435
- } else if (encodeCheck > 0) {
436
- if (isHexTable[code] === 1) {
437
- if (++encodeCheck === 3) {
438
- keyEncoded = true;
439
- }
440
- continue;
441
- } else {
442
- encodeCheck = 0;
443
- }
444
- }
445
- }
446
- }
447
- if (code === 43) {
448
- if (lastPos < i) {
449
- key += str.slice(lastPos, i);
450
- }
451
- key += plusChar;
452
- lastPos = i + 1;
453
- continue;
454
- }
455
- }
456
- if (code === 43) {
457
- if (lastPos < i) {
458
- value += str.slice(lastPos, i);
459
- }
460
- value += plusChar;
461
- lastPos = i + 1;
462
- } else if (!valEncoded) {
463
- if (code === 37) {
464
- encodeCheck = 1;
465
- } else if (encodeCheck > 0) {
466
- if (isHexTable[code] === 1) {
467
- if (++encodeCheck === 3) {
468
- valEncoded = true;
469
- }
470
- } else {
471
- encodeCheck = 0;
472
- }
473
- }
474
- }
475
- }
476
- }
477
- if (lastPos < str.length) {
478
- if (eqIdx < eqLen) {
479
- key += str.slice(lastPos);
480
- } else if (sepIdx < sepLen) {
481
- value += str.slice(lastPos);
482
- }
483
- } else if (eqIdx === 0 && key.length === 0) {
484
- return obj;
485
- }
486
- addKeyVal(obj, key, value, keyEncoded, valEncoded, decode2);
487
- return obj;
488
- }
489
- const noEscape = new Int8Array([
490
- 0,
491
- 0,
492
- 0,
493
- 0,
494
- 0,
495
- 0,
496
- 0,
497
- 0,
498
- 0,
499
- 0,
500
- 0,
501
- 0,
502
- 0,
503
- 0,
504
- 0,
505
- 0,
506
- // 0 - 15
507
- 0,
508
- 0,
509
- 0,
510
- 0,
511
- 0,
512
- 0,
513
- 0,
514
- 0,
515
- 0,
516
- 0,
517
- 0,
518
- 0,
519
- 0,
520
- 0,
521
- 0,
522
- 0,
523
- // 16 - 31
524
- 0,
525
- 1,
526
- 0,
527
- 0,
528
- 0,
529
- 0,
530
- 0,
531
- 1,
532
- 1,
533
- 1,
534
- 1,
535
- 0,
536
- 0,
537
- 1,
538
- 1,
539
- 0,
540
- // 32 - 47
541
- 1,
542
- 1,
543
- 1,
544
- 1,
545
- 1,
546
- 1,
547
- 1,
548
- 1,
549
- 1,
550
- 1,
551
- 0,
552
- 0,
553
- 0,
554
- 0,
555
- 0,
556
- 0,
557
- // 48 - 63
558
- 0,
559
- 1,
560
- 1,
561
- 1,
562
- 1,
563
- 1,
564
- 1,
565
- 1,
566
- 1,
567
- 1,
568
- 1,
569
- 1,
570
- 1,
571
- 1,
572
- 1,
573
- 1,
574
- // 64 - 79
575
- 1,
576
- 1,
577
- 1,
578
- 1,
579
- 1,
580
- 1,
581
- 1,
582
- 1,
583
- 1,
584
- 1,
585
- 1,
586
- 0,
587
- 0,
588
- 0,
589
- 0,
590
- 1,
591
- // 80 - 95
592
- 0,
593
- 1,
594
- 1,
595
- 1,
596
- 1,
597
- 1,
598
- 1,
599
- 1,
600
- 1,
601
- 1,
602
- 1,
603
- 1,
604
- 1,
605
- 1,
606
- 1,
607
- 1,
608
- // 96 - 111
609
- 1,
610
- 1,
611
- 1,
612
- 1,
613
- 1,
614
- 1,
615
- 1,
616
- 1,
617
- 1,
618
- 1,
619
- 1,
620
- 0,
621
- 0,
622
- 0,
623
- 1,
624
- 0
625
- // 112 - 127
626
- ]);
627
- function stringifyPrimitive(v) {
628
- if (typeof v === "string") {
629
- return v;
630
- }
631
- if (typeof v === "number" && isFinite(v)) {
632
- return "" + v;
633
- }
634
- if (typeof v === "bigint") {
635
- return "" + v;
636
- }
637
- if (typeof v === "boolean") {
638
- return v ? "true" : "false";
639
- }
640
- return "";
641
- }
642
- function encodeStringifiedCustom(v, encode2) {
643
- return encode2(stringifyPrimitive(v));
644
- }
645
- function encodeStringified(v, encode2) {
646
- if (typeof v === "string") {
647
- return v.length ? encode2(v) : "";
648
- }
649
- if (typeof v === "number" && isFinite(v)) {
650
- return Math.abs(v) < 1e21 ? "" + v : encode2("" + v);
651
- }
652
- if (typeof v === "bigint") {
653
- return "" + v;
654
- }
655
- if (typeof v === "boolean") {
656
- return v ? "true" : "false";
657
- }
658
- return "";
659
- }
660
- function stringify(obj, sep, eq, options) {
661
- sep ||= "&";
662
- eq ||= "=";
663
- const encode2 = options ? options.encodeURIComponent : qsEscape;
664
- const convert = options ? encodeStringifiedCustom : encodeStringified;
665
- if (obj !== null && typeof obj === "object") {
666
- const keys = Object.keys(obj);
667
- const len = keys.length;
668
- let fields = "";
669
- for (let i = 0; i < len; ++i) {
670
- const k = keys[i];
671
- const v = obj[k];
672
- let ks = convert(k, encode2);
673
- ks += eq;
674
- if (Array.isArray(v)) {
675
- const vlen = v.length;
676
- if (vlen === 0)
677
- continue;
678
- if (fields) {
679
- fields += sep;
680
- }
681
- for (let j = 0; j < vlen; ++j) {
682
- if (j) {
683
- fields += sep;
684
- }
685
- fields += ks;
686
- fields += convert(v[j], encode2);
687
- }
688
- } else {
689
- if (fields) {
690
- fields += sep;
691
- }
692
- fields += ks;
693
- fields += convert(v, encode2);
694
- }
695
- }
696
- return fields;
697
- }
698
- return "";
699
- }
700
- const unhexTable = new Int8Array([
701
- -1,
702
- -1,
703
- -1,
704
- -1,
705
- -1,
706
- -1,
707
- -1,
708
- -1,
709
- -1,
710
- -1,
711
- -1,
712
- -1,
713
- -1,
714
- -1,
715
- -1,
716
- -1,
717
- // 0 - 15
718
- -1,
719
- -1,
720
- -1,
721
- -1,
722
- -1,
723
- -1,
724
- -1,
725
- -1,
726
- -1,
727
- -1,
728
- -1,
729
- -1,
730
- -1,
731
- -1,
732
- -1,
733
- -1,
734
- // 16 - 31
735
- -1,
736
- -1,
737
- -1,
738
- -1,
739
- -1,
740
- -1,
741
- -1,
742
- -1,
743
- -1,
744
- -1,
745
- -1,
746
- -1,
747
- -1,
748
- -1,
749
- -1,
750
- -1,
751
- // 32 - 47
752
- 0,
753
- 1,
754
- 2,
755
- 3,
756
- 4,
757
- 5,
758
- 6,
759
- 7,
760
- 8,
761
- 9,
762
- -1,
763
- -1,
764
- -1,
765
- -1,
766
- -1,
767
- -1,
768
- // 48 - 63
769
- -1,
770
- 10,
771
- 11,
772
- 12,
773
- 13,
774
- 14,
775
- 15,
776
- -1,
777
- -1,
778
- -1,
779
- -1,
780
- -1,
781
- -1,
782
- -1,
783
- -1,
784
- -1,
785
- // 64 - 79
786
- -1,
787
- -1,
788
- -1,
789
- -1,
790
- -1,
791
- -1,
792
- -1,
793
- -1,
794
- -1,
795
- -1,
796
- -1,
797
- -1,
798
- -1,
799
- -1,
800
- -1,
801
- -1,
802
- // 80 - 95
803
- -1,
804
- 10,
805
- 11,
806
- 12,
807
- 13,
808
- 14,
809
- 15,
810
- -1,
811
- -1,
812
- -1,
813
- -1,
814
- -1,
815
- -1,
816
- -1,
817
- -1,
818
- -1,
819
- // 96 - 111
820
- -1,
821
- -1,
822
- -1,
823
- -1,
824
- -1,
825
- -1,
826
- -1,
827
- -1,
828
- -1,
829
- -1,
830
- -1,
831
- -1,
832
- -1,
833
- -1,
834
- -1,
835
- -1,
836
- // 112 - 127
837
- -1,
838
- -1,
839
- -1,
840
- -1,
841
- -1,
842
- -1,
843
- -1,
844
- -1,
845
- -1,
846
- -1,
847
- -1,
848
- -1,
849
- -1,
850
- -1,
851
- -1,
852
- -1,
853
- // 128 ...
854
- -1,
855
- -1,
856
- -1,
857
- -1,
858
- -1,
859
- -1,
860
- -1,
861
- -1,
862
- -1,
863
- -1,
864
- -1,
865
- -1,
866
- -1,
867
- -1,
868
- -1,
869
- -1,
870
- -1,
871
- -1,
872
- -1,
873
- -1,
874
- -1,
875
- -1,
876
- -1,
877
- -1,
878
- -1,
879
- -1,
880
- -1,
881
- -1,
882
- -1,
883
- -1,
884
- -1,
885
- -1,
886
- -1,
887
- -1,
888
- -1,
889
- -1,
890
- -1,
891
- -1,
892
- -1,
893
- -1,
894
- -1,
895
- -1,
896
- -1,
897
- -1,
898
- -1,
899
- -1,
900
- -1,
901
- -1,
902
- -1,
903
- -1,
904
- -1,
905
- -1,
906
- -1,
907
- -1,
908
- -1,
909
- -1,
910
- -1,
911
- -1,
912
- -1,
913
- -1,
914
- -1,
915
- -1,
916
- -1,
917
- -1,
918
- -1,
919
- -1,
920
- -1,
921
- -1,
922
- -1,
923
- -1,
924
- -1,
925
- -1,
926
- -1,
927
- -1,
928
- -1,
929
- -1,
930
- -1,
931
- -1,
932
- -1,
933
- -1,
934
- -1,
935
- -1,
936
- -1,
937
- -1,
938
- -1,
939
- -1,
940
- -1,
941
- -1,
942
- -1,
943
- -1,
944
- -1,
945
- -1,
946
- -1,
947
- -1,
948
- -1,
949
- -1,
950
- -1,
951
- -1,
952
- -1,
953
- -1,
954
- -1,
955
- -1,
956
- -1,
957
- -1,
958
- -1,
959
- -1,
960
- -1,
961
- -1,
962
- -1,
963
- -1,
964
- -1,
965
- -1
966
- // ... 255
967
- ]);
968
- function unescapeBuffer(s, decodeSpaces = false) {
969
- const out = new Buffer(s.length);
970
- let index = 0;
971
- let outIndex = 0;
972
- let currentChar;
973
- let nextChar;
974
- let hexHigh;
975
- let hexLow;
976
- const maxLength = s.length - 2;
977
- let hasHex = false;
978
- while (index < s.length) {
979
- currentChar = s.charCodeAt(index);
980
- if (currentChar === 43 && decodeSpaces) {
981
- out[outIndex++] = 32;
982
- index++;
983
- continue;
984
- }
985
- if (currentChar === 37 && index < maxLength) {
986
- currentChar = s.charCodeAt(++index);
987
- hexHigh = unhexTable[currentChar];
988
- if (!(hexHigh >= 0)) {
989
- out[outIndex++] = 37;
990
- continue;
991
- } else {
992
- nextChar = s.charCodeAt(++index);
993
- hexLow = unhexTable[nextChar];
994
- if (!(hexLow >= 0)) {
995
- out[outIndex++] = 37;
996
- index--;
997
- } else {
998
- hasHex = true;
999
- currentChar = hexHigh * 16 + hexLow;
1000
- }
1001
- }
1002
- }
1003
- out[outIndex++] = currentChar;
1004
- index++;
1005
- }
1006
- return hasHex ? out.slice(0, outIndex) : out;
1007
- }
1008
- function qsUnescape(s) {
1009
- try {
1010
- return decodeURIComponent(s);
1011
- } catch {
1012
- return unescapeBuffer(s).toString();
1013
- }
1014
- }
1015
- const unescape = qsUnescape;
1016
- var src_default = {
1017
- parse,
1018
- stringify,
1019
- decode,
1020
- encode,
1021
- unescape,
1022
- escape,
1023
- unescapeBuffer
1024
- };
1025
- export {
1026
- ERR_INVALID_URI,
1027
- decode,
1028
- src_default as default,
1029
- encode,
1030
- escape,
1031
- parse,
1032
- stringify,
1033
- unescape,
1034
- unescapeBuffer
1035
- };