json-stream-lite 1.0.1 → 1.0.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.
Files changed (3) hide show
  1. package/EXAMPLES.md +19 -12
  2. package/README.md +1 -1
  3. package/package.json +1 -1
package/EXAMPLES.md CHANGED
@@ -468,27 +468,34 @@ const nestedJson = Array.from(jsonStreamStringify(nested, null, 2)).join('')
468
468
  console.log(nestedJson)
469
469
 
470
470
  // Example 4: Using a replacer function
471
+ // Note: The replacer function is called on each value (with the key parameter, which is '' for the root) during stringification.
471
472
  console.log('\n=== Example 4: With Replacer Function ===')
472
- const withSecrets = {
473
- username: 'alice',
474
- password: 'secret123',
475
- apiKey: 'key-12345',
476
- public: 'visible data',
477
- }
473
+ const numbers = { a: 1, b: 2, c: 3 }
478
474
 
479
475
  const replacer = (key: string, value: any) => {
480
- if (key === 'password' || key === 'apiKey') {
481
- return '***REDACTED***'
476
+ // Transform objects by doubling all number values
477
+ if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
478
+ const transformed: Record<string, any> = {}
479
+ for (const [k, v] of Object.entries(value)) {
480
+ transformed[k] = typeof v === 'number' ? v * 2 : v
481
+ }
482
+ return transformed
482
483
  }
483
484
  return value
484
485
  }
485
486
 
486
- console.log('Original object:', withSecrets)
487
- console.log('Stringified with replacer:')
488
- const redacted = Array.from(jsonStreamStringify(withSecrets, replacer, 2)).join(
487
+ console.log('Original object:', numbers)
488
+ console.log('Stringified with replacer (numbers doubled):')
489
+ const transformed = Array.from(jsonStreamStringify(numbers, replacer, 2)).join(
489
490
  '',
490
491
  )
491
- console.log(redacted)
492
+ console.log(transformed)
493
+ // Output:
494
+ // {
495
+ // "a": 2,
496
+ // "b": 4,
497
+ // "c": 6
498
+ // }
492
499
 
493
500
  // Example 5: Stringify to bytes
494
501
  console.log('\n=== Example 5: Stringify to Bytes ===')
package/README.md CHANGED
@@ -327,7 +327,7 @@ interface JsonStreamStringifyOptions {
327
327
  **Parameters:**
328
328
 
329
329
  - `value`: The value to stringify
330
- - `replacer`: Optional replacer function (like `JSON.stringify`)
330
+ - `replacer`: Optional replacer function called on each value (with empty key) during stringification
331
331
  - `indent`: Number of spaces for indentation (0 for compact)
332
332
  - `options.stringChunkSize`: Maximum size of string chunks in bytes
333
333
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-stream-lite",
3
- "version": "1.0.1",
3
+ "version": "1.0.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",