@fluixi/utils 1.0.0-alpha.83 → 1.0.0-alpha.84

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.
Files changed (129) hide show
  1. package/dist/index.cjs +2858 -1
  2. package/dist/index.mjs +2838 -1
  3. package/dist/lib/array/advanced.cjs +2227 -1
  4. package/dist/lib/array/advanced.mjs +2204 -1
  5. package/dist/lib/array/array.cjs +57 -1
  6. package/dist/lib/array/array.mjs +36 -1
  7. package/dist/lib/array/index.cjs +2344 -1
  8. package/dist/lib/array/index.mjs +2322 -1
  9. package/dist/lib/array/utils.cjs +103 -1
  10. package/dist/lib/array/utils.mjs +82 -1
  11. package/dist/lib/color/color.cjs +2190 -1
  12. package/dist/lib/color/color.mjs +2167 -1
  13. package/dist/lib/color/constants.cjs +380 -1
  14. package/dist/lib/color/constants.mjs +359 -1
  15. package/dist/lib/color/conversions.cjs +629 -1
  16. package/dist/lib/color/conversions.mjs +608 -1
  17. package/dist/lib/color/helpers.cjs +2534 -1
  18. package/dist/lib/color/helpers.mjs +2511 -1
  19. package/dist/lib/color/index.cjs +2641 -1
  20. package/dist/lib/color/index.mjs +2619 -1
  21. package/dist/lib/color/types.cjs +18 -1
  22. package/dist/lib/color/utils.cjs +962 -1
  23. package/dist/lib/color/utils.mjs +939 -1
  24. package/dist/lib/compare/comparators.cjs +171 -1
  25. package/dist/lib/compare/comparators.mjs +150 -1
  26. package/dist/lib/compare/index.cjs +172 -1
  27. package/dist/lib/compare/index.mjs +152 -1
  28. package/dist/lib/crypto/hash.cjs +83 -1
  29. package/dist/lib/crypto/hash.mjs +62 -1
  30. package/dist/lib/crypto/index.cjs +85 -1
  31. package/dist/lib/crypto/index.mjs +62 -1
  32. package/dist/lib/dom/events.cjs +40 -1
  33. package/dist/lib/dom/events.mjs +19 -1
  34. package/dist/lib/dom/index.cjs +78 -1
  35. package/dist/lib/dom/index.mjs +56 -1
  36. package/dist/lib/dom/utils.cjs +57 -1
  37. package/dist/lib/dom/utils.mjs +36 -1
  38. package/dist/lib/functions/functions.cjs +366 -1
  39. package/dist/lib/functions/functions.mjs +345 -1
  40. package/dist/lib/functions/index.cjs +369 -1
  41. package/dist/lib/functions/index.mjs +347 -1
  42. package/dist/lib/functions/types.cjs +18 -1
  43. package/dist/lib/helpers.cjs +78 -1
  44. package/dist/lib/helpers.mjs +59 -1
  45. package/dist/lib/index.cjs +2857 -1
  46. package/dist/lib/index.mjs +2836 -1
  47. package/dist/lib/maths/constants.cjs +70 -1
  48. package/dist/lib/maths/constants.mjs +50 -1
  49. package/dist/lib/maths/fn/advanced.cjs +231 -1
  50. package/dist/lib/maths/fn/advanced.mjs +208 -1
  51. package/dist/lib/maths/fn/basic.cjs +212 -1
  52. package/dist/lib/maths/fn/basic.mjs +191 -1
  53. package/dist/lib/maths/fn/complex.cjs +268 -1
  54. package/dist/lib/maths/fn/complex.mjs +247 -1
  55. package/dist/lib/maths/fn/index.cjs +877 -1
  56. package/dist/lib/maths/fn/index.mjs +855 -1
  57. package/dist/lib/maths/fn/trigo.cjs +179 -1
  58. package/dist/lib/maths/fn/trigo.mjs +156 -1
  59. package/dist/lib/maths/fn/vector.cjs +728 -1
  60. package/dist/lib/maths/fn/vector.mjs +707 -1
  61. package/dist/lib/maths/formatter.cjs +61 -1
  62. package/dist/lib/maths/formatter.mjs +40 -1
  63. package/dist/lib/maths/guards.cjs +164 -1
  64. package/dist/lib/maths/guards.mjs +144 -1
  65. package/dist/lib/maths/index.cjs +1152 -1
  66. package/dist/lib/maths/index.mjs +1130 -1
  67. package/dist/lib/maths/parser.cjs +75 -1
  68. package/dist/lib/maths/parser.mjs +54 -1
  69. package/dist/lib/maths/random.cjs +49 -1
  70. package/dist/lib/maths/random.mjs +28 -1
  71. package/dist/lib/maths/types/advanced.cjs +18 -1
  72. package/dist/lib/maths/types/basic.cjs +18 -1
  73. package/dist/lib/maths/types/index.cjs +19 -1
  74. package/dist/lib/maths/types/index.mjs +1 -0
  75. package/dist/lib/maths/types/negative.cjs +18 -1
  76. package/dist/lib/maths/types/operations.cjs +18 -1
  77. package/dist/lib/object/clone.cjs +88 -1
  78. package/dist/lib/object/clone.mjs +65 -1
  79. package/dist/lib/object/diff.cjs +573 -1
  80. package/dist/lib/object/diff.mjs +550 -1
  81. package/dist/lib/object/getter-setter.cjs +2351 -1
  82. package/dist/lib/object/getter-setter.mjs +2330 -1
  83. package/dist/lib/object/index.cjs +3956 -6
  84. package/dist/lib/object/index.mjs +3936 -6
  85. package/dist/lib/object/merge.cjs +1029 -1
  86. package/dist/lib/object/merge.mjs +1006 -1
  87. package/dist/lib/object/object.cjs +280 -1
  88. package/dist/lib/object/object.mjs +257 -1
  89. package/dist/lib/object/omit.cjs +2022 -1
  90. package/dist/lib/object/omit.mjs +1999 -1
  91. package/dist/lib/object/reconcile.cjs +126 -1
  92. package/dist/lib/object/reconcile.mjs +105 -1
  93. package/dist/lib/object/selector.cjs +303 -1
  94. package/dist/lib/object/selector.mjs +282 -1
  95. package/dist/lib/object/sort.cjs +209 -1
  96. package/dist/lib/object/sort.mjs +186 -1
  97. package/dist/lib/object/transform.cjs +2211 -1
  98. package/dist/lib/object/transform.mjs +2190 -1
  99. package/dist/lib/object/types.cjs +18 -1
  100. package/dist/lib/object/utils.cjs +326 -6
  101. package/dist/lib/object/utils.mjs +305 -6
  102. package/dist/lib/primitive/boolean/boolean.cjs +407 -1
  103. package/dist/lib/primitive/boolean/boolean.mjs +386 -1
  104. package/dist/lib/primitive/boolean/index.cjs +382 -1
  105. package/dist/lib/primitive/boolean/index.mjs +359 -1
  106. package/dist/lib/primitive/boolean/types.cjs +18 -1
  107. package/dist/lib/primitive/date/date.cjs +1126 -1
  108. package/dist/lib/primitive/date/date.mjs +1105 -1
  109. package/dist/lib/primitive/date/index.cjs +1128 -1
  110. package/dist/lib/primitive/date/index.mjs +1105 -1
  111. package/dist/lib/primitive/date/types.cjs +18 -1
  112. package/dist/lib/primitive/index.cjs +2338 -5
  113. package/dist/lib/primitive/index.mjs +2316 -5
  114. package/dist/lib/primitive/string/index.cjs +875 -5
  115. package/dist/lib/primitive/string/index.mjs +852 -5
  116. package/dist/lib/primitive/string/parser-2.cjs +543 -8
  117. package/dist/lib/primitive/string/parser-2.mjs +522 -8
  118. package/dist/lib/primitive/string/parser.cjs +236 -3
  119. package/dist/lib/primitive/string/parser.mjs +215 -3
  120. package/dist/lib/primitive/string/string.cjs +926 -5
  121. package/dist/lib/primitive/string/string.mjs +903 -5
  122. package/dist/lib/primitive/string/types.cjs +18 -1
  123. package/dist/lib/primitive/types.cjs +18 -1
  124. package/dist/lib/url/index.cjs +327 -1
  125. package/dist/lib/url/index.mjs +304 -1
  126. package/dist/lib/url/parser.cjs +325 -1
  127. package/dist/lib/url/parser.mjs +304 -1
  128. package/dist/lib/url/types.cjs +18 -1
  129. package/package.json +5 -5
