adofai 2.9.13 → 2.9.14

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 (58) hide show
  1. package/dist/src/effectProcessor.d.ts +32 -0
  2. package/dist/src/effectProcessor.js +90 -0
  3. package/dist/src/effectProcessor.js.map +1 -0
  4. package/dist/src/format.d.ts +8 -0
  5. package/dist/src/format.js +47 -0
  6. package/dist/src/format.js.map +1 -0
  7. package/dist/src/index.d.ts +5 -0
  8. package/dist/src/index.js +49 -0
  9. package/dist/src/index.js.map +1 -0
  10. package/dist/src/parser/ArrayBufferParser.d.ts +9 -0
  11. package/dist/src/parser/ArrayBufferParser.js +109 -0
  12. package/dist/src/parser/ArrayBufferParser.js.map +1 -0
  13. package/dist/src/parser/BufferParser.d.ts +9 -0
  14. package/dist/src/parser/BufferParser.js +103 -0
  15. package/dist/src/parser/BufferParser.js.map +1 -0
  16. package/{src/parser/Parser.ts → dist/src/parser/Parser.d.ts} +5 -6
  17. package/dist/src/parser/Parser.js +6 -0
  18. package/dist/src/parser/Parser.js.map +1 -0
  19. package/dist/src/parser/StringParser.d.ts +7 -0
  20. package/{src/parser/StringParser.ts → dist/src/parser/StringParser.js} +449 -438
  21. package/dist/src/parser/StringParser.js.map +1 -0
  22. package/dist/src/parser/index.d.ts +16 -0
  23. package/dist/src/parser/index.js +29 -0
  24. package/dist/src/parser/index.js.map +1 -0
  25. package/{src/parser.ts → dist/src/parser.d.ts} +1 -2
  26. package/dist/src/parser.js +15 -0
  27. package/dist/src/parser.js.map +1 -0
  28. package/dist/src/pathdata.d.ts +13 -0
  29. package/dist/src/pathdata.js +17 -0
  30. package/dist/src/pathdata.js.map +1 -0
  31. package/dist/src/presets.d.ts +10 -0
  32. package/{src/presets.ts → dist/src/presets.js} +13 -19
  33. package/dist/src/presets.js.map +1 -0
  34. package/dist/src/structure/Level.d.ts +54 -0
  35. package/dist/src/structure/Level.js +388 -0
  36. package/dist/src/structure/Level.js.map +1 -0
  37. package/{src/structure/interfaces.ts → dist/src/structure/interfaces.d.ts} +33 -38
  38. package/dist/src/structure/interfaces.js +3 -0
  39. package/dist/src/structure/interfaces.js.map +1 -0
  40. package/{src/structure.ts → dist/src/structure.d.ts} +4 -6
  41. package/dist/src/structure.js +5 -0
  42. package/dist/src/structure.js.map +1 -0
  43. package/package.json +6 -2
  44. package/.babelrc +0 -5
  45. package/index.ts +0 -12
  46. package/src/effectProcessor.ts +0 -82
  47. package/src/format.ts +0 -69
  48. package/src/parser/ArrayBufferParser.ts +0 -101
  49. package/src/parser/BufferParser.ts +0 -93
  50. package/src/parser/index.ts +0 -28
  51. package/src/pathdata.ts +0 -20
  52. package/src/structure/Level.ts +0 -351
  53. package/src/structure.ts.bak +0 -412
  54. package/test/Buffer.js +0 -2030
  55. package/test/editor.html +0 -501
  56. package/test/index.html +0 -31
  57. package/tsconfig.json +0 -17
  58. package/webpack.config.mjs +0 -35
