json-stream-lite 1.0.13 → 1.0.15
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/byte-buffer.js +2 -6
- package/dist/parser.d.ts +2 -2
- package/dist/parser.js +1 -1
- package/dist/stringify.js +2 -5
- package/dist/utils.js +4 -2
- package/package.json +1 -1
package/dist/byte-buffer.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { bytesToString } from './utils.js';
|
|
2
|
-
/**
|
|
3
|
-
* Shared TextEncoder instance for converting strings to UTF-8 bytes.
|
|
4
|
-
*/
|
|
5
|
-
const textEncoder = new TextEncoder();
|
|
1
|
+
import { bytesToString, stringToBytes } from './utils.js';
|
|
6
2
|
/**
|
|
7
3
|
* Default maximum buffer size before compaction
|
|
8
4
|
*/
|
|
@@ -119,7 +115,7 @@ export class ByteBuffer {
|
|
|
119
115
|
continue;
|
|
120
116
|
}
|
|
121
117
|
else if (typeof item === 'string') {
|
|
122
|
-
const encoded =
|
|
118
|
+
const encoded = stringToBytes(item);
|
|
123
119
|
for (const byte of encoded) {
|
|
124
120
|
this.buffer.push(byte);
|
|
125
121
|
}
|
package/dist/parser.d.ts
CHANGED
|
@@ -178,13 +178,13 @@ export declare class JsonValue<T extends unknown = unknown, K extends string = s
|
|
|
178
178
|
*
|
|
179
179
|
* @returns The actual JavaScript value (string, number, boolean, null, object, or array)
|
|
180
180
|
*/
|
|
181
|
-
readValue():
|
|
181
|
+
readValue(): T;
|
|
182
182
|
/**
|
|
183
183
|
* Asynchronously reads and fully evaluates the value.
|
|
184
184
|
*
|
|
185
185
|
* @returns A promise that resolves to the actual JavaScript value
|
|
186
186
|
*/
|
|
187
|
-
readValueAsync(): Promise<
|
|
187
|
+
readValueAsync(): Promise<T>;
|
|
188
188
|
/**
|
|
189
189
|
* Asynchronously reads the value entity from a stream.
|
|
190
190
|
*
|
package/dist/parser.js
CHANGED
|
@@ -390,7 +390,7 @@ export class JsonValue extends JsonEntity {
|
|
|
390
390
|
*/
|
|
391
391
|
async readValueAsync() {
|
|
392
392
|
const value = await this.readAsync();
|
|
393
|
-
return await value.readAsync();
|
|
393
|
+
return (await value.readAsync());
|
|
394
394
|
}
|
|
395
395
|
/**
|
|
396
396
|
* Asynchronously reads the value entity from a stream.
|
package/dist/stringify.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stringToBytes } from './utils';
|
|
1
2
|
/**
|
|
2
3
|
* Formats a string value for JSON output, escaping special characters.
|
|
3
4
|
* Yields the formatted string in chunks for memory efficiency.
|
|
@@ -184,10 +185,6 @@ function* jsonStreamStringifyWithDepth(value, replacer, indent = 0, currentDepth
|
|
|
184
185
|
export function jsonStreamStringify(value, replacer, indent = 0, options) {
|
|
185
186
|
return jsonStreamStringifyWithDepth(value, replacer, indent, 0, options);
|
|
186
187
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Shared TextEncoder instance for converting strings to UTF-8 bytes.
|
|
189
|
-
*/
|
|
190
|
-
const TEXT_ENCODER = new TextEncoder();
|
|
191
188
|
/**
|
|
192
189
|
* Converts a JavaScript value to JSON format, yielding Uint8Array byte chunks.
|
|
193
190
|
* Provides memory-efficient streaming stringification with binary output.
|
|
@@ -209,6 +206,6 @@ const TEXT_ENCODER = new TextEncoder();
|
|
|
209
206
|
export function* jsonStreamStringifyBytes(value, replacer, indent = 0, options) {
|
|
210
207
|
const stringGenerator = jsonStreamStringify(value, replacer, indent, options);
|
|
211
208
|
for (const chunk of stringGenerator) {
|
|
212
|
-
yield
|
|
209
|
+
yield stringToBytes(chunk);
|
|
213
210
|
}
|
|
214
211
|
}
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const textEncoder = new TextEncoder();
|
|
2
|
+
const textDecoder = new TextDecoder();
|
|
1
3
|
/**
|
|
2
4
|
* Converts a string to a Uint8Array of UTF-8 encoded bytes.
|
|
3
5
|
*
|
|
@@ -5,7 +7,7 @@
|
|
|
5
7
|
* @returns A Uint8Array containing the UTF-8 encoded bytes
|
|
6
8
|
*/
|
|
7
9
|
export function stringToBytes(str) {
|
|
8
|
-
return
|
|
10
|
+
return textEncoder.encode(str);
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Converts a Uint8Array of UTF-8 encoded bytes to a string.
|
|
@@ -14,7 +16,7 @@ export function stringToBytes(str) {
|
|
|
14
16
|
* @returns The decoded string
|
|
15
17
|
*/
|
|
16
18
|
export function bytesToString(bytes) {
|
|
17
|
-
return
|
|
19
|
+
return textDecoder.decode(bytes);
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
22
|
* Converts a Uint8Array of UTF-8 encoded bytes to a number.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-stream-lite",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.15",
|
|
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",
|