@@ -1,8 +1,522 @@
1
- var w=class extends Error{constructor(U,p,s,n){super(`${U} at line ${s}, column ${n} (position ${p})`);this.position=p;this.line=s;this.column=n;this.name="ParseError"}};function K(f,I={}){if(typeof f!="string")throw new TypeError("Input must be a string");if(f.trim().length===0)throw new w("Input string is empty",0,1,1);let p={...{allowUnquotedKeys:!0,allowTrailingCommas:!0,allowSingleQuotes:!0,allowComments:!0,allowUndefined:!1,allowSpecialNumbers:!1,reviver:void 0,strict:!1,maxDepth:100},...I},s=0,n=f[0],k=1,y=1,b=0,u=p,g=f.length,c=()=>s>=g,i=()=>{n===`
2
- `?(k++,y=1):y++,s++,s<g?n=f[s]:n=""},h=(r=1)=>{let e=s+r;return e<g?f[e]:""},a=r=>new w(r,s,k,y),O=()=>{for(;!c()&&(n===" "||n===" "||n===`
3
- `||n==="\r");)i()},q=()=>{for(i();!c()&&n!==`
4
- `&&n!=="\r";)i()},E=()=>{for(i();!c();){if(n==="*"&&h()==="/"){i(),i();return}i()}throw a("Unterminated block comment")},d=()=>{for(;!c();){let r=s;if(O(),u.allowComments&&n==="/"){let e=h();if(e==="/"){q();continue}else if(e==="*"){E();continue}}if(s===r)break}},C=()=>{if(b++,b>u.maxDepth)throw a(`Maximum nesting depth (${u.maxDepth}) exceeded`);if(d(),c())throw a("Unexpected end of input");let r,e=n;return e==="{"?r=T():e==="["?r=A():e==='"'||e==="'"?r=S():e==="-"||e>="0"&&e<="9"?r=R():e==="t"||e==="f"||e==="n"||e==="u"&&u.allowUndefined?r=v():(e==="I"||e==="N")&&u.allowSpecialNumbers&&(r=j()),b--,r},T=()=>{let r={};if(i(),d(),n==="}")return i(),r;for(;!c();){d();let e,t=n;if(t==='"'||t==="'")e=S();else if(u.allowUnquotedKeys&&(t>="a"&&t<="z"||t>="A"&&t<="Z"||t==="_"||t==="$")){let l=s;for(;!c()&&(n>="a"&&n<="z"||n>="A"&&n<="Z"||n>="0"&&n<="9"||n==="_"||n==="$");)i();if(e=f.slice(l,s),e==="true"||e==="false"||e==="null"||u.allowUndefined&&e==="undefined")throw a(`Keyword "${e}" cannot be used as unquoted property name`)}else throw a(`Expected property name, got "${n}"`);d(),i(),d(),r[e]=C(),d();let o=n;if(o==="}")return i(),r;if(o===","){if(i(),d(),n==="}"){if(u.allowTrailingCommas)return i(),r;throw a("Trailing comma not allowed")}continue}}throw a("Unexpected end of input in object")},A=()=>{let r=[];if(i(),d(),n==="]")return i(),r;for(;!c();){r.push(C()),d();let e=n;if(e==="]")return i(),r;if(e===","){if(i(),d(),n==="]"){if(u.allowTrailingCommas)return i(),r;throw a("Trailing comma not allowed")}continue}throw a(`Expected comma or closing bracket, got "${e}"`)}throw a("Unexpected end of input in array")},S=()=>{let r=n,e=s;if(r==="'"&&!u.allowSingleQuotes)throw a("Single quotes are not allowed");i();let t="";for(;!c();){let o=n;if(o==="\\"){if(i(),c())throw a("Unterminated escape sequence");t+=P(r)}else{if(o===r)return i(),t;if(o===`
5
- `||o==="\r")throw a("Unterminated string literal");t+=o,i()}}throw a(`Unterminated string literal starting at position ${e}`)},P=r=>{let e=n;if(e==="b")return i(),"\b";if(e==="f")return i(),"\f";if(e==="n")return i(),`
6
- `;if(e==="r")return i(),"\r";if(e==="t")return i()," ";if(e==="v")return i(),"\v";if(e==="0")return i(),"\0";if(e==="x")return i(),$(2);if(e==="u")return i(),F();if(e===`
7
- `)return i(),"";if(e==="\r")return h()===`
8
- `&&i(),i(),"";{let t=e;return i(),t}},$=r=>{let e="";for(let t=0;t<r;t++){let o=n,l=o>="0"&&o<="9"||o>="a"&&o<="f"||o>="A"&&o<="F";if(c()||!l)throw a("Invalid hex escape sequence");e+=o,i()}return String.fromCharCode(parseInt(e,16))},F=()=>{if(n==="{"){i();let e="";for(;!c()&&n!=="}";){let o=n;if(!(o>="0"&&o<="9"||o>="a"&&o<="f"||o>="A"&&o<="F"))throw a("Invalid Unicode code point");e+=o,i()}if(n!=="}")throw a("Unterminated Unicode code point escape");i();let t=parseInt(e,16);if(isNaN(t)||t>1114111)throw a("Invalid Unicode code point");return String.fromCodePoint(t)}return $(4)},R=()=>{let r=s,e="";if(n==="-"&&(e+=n,i()),u.allowSpecialNumbers){if(n==="I"){if(f.slice(s,s+8)==="Infinity"){for(let l=0;l<8;l++)i();return e==="-"?-1/0:1/0}}else if(n==="N"&&f.slice(s,s+3)==="NaN"){for(let l=0;l<3;l++)i();return NaN}}if(n==="0"&&(e+=n,i(),u.allowUnquotedKeys)){let o=e.charAt(1);if(o==="x"||o==="X")return i(),x(16);if(o==="o"||o==="O")return i(),x(8);if(o==="b"||o==="B")return i(),x(2)}for(;!c()&&n>="0"&&n<="9";)e+=n,i();if(n==="."){if(e+=n,i(),!(n>="0"&&n<="9"))throw a("Expected digit after decimal point");for(;!c()&&n>="0"&&n<="9";)e+=n,i()}if(n==="e"||n==="E"){if(e+=n,i(),(h()==="+"||h()==="-")&&(e+=n,i()),!(n>="0"&&n<="9"))throw a("Expected digit in exponent");for(;!c()&&n>="0"&&n<="9";)e+=n,i()}let t=parseFloat(e);if(isNaN(t))throw a(`Invalid number "${e}"`);return t},x=r=>{let e="";for(;!c();){let t=n,o=!1;if(r===16?o=t>="0"&&t<="9"||t>="a"&&t<="f"||t>="A"&&t<="F":r===8?o=t>="0"&&t<="7":r===2&&(o=t==="0"||t==="1"),!o)break;e+=t,i()}if(e.length===0)throw a(`Invalid ${r===16?"hexadecimal":r===8?"octal":"binary"} number`);return parseInt(e,r)},j=()=>{if(n==="I"&&f.slice(s,s+8)==="Infinity"){for(let r=0;r<8;r++)i();return 1/0}else if(n==="N"&&f.slice(s,s+3)==="NaN"){for(let r=0;r<3;r++)i();return NaN}else if(n==="-"&&f.slice(s,s+9)==="-Infinity"){for(let r=0;r<9;r++)i();return-1/0}throw a("Invalid special number")},v=()=>{let r=s,e="";for(;!c();){let t=n;if(!(t>="a"&&t<="z"||t>="A"&&t<="Z"||t>="0"&&t<="9"||t==="_"||t==="$"))break;e+=t,i()}if(e==="true")return!0;if(e==="false")return!1;if(e==="null")return null;if(e==="undefined"&&u.allowUndefined)return;throw a(`Unknown keyword "${e}"`)},N=(r,e,t,o)=>{if(t&&typeof t=="object"){if(Array.isArray(t))for(let l=0;l<t.length;l++){let m=N(t,l.toString(),t[l],o);m===void 0?(t.splice(l,1),l--):t[l]=m}else for(let l in t)if(Object.prototype.hasOwnProperty.call(t,l)){let m=N(t,l,t[l],o);m===void 0?delete t[l]:t[l]=m}}return o.call(r,e,t)};try{d();let r=C();if(d(),!c())throw a(`Unexpected trailing content: "${f.slice(s,s+20)}"`);return p.reviver?N({"":r},"",r,p.reviver):r}catch(r){if(!p.strict&&r instanceof w)try{return p.reviver?JSON.parse(f,p.reviver):JSON.parse(f)}catch{throw r}throw r}}export{K as parseObjectLiteral};
1
+ // src/lib/primitive/string/parser-2.ts
2
+ var ParseError = class extends Error {
3
+ constructor(message, position, line, column) {
4
+ super(`${message} at line ${line}, column ${column} (position ${position})`);
5
+ this.position = position;
6
+ this.line = line;
7
+ this.column = column;
8
+ this.name = "ParseError";
9
+ }
10
+ };
11
+ function parseObjectLiteral(str, options = {}) {
12
+ if (typeof str !== "string") {
13
+ throw new TypeError("Input must be a string");
14
+ }
15
+ if (str.trim().length === 0) {
16
+ throw new ParseError("Input string is empty", 0, 1, 1);
17
+ }
18
+ const defaultOptions = {
19
+ allowUnquotedKeys: true,
20
+ allowTrailingCommas: true,
21
+ allowSingleQuotes: true,
22
+ allowComments: true,
23
+ allowUndefined: false,
24
+ allowSpecialNumbers: false,
25
+ reviver: void 0,
26
+ strict: false,
27
+ maxDepth: 100
28
+ };
29
+ const mergedOptions = {
30
+ ...defaultOptions,
31
+ ...options
32
+ };
33
+ let index = 0;
34
+ let char = str[0];
35
+ let line = 1;
36
+ let column = 1;
37
+ let depth = 0;
38
+ const optionsRef = mergedOptions;
39
+ const maxLength = str.length;
40
+ const isEnd = () => index >= maxLength;
41
+ const advance = () => {
42
+ if (char === "\n") {
43
+ line++;
44
+ column = 1;
45
+ } else {
46
+ column++;
47
+ }
48
+ index++;
49
+ if (index < maxLength) {
50
+ char = str[index];
51
+ } else {
52
+ char = "";
53
+ }
54
+ };
55
+ const peek = (offset = 1) => {
56
+ const peekIndex = index + offset;
57
+ return peekIndex < maxLength ? str[peekIndex] : "";
58
+ };
59
+ const createError = (message) => {
60
+ return new ParseError(message, index, line, column);
61
+ };
62
+ const skipWhitespace = () => {
63
+ while (!isEnd() && (char === " " || char === " " || char === "\n" || char === "\r")) {
64
+ advance();
65
+ }
66
+ };
67
+ const skipLineComment = () => {
68
+ advance();
69
+ while (!isEnd() && char !== "\n" && char !== "\r") {
70
+ advance();
71
+ }
72
+ };
73
+ const skipBlockComment = () => {
74
+ advance();
75
+ while (!isEnd()) {
76
+ if (char === "*" && peek() === "/") {
77
+ advance();
78
+ advance();
79
+ return;
80
+ }
81
+ advance();
82
+ }
83
+ throw createError("Unterminated block comment");
84
+ };
85
+ const skipWhitespaceAndComments = () => {
86
+ while (!isEnd()) {
87
+ const prevIndex = index;
88
+ skipWhitespace();
89
+ if (optionsRef.allowComments && char === "/") {
90
+ const nextChar = peek();
91
+ if (nextChar === "/") {
92
+ skipLineComment();
93
+ continue;
94
+ } else if (nextChar === "*") {
95
+ skipBlockComment();
96
+ continue;
97
+ }
98
+ }
99
+ if (index === prevIndex) {
100
+ break;
101
+ }
102
+ }
103
+ };
104
+ const parseValue = () => {
105
+ depth++;
106
+ if (depth > optionsRef.maxDepth) {
107
+ throw createError(`Maximum nesting depth (${optionsRef.maxDepth}) exceeded`);
108
+ }
109
+ skipWhitespaceAndComments();
110
+ if (isEnd()) {
111
+ throw createError("Unexpected end of input");
112
+ }
113
+ let value;
114
+ const currentChar = char;
115
+ if (currentChar === "{") {
116
+ value = parseObject();
117
+ } else if (currentChar === "[") {
118
+ value = parseArray();
119
+ } else if (currentChar === '"' || currentChar === "'") {
120
+ value = parseString();
121
+ } else if (currentChar === "-" || currentChar >= "0" && currentChar <= "9") {
122
+ value = parseNumber();
123
+ } else if (currentChar === "t" || currentChar === "f" || currentChar === "n") {
124
+ value = parseKeyword();
125
+ } else if (currentChar === "u" && optionsRef.allowUndefined) {
126
+ value = parseKeyword();
127
+ } else if ((currentChar === "I" || currentChar === "N") && optionsRef.allowSpecialNumbers) {
128
+ value = parseSpecialNumber();
129
+ } else {
130
+ }
131
+ depth--;
132
+ return value;
133
+ };
134
+ const parseObject = () => {
135
+ const obj = {};
136
+ advance();
137
+ skipWhitespaceAndComments();
138
+ if (char === "}") {
139
+ advance();
140
+ return obj;
141
+ }
142
+ while (!isEnd()) {
143
+ skipWhitespaceAndComments();
144
+ let key;
145
+ const currentChar = char;
146
+ if (currentChar === '"' || currentChar === "'") {
147
+ key = parseString();
148
+ } else if (optionsRef.allowUnquotedKeys && (currentChar >= "a" && currentChar <= "z" || currentChar >= "A" && currentChar <= "Z" || currentChar === "_" || currentChar === "$")) {
149
+ const start = index;
150
+ while (!isEnd() && (char >= "a" && char <= "z" || char >= "A" && char <= "Z" || char >= "0" && char <= "9" || char === "_" || char === "$")) {
151
+ advance();
152
+ }
153
+ key = str.slice(start, index);
154
+ if (key === "true" || key === "false" || key === "null" || optionsRef.allowUndefined && key === "undefined") {
155
+ throw createError(`Keyword "${key}" cannot be used as unquoted property name`);
156
+ }
157
+ } else {
158
+ throw createError(`Expected property name, got "${char}"`);
159
+ }
160
+ skipWhitespaceAndComments();
161
+ advance();
162
+ skipWhitespaceAndComments();
163
+ obj[key] = parseValue();
164
+ skipWhitespaceAndComments();
165
+ const nextChar = char;
166
+ if (nextChar === "}") {
167
+ advance();
168
+ return obj;
169
+ }
170
+ if (nextChar === ",") {
171
+ advance();
172
+ skipWhitespaceAndComments();
173
+ const afterCommaChar = char;
174
+ if (afterCommaChar === "}") {
175
+ if (optionsRef.allowTrailingCommas) {
176
+ advance();
177
+ return obj;
178
+ } else {
179
+ throw createError("Trailing comma not allowed");
180
+ }
181
+ }
182
+ continue;
183
+ }
184
+ continue;
185
+ }
186
+ throw createError("Unexpected end of input in object");
187
+ };
188
+ const parseArray = () => {
189
+ const arr = [];
190
+ advance();
191
+ skipWhitespaceAndComments();
192
+ if (char === "]") {
193
+ advance();
194
+ return arr;
195
+ }
196
+ while (!isEnd()) {
197
+ arr.push(parseValue());
198
+ skipWhitespaceAndComments();
199
+ const nextChar = char;
200
+ if (nextChar === "]") {
201
+ advance();
202
+ return arr;
203
+ }
204
+ if (nextChar === ",") {
205
+ advance();
206
+ skipWhitespaceAndComments();
207
+ const afterCommaChar = char;
208
+ if (afterCommaChar === "]") {
209
+ if (optionsRef.allowTrailingCommas) {
210
+ advance();
211
+ return arr;
212
+ } else {
213
+ throw createError("Trailing comma not allowed");
214
+ }
215
+ }
216
+ continue;
217
+ }
218
+ throw createError(`Expected comma or closing bracket, got "${nextChar}"`);
219
+ }
220
+ throw createError("Unexpected end of input in array");
221
+ };
222
+ const parseString = () => {
223
+ const quoteChar = char;
224
+ const startPos = index;
225
+ if (quoteChar === "'" && !optionsRef.allowSingleQuotes) {
226
+ throw createError("Single quotes are not allowed");
227
+ }
228
+ advance();
229
+ let result = "";
230
+ while (!isEnd()) {
231
+ const currentChar = char;
232
+ if (currentChar === "\\") {
233
+ advance();
234
+ if (isEnd()) {
235
+ throw createError("Unterminated escape sequence");
236
+ }
237
+ result += parseEscapeSequence(quoteChar);
238
+ } else if (currentChar === quoteChar) {
239
+ advance();
240
+ return result;
241
+ } else if (currentChar === "\n" || currentChar === "\r") {
242
+ throw createError("Unterminated string literal");
243
+ } else {
244
+ result += currentChar;
245
+ advance();
246
+ }
247
+ }
248
+ throw createError(`Unterminated string literal starting at position ${startPos}`);
249
+ };
250
+ const parseEscapeSequence = (quoteChar) => {
251
+ const escapeChar = char;
252
+ if (escapeChar === "b") {
253
+ advance();
254
+ return "\b";
255
+ } else if (escapeChar === "f") {
256
+ advance();
257
+ return "\f";
258
+ } else if (escapeChar === "n") {
259
+ advance();
260
+ return "\n";
261
+ } else if (escapeChar === "r") {
262
+ advance();
263
+ return "\r";
264
+ } else if (escapeChar === "t") {
265
+ advance();
266
+ return " ";
267
+ } else if (escapeChar === "v") {
268
+ advance();
269
+ return "\v";
270
+ } else if (escapeChar === "0") {
271
+ advance();
272
+ return "\0";
273
+ } else if (escapeChar === "x") {
274
+ advance();
275
+ return parseHexEscape(2);
276
+ } else if (escapeChar === "u") {
277
+ advance();
278
+ return parseUnicodeEscape();
279
+ } else if (escapeChar === "\n") {
280
+ advance();
281
+ return "";
282
+ } else if (escapeChar === "\r") {
283
+ if (peek() === "\n") {
284
+ advance();
285
+ advance();
286
+ } else {
287
+ advance();
288
+ }
289
+ return "";
290
+ } else {
291
+ const charToReturn = escapeChar;
292
+ advance();
293
+ return charToReturn;
294
+ }
295
+ };
296
+ const parseHexEscape = (length) => {
297
+ let hex = "";
298
+ for (let i = 0; i < length; i++) {
299
+ const currentChar = char;
300
+ const isHex = currentChar >= "0" && currentChar <= "9" || currentChar >= "a" && currentChar <= "f" || currentChar >= "A" && currentChar <= "F";
301
+ if (isEnd() || !isHex) {
302
+ throw createError("Invalid hex escape sequence");
303
+ }
304
+ hex += currentChar;
305
+ advance();
306
+ }
307
+ return String.fromCharCode(parseInt(hex, 16));
308
+ };
309
+ const parseUnicodeEscape = () => {
310
+ const currentChar = char;
311
+ if (currentChar === "{") {
312
+ advance();
313
+ let hex = "";
314
+ while (!isEnd() && char !== "}") {
315
+ const currentHexChar = char;
316
+ const isHex = currentHexChar >= "0" && currentHexChar <= "9" || currentHexChar >= "a" && currentHexChar <= "f" || currentHexChar >= "A" && currentHexChar <= "F";
317
+ if (!isHex) {
318
+ throw createError("Invalid Unicode code point");
319
+ }
320
+ hex += currentHexChar;
321
+ advance();
322
+ }
323
+ if (char !== "}") {
324
+ throw createError("Unterminated Unicode code point escape");
325
+ }
326
+ advance();
327
+ const codePoint = parseInt(hex, 16);
328
+ if (isNaN(codePoint) || codePoint > 1114111) {
329
+ throw createError("Invalid Unicode code point");
330
+ }
331
+ return String.fromCodePoint(codePoint);
332
+ }
333
+ return parseHexEscape(4);
334
+ };
335
+ const parseNumber = () => {
336
+ const start = index;
337
+ let numberStr = "";
338
+ if (char === "-") {
339
+ numberStr += char;
340
+ advance();
341
+ }
342
+ if (optionsRef.allowSpecialNumbers) {
343
+ if (char === "I") {
344
+ const word = str.slice(index, index + 8);
345
+ if (word === "Infinity") {
346
+ for (let i = 0; i < 8; i++) advance();
347
+ return numberStr === "-" ? -Infinity : Infinity;
348
+ }
349
+ } else if (char === "N") {
350
+ const word = str.slice(index, index + 3);
351
+ if (word === "NaN") {
352
+ for (let i = 0; i < 3; i++) advance();
353
+ return NaN;
354
+ }
355
+ }
356
+ }
357
+ if (char === "0") {
358
+ numberStr += char;
359
+ advance();
360
+ if (optionsRef.allowUnquotedKeys) {
361
+ const radixChar = numberStr.charAt(1);
362
+ if (radixChar === "x" || radixChar === "X") {
363
+ advance();
364
+ return parseNonDecimalNumber(16);
365
+ } else if (radixChar === "o" || radixChar === "O") {
366
+ advance();
367
+ return parseNonDecimalNumber(8);
368
+ } else if (radixChar === "b" || radixChar === "B") {
369
+ advance();
370
+ return parseNonDecimalNumber(2);
371
+ }
372
+ }
373
+ }
374
+ while (!isEnd() && char >= "0" && char <= "9") {
375
+ numberStr += char;
376
+ advance();
377
+ }
378
+ if (char === ".") {
379
+ numberStr += char;
380
+ advance();
381
+ if (!(char >= "0" && char <= "9")) {
382
+ throw createError("Expected digit after decimal point");
383
+ }
384
+ while (!isEnd() && char >= "0" && char <= "9") {
385
+ numberStr += char;
386
+ advance();
387
+ }
388
+ }
389
+ if (char === "e" || char === "E") {
390
+ numberStr += char;
391
+ advance();
392
+ if (peek() === "+" || peek() === "-") {
393
+ numberStr += char;
394
+ advance();
395
+ }
396
+ if (!(char >= "0" && char <= "9")) {
397
+ throw createError("Expected digit in exponent");
398
+ }
399
+ while (!isEnd() && char >= "0" && char <= "9") {
400
+ numberStr += char;
401
+ advance();
402
+ }
403
+ }
404
+ const num = parseFloat(numberStr);
405
+ if (isNaN(num)) {
406
+ throw createError(`Invalid number "${numberStr}"`);
407
+ }
408
+ return num;
409
+ };
410
+ const parseNonDecimalNumber = (radix) => {
411
+ let digits = "";
412
+ while (!isEnd()) {
413
+ const currentChar = char;
414
+ let isValid = false;
415
+ if (radix === 16) {
416
+ isValid = currentChar >= "0" && currentChar <= "9" || currentChar >= "a" && currentChar <= "f" || currentChar >= "A" && currentChar <= "F";
417
+ } else if (radix === 8) {
418
+ isValid = currentChar >= "0" && currentChar <= "7";
419
+ } else if (radix === 2) {
420
+ isValid = currentChar === "0" || currentChar === "1";
421
+ }
422
+ if (!isValid) {
423
+ break;
424
+ }
425
+ digits += currentChar;
426
+ advance();
427
+ }
428
+ if (digits.length === 0) {
429
+ const baseName = radix === 16 ? "hexadecimal" : radix === 8 ? "octal" : "binary";
430
+ throw createError(`Invalid ${baseName} number`);
431
+ }
432
+ return parseInt(digits, radix);
433
+ };
434
+ const parseSpecialNumber = () => {
435
+ if (char === "I" && str.slice(index, index + 8) === "Infinity") {
436
+ for (let i = 0; i < 8; i++) advance();
437
+ return Infinity;
438
+ } else if (char === "N" && str.slice(index, index + 3) === "NaN") {
439
+ for (let i = 0; i < 3; i++) advance();
440
+ return NaN;
441
+ } else if (char === "-" && str.slice(index, index + 9) === "-Infinity") {
442
+ for (let i = 0; i < 9; i++) advance();
443
+ return -Infinity;
444
+ }
445
+ throw createError("Invalid special number");
446
+ };
447
+ const parseKeyword = () => {
448
+ const start = index;
449
+ let keyword = "";
450
+ while (!isEnd()) {
451
+ const currentChar = char;
452
+ const isIdentifierChar = currentChar >= "a" && currentChar <= "z" || currentChar >= "A" && currentChar <= "Z" || currentChar >= "0" && currentChar <= "9" || currentChar === "_" || currentChar === "$";
453
+ if (!isIdentifierChar) {
454
+ break;
455
+ }
456
+ keyword += currentChar;
457
+ advance();
458
+ }
459
+ if (keyword === "true") {
460
+ return true;
461
+ } else if (keyword === "false") {
462
+ return false;
463
+ } else if (keyword === "null") {
464
+ return null;
465
+ } else if (keyword === "undefined" && optionsRef.allowUndefined) {
466
+ return void 0;
467
+ } else {
468
+ throw createError(`Unknown keyword "${keyword}"`);
469
+ }
470
+ };
471
+ const applyReviver = (holder, key, value, reviver) => {
472
+ if (value && typeof value === "object") {
473
+ if (Array.isArray(value)) {
474
+ for (let i = 0; i < value.length; i++) {
475
+ const transformed = applyReviver(value, i.toString(), value[i], reviver);
476
+ if (transformed === void 0) {
477
+ value.splice(i, 1);
478
+ i--;
479
+ } else {
480
+ value[i] = transformed;
481
+ }
482
+ }
483
+ } else {
484
+ for (const k in value) {
485
+ if (Object.prototype.hasOwnProperty.call(value, k)) {
486
+ const transformed = applyReviver(value, k, value[k], reviver);
487
+ if (transformed === void 0) {
488
+ delete value[k];
489
+ } else {
490
+ value[k] = transformed;
491
+ }
492
+ }
493
+ }
494
+ }
495
+ }
496
+ return reviver.call(holder, key, value);
497
+ };
498
+ try {
499
+ skipWhitespaceAndComments();
500
+ const result = parseValue();
501
+ skipWhitespaceAndComments();
502
+ if (!isEnd()) {
503
+ throw createError(`Unexpected trailing content: "${str.slice(index, index + 20)}"`);
504
+ }
505
+ if (mergedOptions.reviver) {
506
+ return applyReviver({ "": result }, "", result, mergedOptions.reviver);
507
+ }
508
+ return result;
509
+ } catch (error) {
510
+ if (!mergedOptions.strict && error instanceof ParseError) {
511
+ try {
512
+ return mergedOptions.reviver ? JSON.parse(str, mergedOptions.reviver) : JSON.parse(str);
513
+ } catch {
514
+ throw error;
515
+ }
516
+ }
517
+ throw error;
518
+ }
519
+ }
520
+ export {
521
+ parseObjectLiteral
522
+ };