@@ -1,438 +1,449 @@
1
- import Parser from "./Parser";
2
-
3
- class StringParser extends Parser<string, any> {
4
- parse(text: string | null, reviver?: (key: string, value: any) => any): any {
5
- if (text == null) return null;
6
- const result = new ParserX(text).parseValue();
7
- if (typeof reviver === "function") {
8
- return StringParser._applyReviver("", result, reviver);
9
- }
10
- return result;
11
- }
12
-
13
- stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): string {
14
- const serializer = new Serializer(replacer, space);
15
- return serializer.serialize(value);
16
- }
17
-
18
- static _applyReviver(key: string, value: any, reviver: (key: string, value: any) => any): any {
19
- if (value && typeof value === "object") {
20
- if (Array.isArray(value)) {
21
- for (let i = 0; i < value.length; i++) {
22
- value[i] = StringParser._applyReviver(i.toString(), value[i], reviver);
23
- }
24
- } else {
25
- for (const prop in value) {
26
- if (Object.prototype.hasOwnProperty.call(value, prop)) {
27
- value[prop] = StringParser._applyReviver(prop, value[prop], reviver);
28
- }
29
- }
30
- }
31
- }
32
- return reviver(key, value);
33
- }
34
- }
35
-
36
- class ParserX {
37
- static WHITE_SPACE = " \t\n\r\uFEFF";
38
- static WORD_BREAK = ' \t\n\r{}[],:"';
39
- static TOKEN = {
40
- NONE: 0,
41
- CURLY_OPEN: 1,
42
- CURLY_CLOSE: 2,
43
- SQUARED_OPEN: 3,
44
- SQUARED_CLOSE: 4,
45
- COLON: 5,
46
- COMMA: 6,
47
- STRING: 7,
48
- NUMBER: 8,
49
- TRUE: 9,
50
- FALSE: 10,
51
- NULL: 11,
52
- };
53
- private json: string;
54
- private position: number;
55
- private endSection: string | null;
56
- constructor(jsonString: string, endSection: string | null = null) {
57
- this.json = jsonString;
58
- this.position = 0;
59
- this.endSection = endSection;
60
- if (this.peek() === 0xfeff) {
61
- this.read();
62
- }
63
- }
64
- parseValue(): any {
65
- return this.parseByToken(this.nextToken);
66
- }
67
- parseObject(): Record<string, any> | null {
68
- const obj: Record<string, any> = {};
69
- this.read();
70
- while (true) {
71
- let nextToken;
72
- do {
73
- nextToken = this.nextToken;
74
- if (nextToken === ParserX.TOKEN.NONE) {
75
- return null;
76
- }
77
- if (nextToken === ParserX.TOKEN.CURLY_CLOSE) {
78
- return obj;
79
- }
80
- } while (nextToken === ParserX.TOKEN.COMMA);
81
- const key = this.parseString();
82
- if (key === null) {
83
- return null;
84
- }
85
- if (this.nextToken !== ParserX.TOKEN.COLON) {
86
- return null;
87
- }
88
- if (this.endSection == null || key !== this.endSection) {
89
- this.read();
90
- obj[key] = this.parseValue();
91
- } else {
92
- return obj;
93
- }
94
- }
95
- }
96
- parseArray(): any[] | null {
97
- const array: any[] = [];
98
- this.read();
99
- let parsing = true;
100
- while (parsing) {
101
- const nextToken = this.nextToken;
102
- switch (nextToken) {
103
- case ParserX.TOKEN.NONE:
104
- return null;
105
- case ParserX.TOKEN.SQUARED_CLOSE:
106
- parsing = false;
107
- break;
108
- case ParserX.TOKEN.COMMA:
109
- break;
110
- default:
111
- const value = this.parseByToken(nextToken);
112
- array.push(value);
113
- break;
114
- }
115
- }
116
- return array;
117
- }
118
- parseByToken(token: number): any {
119
- switch (token) {
120
- case ParserX.TOKEN.CURLY_OPEN:
121
- return this.parseObject();
122
- case ParserX.TOKEN.SQUARED_OPEN:
123
- return this.parseArray();
124
- case ParserX.TOKEN.STRING:
125
- return this.parseString();
126
- case ParserX.TOKEN.NUMBER:
127
- return this.parseNumber();
128
- case ParserX.TOKEN.TRUE:
129
- return true;
130
- case ParserX.TOKEN.FALSE:
131
- return false;
132
- case ParserX.TOKEN.NULL:
133
- return null;
134
- default:
135
- return null;
136
- }
137
- }
138
- parseString(): string | null {
139
- let result = "";
140
- this.read();
141
- let parsing = true;
142
- while (parsing) {
143
- if (this.peek() === -1) {
144
- break;
145
- }
146
- const char = this.nextChar;
147
- switch (char) {
148
- case '"':
149
- parsing = false;
150
- break;
151
- case "\\":
152
- if (this.peek() === -1) {
153
- parsing = false;
154
- break;
155
- }
156
- const escaped = this.nextChar;
157
- switch (escaped) {
158
- case '"':
159
- case "/":
160
- case "\\":
161
- result += escaped;
162
- break;
163
- case "b":
164
- result += "\b";
165
- break;
166
- case "f":
167
- result += "\f";
168
- break;
169
- case "n":
170
- result += "\n";
171
- break;
172
- case "r":
173
- result += "\r";
174
- break;
175
- case "t":
176
- result += "\t";
177
- break;
178
- case "u":
179
- let unicode = "";
180
- for (let i = 0; i < 4; i++) {
181
- unicode += this.nextChar;
182
- }
183
- result += String.fromCharCode(Number.parseInt(unicode, 16));
184
- break;
185
- }
186
- break;
187
- default:
188
- result += char;
189
- break;
190
- }
191
- }
192
- return result;
193
- }
194
- parseNumber(): number {
195
- const word = this.nextWord;
196
- if (word.indexOf(".") === -1) {
197
- return Number.parseInt(word, 10) || 0;
198
- } else {
199
- return Number.parseFloat(word) || 0.0;
200
- }
201
- }
202
- eatWhitespace(): void {
203
- while (ParserX.WHITE_SPACE.indexOf(this.peekChar) !== -1) {
204
- this.read();
205
- if (this.peek() === -1) {
206
- break;
207
- }
208
- }
209
- }
210
- peek(): number {
211
- if (this.position >= this.json.length) {
212
- return -1;
213
- }
214
- return this.json.charCodeAt(this.position);
215
- }
216
- read(): number {
217
- if (this.position >= this.json.length) {
218
- return -1;
219
- }
220
- return this.json.charCodeAt(this.position++);
221
- }
222
- get peekChar(): string {
223
- const code = this.peek();
224
- return code === -1 ? "\0" : String.fromCharCode(code);
225
- }
226
- get nextChar(): string {
227
- const code = this.read();
228
- return code === -1 ? "\0" : String.fromCharCode(code);
229
- }
230
- get nextWord(): string {
231
- let result = "";
232
- while (ParserX.WORD_BREAK.indexOf(this.peekChar) === -1) {
233
- result += this.nextChar;
234
- if (this.peek() === -1) {
235
- break;
236
- }
237
- }
238
- return result;
239
- }
240
- get nextToken(): number {
241
- this.eatWhitespace();
242
- if (this.peek() === -1) {
243
- return ParserX.TOKEN.NONE;
244
- }
245
- const char = this.peekChar;
246
- switch (char) {
247
- case '"':
248
- return ParserX.TOKEN.STRING;
249
- case ",":
250
- this.read();
251
- return ParserX.TOKEN.COMMA;
252
- case "-":
253
- case "0":
254
- case "1":
255
- case "2":
256
- case "3":
257
- case "4":
258
- case "5":
259
- case "6":
260
- case "7":
261
- case "8":
262
- case "9":
263
- return ParserX.TOKEN.NUMBER;
264
- case ":":
265
- return ParserX.TOKEN.COLON;
266
- case "[":
267
- return ParserX.TOKEN.SQUARED_OPEN;
268
- case "]":
269
- this.read();
270
- return ParserX.TOKEN.SQUARED_CLOSE;
271
- case "{":
272
- return ParserX.TOKEN.CURLY_OPEN;
273
- case "}":
274
- this.read();
275
- return ParserX.TOKEN.CURLY_CLOSE;
276
- default:
277
- const word = this.nextWord;
278
- switch (word) {
279
- case "false":
280
- return ParserX.TOKEN.FALSE;
281
- case "true":
282
- return ParserX.TOKEN.TRUE;
283
- case "null":
284
- return ParserX.TOKEN.NULL;
285
- default:
286
- return ParserX.TOKEN.NONE;
287
- }
288
- }
289
- }
290
- }
291
-
292
- class Serializer {
293
- private result: string = "";
294
- private replacer: ((key: string, value: any) => any) | null;
295
- private space: string | number | null;
296
- private indent: number = 0;
297
- private indentStr: string = "";
298
- constructor(replacer?: (key: string, value: any) => any, space?: string | number) {
299
- this.replacer = replacer || null;
300
- this.space = space || null;
301
- if (typeof space === "number") {
302
- this.indentStr = " ".repeat(Math.min(10, Math.max(0, space)));
303
- } else if (typeof space === "string") {
304
- this.indentStr = space.slice(0, 10);
305
- }
306
- }
307
- serialize(obj: any): string {
308
- this.result = "";
309
- this.serializeValue(obj, "");
310
- return this.result;
311
- }
312
- private serializeValue(value: any, key: string = ""): void {
313
- if (typeof this.replacer === "function") {
314
- value = this.replacer(key, value);
315
- }
316
- if (value === null || value === undefined) {
317
- this.result += "null";
318
- } else if (typeof value === "string") {
319
- this.serializeString(value);
320
- } else if (typeof value === "boolean") {
321
- this.result += value.toString();
322
- } else if (Array.isArray(value)) {
323
- this.serializeArray(value);
324
- } else if (typeof value === "object") {
325
- this.serializeObject(value);
326
- } else {
327
- this.serializeOther(value);
328
- }
329
- }
330
- private serializeObject(obj: Record<string, any>): void {
331
- let first = true;
332
- this.result += "{";
333
- if (this.indentStr) {
334
- this.result += "\n";
335
- this.indent++;
336
- }
337
- for (const key in obj) {
338
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
339
- if (Array.isArray(this.replacer) && !this.replacer.includes(key)) {
340
- continue;
341
- }
342
- if (!first) {
343
- this.result += ",";
344
- if (this.indentStr) this.result += "\n";
345
- }
346
- if (this.indentStr) {
347
- this.result += this.indentStr.repeat(this.indent);
348
- }
349
- this.serializeString(key.toString());
350
- this.result += ":";
351
- if (this.indentStr) this.result += " ";
352
- this.serializeValue(obj[key], key);
353
- first = false;
354
- }
355
- }
356
- if (this.indentStr) {
357
- this.result += "\n";
358
- this.indent--;
359
- this.result += this.indentStr.repeat(this.indent);
360
- }
361
- this.result += "}";
362
- }
363
- private serializeArray(array: any[]): void {
364
- this.result += "[";
365
- if (this.indentStr && array.length > 0) {
366
- this.result += "\n";
367
- this.indent++;
368
- }
369
- let first = true;
370
- for (let i = 0; i < array.length; i++) {
371
- if (!first) {
372
- this.result += ",";
373
- if (this.indentStr) this.result += "\n";
374
- }
375
- if (this.indentStr) {
376
- this.result += this.indentStr.repeat(this.indent);
377
- }
378
- this.serializeValue(array[i], i.toString());
379
- first = false;
380
- }
381
- if (this.indentStr && array.length > 0) {
382
- this.result += "\n";
383
- this.indent--;
384
- this.result += this.indentStr.repeat(this.indent);
385
- }
386
- this.result += "]";
387
- }
388
- private serializeString(str: string): void {
389
- this.result += '"';
390
- for (const char of str) {
391
- switch (char) {
392
- case "\b":
393
- this.result += "\\b";
394
- break;
395
- case "\t":
396
- this.result += "\\t";
397
- break;
398
- case "\n":
399
- this.result += "\\n";
400
- break;
401
- case "\f":
402
- this.result += "\\f";
403
- break;
404
- case "\r":
405
- this.result += "\\r";
406
- break;
407
- case '"':
408
- this.result += '\\"';
409
- break;
410
- case "\\":
411
- this.result += "\\\\";
412
- break;
413
- default:
414
- const code = char.charCodeAt(0);
415
- if (code >= 32 && code <= 126) {
416
- this.result += char;
417
- } else {
418
- this.result += "\\u" + code.toString(16).padStart(4, "0");
419
- }
420
- break;
421
- }
422
- }
423
- this.result += '"';
424
- }
425
- private serializeOther(value: any): void {
426
- if (typeof value === "number") {
427
- if (isFinite(value)) {
428
- this.result += value.toString();
429
- } else {
430
- this.result += "null";
431
- }
432
- } else {
433
- this.serializeString(value.toString());
434
- }
435
- }
436
- }
437
-
438
- export default StringParser;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const Parser_1 = __importDefault(require("./Parser"));
7
+ class StringParser extends Parser_1.default {
8
+ parse(text, reviver) {
9
+ if (text == null)
10
+ return null;
11
+ const result = new ParserX(text).parseValue();
12
+ if (typeof reviver === "function") {
13
+ return StringParser._applyReviver("", result, reviver);
14
+ }
15
+ return result;
16
+ }
17
+ stringify(value, replacer, space) {
18
+ const serializer = new Serializer(replacer, space);
19
+ return serializer.serialize(value);
20
+ }
21
+ static _applyReviver(key, value, reviver) {
22
+ if (value && typeof value === "object") {
23
+ if (Array.isArray(value)) {
24
+ for (let i = 0; i < value.length; i++) {
25
+ value[i] = StringParser._applyReviver(i.toString(), value[i], reviver);
26
+ }
27
+ }
28
+ else {
29
+ for (const prop in value) {
30
+ if (Object.prototype.hasOwnProperty.call(value, prop)) {
31
+ value[prop] = StringParser._applyReviver(prop, value[prop], reviver);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return reviver(key, value);
37
+ }
38
+ }
39
+ class ParserX {
40
+ constructor(jsonString, endSection = null) {
41
+ this.json = jsonString;
42
+ this.position = 0;
43
+ this.endSection = endSection;
44
+ if (this.peek() === 0xfeff) {
45
+ this.read();
46
+ }
47
+ }
48
+ parseValue() {
49
+ return this.parseByToken(this.nextToken);
50
+ }
51
+ parseObject() {
52
+ const obj = {};
53
+ this.read();
54
+ while (true) {
55
+ let nextToken;
56
+ do {
57
+ nextToken = this.nextToken;
58
+ if (nextToken === ParserX.TOKEN.NONE) {
59
+ return null;
60
+ }
61
+ if (nextToken === ParserX.TOKEN.CURLY_CLOSE) {
62
+ return obj;
63
+ }
64
+ } while (nextToken === ParserX.TOKEN.COMMA);
65
+ const key = this.parseString();
66
+ if (key === null) {
67
+ return null;
68
+ }
69
+ if (this.nextToken !== ParserX.TOKEN.COLON) {
70
+ return null;
71
+ }
72
+ if (this.endSection == null || key !== this.endSection) {
73
+ this.read();
74
+ obj[key] = this.parseValue();
75
+ }
76
+ else {
77
+ return obj;
78
+ }
79
+ }
80
+ }
81
+ parseArray() {
82
+ const array = [];
83
+ this.read();
84
+ let parsing = true;
85
+ while (parsing) {
86
+ const nextToken = this.nextToken;
87
+ switch (nextToken) {
88
+ case ParserX.TOKEN.NONE:
89
+ return null;
90
+ case ParserX.TOKEN.SQUARED_CLOSE:
91
+ parsing = false;
92
+ break;
93
+ case ParserX.TOKEN.COMMA:
94
+ break;
95
+ default:
96
+ const value = this.parseByToken(nextToken);
97
+ array.push(value);
98
+ break;
99
+ }
100
+ }
101
+ return array;
102
+ }
103
+ parseByToken(token) {
104
+ switch (token) {
105
+ case ParserX.TOKEN.CURLY_OPEN:
106
+ return this.parseObject();
107
+ case ParserX.TOKEN.SQUARED_OPEN:
108
+ return this.parseArray();
109
+ case ParserX.TOKEN.STRING:
110
+ return this.parseString();
111
+ case ParserX.TOKEN.NUMBER:
112
+ return this.parseNumber();
113
+ case ParserX.TOKEN.TRUE:
114
+ return true;
115
+ case ParserX.TOKEN.FALSE:
116
+ return false;
117
+ case ParserX.TOKEN.NULL:
118
+ return null;
119
+ default:
120
+ return null;
121
+ }
122
+ }
123
+ parseString() {
124
+ let result = "";
125
+ this.read();
126
+ let parsing = true;
127
+ while (parsing) {
128
+ if (this.peek() === -1) {
129
+ break;
130
+ }
131
+ const char = this.nextChar;
132
+ switch (char) {
133
+ case '"':
134
+ parsing = false;
135
+ break;
136
+ case "\\":
137
+ if (this.peek() === -1) {
138
+ parsing = false;
139
+ break;
140
+ }
141
+ const escaped = this.nextChar;
142
+ switch (escaped) {
143
+ case '"':
144
+ case "/":
145
+ case "\\":
146
+ result += escaped;
147
+ break;
148
+ case "b":
149
+ result += "\b";
150
+ break;
151
+ case "f":
152
+ result += "\f";
153
+ break;
154
+ case "n":
155
+ result += "\n";
156
+ break;
157
+ case "r":
158
+ result += "\r";
159
+ break;
160
+ case "t":
161
+ result += "\t";
162
+ break;
163
+ case "u":
164
+ let unicode = "";
165
+ for (let i = 0; i < 4; i++) {
166
+ unicode += this.nextChar;
167
+ }
168
+ result += String.fromCharCode(Number.parseInt(unicode, 16));
169
+ break;
170
+ }
171
+ break;
172
+ default:
173
+ result += char;
174
+ break;
175
+ }
176
+ }
177
+ return result;
178
+ }
179
+ parseNumber() {
180
+ const word = this.nextWord;
181
+ if (word.indexOf(".") === -1) {
182
+ return Number.parseInt(word, 10) || 0;
183
+ }
184
+ else {
185
+ return Number.parseFloat(word) || 0.0;
186
+ }
187
+ }
188
+ eatWhitespace() {
189
+ while (ParserX.WHITE_SPACE.indexOf(this.peekChar) !== -1) {
190
+ this.read();
191
+ if (this.peek() === -1) {
192
+ break;
193
+ }
194
+ }
195
+ }
196
+ peek() {
197
+ if (this.position >= this.json.length) {
198
+ return -1;
199
+ }
200
+ return this.json.charCodeAt(this.position);
201
+ }
202
+ read() {
203
+ if (this.position >= this.json.length) {
204
+ return -1;
205
+ }
206
+ return this.json.charCodeAt(this.position++);
207
+ }
208
+ get peekChar() {
209
+ const code = this.peek();
210
+ return code === -1 ? "\0" : String.fromCharCode(code);
211
+ }
212
+ get nextChar() {
213
+ const code = this.read();
214
+ return code === -1 ? "\0" : String.fromCharCode(code);
215
+ }
216
+ get nextWord() {
217
+ let result = "";
218
+ while (ParserX.WORD_BREAK.indexOf(this.peekChar) === -1) {
219
+ result += this.nextChar;
220
+ if (this.peek() === -1) {
221
+ break;
222
+ }
223
+ }
224
+ return result;
225
+ }
226
+ get nextToken() {
227
+ this.eatWhitespace();
228
+ if (this.peek() === -1) {
229
+ return ParserX.TOKEN.NONE;
230
+ }
231
+ const char = this.peekChar;
232
+ switch (char) {
233
+ case '"':
234
+ return ParserX.TOKEN.STRING;
235
+ case ",":
236
+ this.read();
237
+ return ParserX.TOKEN.COMMA;
238
+ case "-":
239
+ case "0":
240
+ case "1":
241
+ case "2":
242
+ case "3":
243
+ case "4":
244
+ case "5":
245
+ case "6":
246
+ case "7":
247
+ case "8":
248
+ case "9":
249
+ return ParserX.TOKEN.NUMBER;
250
+ case ":":
251
+ return ParserX.TOKEN.COLON;
252
+ case "[":
253
+ return ParserX.TOKEN.SQUARED_OPEN;
254
+ case "]":
255
+ this.read();
256
+ return ParserX.TOKEN.SQUARED_CLOSE;
257
+ case "{":
258
+ return ParserX.TOKEN.CURLY_OPEN;
259
+ case "}":
260
+ this.read();
261
+ return ParserX.TOKEN.CURLY_CLOSE;
262
+ default:
263
+ const word = this.nextWord;
264
+ switch (word) {
265
+ case "false":
266
+ return ParserX.TOKEN.FALSE;
267
+ case "true":
268
+ return ParserX.TOKEN.TRUE;
269
+ case "null":
270
+ return ParserX.TOKEN.NULL;
271
+ default:
272
+ return ParserX.TOKEN.NONE;
273
+ }
274
+ }
275
+ }
276
+ }
277
+ ParserX.WHITE_SPACE = " \t\n\r\uFEFF";
278
+ ParserX.WORD_BREAK = ' \t\n\r{}[],:"';
279
+ ParserX.TOKEN = {
280
+ NONE: 0,
281
+ CURLY_OPEN: 1,
282
+ CURLY_CLOSE: 2,
283
+ SQUARED_OPEN: 3,
284
+ SQUARED_CLOSE: 4,
285
+ COLON: 5,
286
+ COMMA: 6,
287
+ STRING: 7,
288
+ NUMBER: 8,
289
+ TRUE: 9,
290
+ FALSE: 10,
291
+ NULL: 11,
292
+ };
293
+ class Serializer {
294
+ constructor(replacer, space) {
295
+ this.result = "";
296
+ this.indent = 0;
297
+ this.indentStr = "";
298
+ this.replacer = replacer || null;
299
+ this.space = space || null;
300
+ if (typeof space === "number") {
301
+ this.indentStr = " ".repeat(Math.min(10, Math.max(0, space)));
302
+ }
303
+ else if (typeof space === "string") {
304
+ this.indentStr = space.slice(0, 10);
305
+ }
306
+ }
307
+ serialize(obj) {
308
+ this.result = "";
309
+ this.serializeValue(obj, "");
310
+ return this.result;
311
+ }
312
+ serializeValue(value, key = "") {
313
+ if (typeof this.replacer === "function") {
314
+ value = this.replacer(key, value);
315
+ }
316
+ if (value === null || value === undefined) {
317
+ this.result += "null";
318
+ }
319
+ else if (typeof value === "string") {
320
+ this.serializeString(value);
321
+ }
322
+ else if (typeof value === "boolean") {
323
+ this.result += value.toString();
324
+ }
325
+ else if (Array.isArray(value)) {
326
+ this.serializeArray(value);
327
+ }
328
+ else if (typeof value === "object") {
329
+ this.serializeObject(value);
330
+ }
331
+ else {
332
+ this.serializeOther(value);
333
+ }
334
+ }
335
+ serializeObject(obj) {
336
+ let first = true;
337
+ this.result += "{";
338
+ if (this.indentStr) {
339
+ this.result += "\n";
340
+ this.indent++;
341
+ }
342
+ for (const key in obj) {
343
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
344
+ if (Array.isArray(this.replacer) && !this.replacer.includes(key)) {
345
+ continue;
346
+ }
347
+ if (!first) {
348
+ this.result += ",";
349
+ if (this.indentStr)
350
+ this.result += "\n";
351
+ }
352
+ if (this.indentStr) {
353
+ this.result += this.indentStr.repeat(this.indent);
354
+ }
355
+ this.serializeString(key.toString());
356
+ this.result += ":";
357
+ if (this.indentStr)
358
+ this.result += " ";
359
+ this.serializeValue(obj[key], key);
360
+ first = false;
361
+ }
362
+ }
363
+ if (this.indentStr) {
364
+ this.result += "\n";
365
+ this.indent--;
366
+ this.result += this.indentStr.repeat(this.indent);
367
+ }
368
+ this.result += "}";
369
+ }
370
+ serializeArray(array) {
371
+ this.result += "[";
372
+ if (this.indentStr && array.length > 0) {
373
+ this.result += "\n";
374
+ this.indent++;
375
+ }
376
+ let first = true;
377
+ for (let i = 0; i < array.length; i++) {
378
+ if (!first) {
379
+ this.result += ",";
380
+ if (this.indentStr)
381
+ this.result += "\n";
382
+ }
383
+ if (this.indentStr) {
384
+ this.result += this.indentStr.repeat(this.indent);
385
+ }
386
+ this.serializeValue(array[i], i.toString());
387
+ first = false;
388
+ }
389
+ if (this.indentStr && array.length > 0) {
390
+ this.result += "\n";
391
+ this.indent--;
392
+ this.result += this.indentStr.repeat(this.indent);
393
+ }
394
+ this.result += "]";
395
+ }
396
+ serializeString(str) {
397
+ this.result += '"';
398
+ for (const char of str) {
399
+ switch (char) {
400
+ case "\b":
401
+ this.result += "\\b";
402
+ break;
403
+ case "\t":
404
+ this.result += "\\t";
405
+ break;
406
+ case "\n":
407
+ this.result += "\\n";
408
+ break;
409
+ case "\f":
410
+ this.result += "\\f";
411
+ break;
412
+ case "\r":
413
+ this.result += "\\r";
414
+ break;
415
+ case '"':
416
+ this.result += '\\"';
417
+ break;
418
+ case "\\":
419
+ this.result += "\\\\";
420
+ break;
421
+ default:
422
+ const code = char.charCodeAt(0);
423
+ if (code >= 32 && code <= 126) {
424
+ this.result += char;
425
+ }
426
+ else {
427
+ this.result += "\\u" + code.toString(16).padStart(4, "0");
428
+ }
429
+ break;
430
+ }
431
+ }
432
+ this.result += '"';
433
+ }
434
+ serializeOther(value) {
435
+ if (typeof value === "number") {
436
+ if (isFinite(value)) {
437
+ this.result += value.toString();
438
+ }
439
+ else {
440
+ this.result += "null";
441
+ }
442
+ }
443
+ else {
444
+ this.serializeString(value.toString());
445
+ }
446
+ }
447
+ }
448
+ exports.default = StringParser;
449
+ //# sourceMappingURL=StringParser.js.map