json-stream-lite 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/parser.d.ts +36 -0
- package/dist/parser.js +38 -1
- package/dist/stringify.js +6 -0
- package/package.json +1 -1
package/dist/parser.d.ts
CHANGED
|
@@ -102,11 +102,47 @@ export declare class JsonString<T extends string = string> extends JsonEntity<T>
|
|
|
102
102
|
* @returns The parsed string value
|
|
103
103
|
*/
|
|
104
104
|
protected parse(): T;
|
|
105
|
+
/**
|
|
106
|
+
* Generator that yields the string content as raw byte chunks.
|
|
107
|
+
* Handles escape sequences by converting them to their actual byte values.
|
|
108
|
+
*
|
|
109
|
+
* @param chunkSize - The maximum size of each yielded byte array chunk (defaults to 1024)
|
|
110
|
+
* @yields Uint8Array chunks containing the unescaped string bytes
|
|
111
|
+
*/
|
|
105
112
|
streamBytes(chunkSize?: number): Generator<Uint8Array>;
|
|
113
|
+
/**
|
|
114
|
+
* Async generator that yields the string content as raw byte chunks from a stream.
|
|
115
|
+
* Handles escape sequences by converting them to their actual byte values.
|
|
116
|
+
* Waits for more data from the stream when needed.
|
|
117
|
+
*
|
|
118
|
+
* @param chunkSize - The maximum size of each yielded byte array chunk (defaults to 1024)
|
|
119
|
+
* @yields Uint8Array chunks containing the unescaped string bytes
|
|
120
|
+
*/
|
|
106
121
|
streamBytesAsync(chunkSize?: number): AsyncGenerator<Uint8Array>;
|
|
122
|
+
/**
|
|
123
|
+
* Generator that yields the string content as chunks of strings.
|
|
124
|
+
*
|
|
125
|
+
* @param chunkSize - The maximum size of each yielded string chunk (defaults to 1024)
|
|
126
|
+
* @yields Chunks of the string content
|
|
127
|
+
*/
|
|
107
128
|
stream(chunkSize?: number): Generator<string>;
|
|
129
|
+
/**
|
|
130
|
+
* Async generator that yields the string content as chunks of strings.
|
|
131
|
+
* @param chunkSize - The maximum size of each yielded string chunk (defaults to 1024)
|
|
132
|
+
* @yields Chunks of the string content
|
|
133
|
+
*/
|
|
108
134
|
streamAsync(chunkSize?: number): AsyncGenerator<string>;
|
|
135
|
+
/**
|
|
136
|
+
* Returns an iterator for string chunks.
|
|
137
|
+
* Enables use of for...of loops on JsonString.
|
|
138
|
+
* @yields Chunks of the string content
|
|
139
|
+
*/
|
|
109
140
|
[Symbol.iterator](): Generator<string, any, any>;
|
|
141
|
+
/**
|
|
142
|
+
* Returns an async iterator for string chunks.
|
|
143
|
+
* Enables use of for await...of loops on JsonString.
|
|
144
|
+
* @yields Chunks of the string content
|
|
145
|
+
*/
|
|
110
146
|
[Symbol.asyncIterator](): AsyncGenerator<string, any, any>;
|
|
111
147
|
}
|
|
112
148
|
/**
|
package/dist/parser.js
CHANGED
|
@@ -242,6 +242,13 @@ export class JsonString extends JsonEntity {
|
|
|
242
242
|
const chunk = bytes.next().value;
|
|
243
243
|
return bytesToString(chunk);
|
|
244
244
|
}
|
|
245
|
+
/**
|
|
246
|
+
* Generator that yields the string content as raw byte chunks.
|
|
247
|
+
* Handles escape sequences by converting them to their actual byte values.
|
|
248
|
+
*
|
|
249
|
+
* @param chunkSize - The maximum size of each yielded byte array chunk (defaults to 1024)
|
|
250
|
+
* @yields Uint8Array chunks containing the unescaped string bytes
|
|
251
|
+
*/
|
|
245
252
|
*streamBytes(chunkSize = 1024) {
|
|
246
253
|
if (this.buffer.peek() === BYTE_MAP.quotes) {
|
|
247
254
|
this.buffer.next(); // consume quotes
|
|
@@ -292,6 +299,14 @@ export class JsonString extends JsonEntity {
|
|
|
292
299
|
yield result;
|
|
293
300
|
}
|
|
294
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Async generator that yields the string content as raw byte chunks from a stream.
|
|
304
|
+
* Handles escape sequences by converting them to their actual byte values.
|
|
305
|
+
* Waits for more data from the stream when needed.
|
|
306
|
+
*
|
|
307
|
+
* @param chunkSize - The maximum size of each yielded byte array chunk (defaults to 1024)
|
|
308
|
+
* @yields Uint8Array chunks containing the unescaped string bytes
|
|
309
|
+
*/
|
|
295
310
|
async *streamBytesAsync(chunkSize = 1024) {
|
|
296
311
|
while (!this.buffer.atEof()) {
|
|
297
312
|
const stream = this.streamBytes(chunkSize);
|
|
@@ -308,19 +323,40 @@ export class JsonString extends JsonEntity {
|
|
|
308
323
|
}
|
|
309
324
|
}
|
|
310
325
|
}
|
|
326
|
+
/**
|
|
327
|
+
* Generator that yields the string content as chunks of strings.
|
|
328
|
+
*
|
|
329
|
+
* @param chunkSize - The maximum size of each yielded string chunk (defaults to 1024)
|
|
330
|
+
* @yields Chunks of the string content
|
|
331
|
+
*/
|
|
311
332
|
*stream(chunkSize = 1024) {
|
|
312
333
|
for (const chunk of this.streamBytes(chunkSize)) {
|
|
313
334
|
yield bytesToString(chunk);
|
|
314
335
|
}
|
|
315
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Async generator that yields the string content as chunks of strings.
|
|
339
|
+
* @param chunkSize - The maximum size of each yielded string chunk (defaults to 1024)
|
|
340
|
+
* @yields Chunks of the string content
|
|
341
|
+
*/
|
|
316
342
|
async *streamAsync(chunkSize = 1024) {
|
|
317
343
|
for await (const chunk of this.streamBytesAsync(chunkSize)) {
|
|
318
344
|
yield bytesToString(chunk);
|
|
319
345
|
}
|
|
320
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns an iterator for string chunks.
|
|
349
|
+
* Enables use of for...of loops on JsonString.
|
|
350
|
+
* @yields Chunks of the string content
|
|
351
|
+
*/
|
|
321
352
|
[Symbol.iterator]() {
|
|
322
353
|
return this.stream();
|
|
323
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* Returns an async iterator for string chunks.
|
|
357
|
+
* Enables use of for await...of loops on JsonString.
|
|
358
|
+
* @yields Chunks of the string content
|
|
359
|
+
*/
|
|
324
360
|
[Symbol.asyncIterator]() {
|
|
325
361
|
return this.streamAsync();
|
|
326
362
|
}
|
|
@@ -448,7 +484,8 @@ export class JsonValue extends JsonEntity {
|
|
|
448
484
|
}
|
|
449
485
|
else {
|
|
450
486
|
throw new Error('Unexpected token while parsing JSON value: ' +
|
|
451
|
-
String.fromCharCode(next ?? 0)
|
|
487
|
+
String.fromCharCode(next ?? 0) +
|
|
488
|
+
` (${next})`);
|
|
452
489
|
}
|
|
453
490
|
}
|
|
454
491
|
/**
|
package/dist/stringify.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-stream-lite",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "A lightweight, memory-efficient, zero-dependency streaming JSON parser and stringifier for JavaScript and TypeScript. It works in both Node.js and browser environments.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|