json-stream-lite 1.0.4 → 1.0.6

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/README.md CHANGED
@@ -368,3 +368,5 @@ Contributions welcome! Please ensure:
368
368
  - All tests pass: `pnpm test`
369
369
  - Code compiles: `pnpm compile`
370
370
  - Coverage maintained: `pnpm test -- --coverage`
371
+
372
+ For more details, see [CONTRIBUTING.md](./CONTRIBUTING.md).
@@ -1,4 +1,4 @@
1
- import { ByteStream } from './types';
1
+ import { ByteStream } from './types.js';
2
2
  export declare class NoMoreTokensError extends Error {
3
3
  }
4
4
  export declare class EofReachedError extends Error {
@@ -1,4 +1,4 @@
1
- import { bytesToString } from './utils';
1
+ import { bytesToString } from './utils.js';
2
2
  export class NoMoreTokensError extends Error {
3
3
  }
4
4
  export class EofReachedError extends Error {
@@ -1,3 +1,3 @@
1
- import { JsonKeyValuePair } from './types';
1
+ import { JsonKeyValuePair } from './types.js';
2
2
  export declare function jsonKeyValueParser(bytes: Iterable<number> | string): Generator<JsonKeyValuePair>;
3
3
  export declare function jsonKeyValueParserAsync(bytes: Iterable<number> | AsyncIterable<number> | string | ReadableStream<number> | ReadableStream<Uint8Array> | ReadableStream<string>): AsyncGenerator<JsonKeyValuePair>;
@@ -1,5 +1,5 @@
1
- import { JsonKeyValueParser } from './parser';
2
- import { stringToBytes } from './utils';
1
+ import { JsonKeyValueParser } from './parser.js';
2
+ import { stringToBytes } from './utils.js';
3
3
  export function* jsonKeyValueParser(bytes) {
4
4
  if (typeof bytes === 'string') {
5
5
  bytes = stringToBytes(bytes);
package/dist/stringify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { stringToBytes } from './utils';
1
+ import { stringToBytes } from './utils.js';
2
2
  function* formatString(str, chunkSize = 1024) {
3
3
  const formatted = `"${str.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r').replace(/\t/g, '\\t')}"`;
4
4
  let i = 0;
@@ -13,6 +13,9 @@ function* formatString(str, chunkSize = 1024) {
13
13
  i += chunkSize;
14
14
  }
15
15
  }
16
+ function shouldIgnore(value) {
17
+ return typeof value === 'function' || value === undefined;
18
+ }
16
19
  function* jsonStreamStringifyWithDepth(value, replacer, indent = 0, currentDepth = 0, options) {
17
20
  if (replacer) {
18
21
  value = replacer('', value);
@@ -41,7 +44,7 @@ function* jsonStreamStringifyWithDepth(value, replacer, indent = 0, currentDepth
41
44
  if (indent > 0) {
42
45
  yield '\n' + ' '.repeat(valueIndent);
43
46
  }
44
- if (next === undefined) {
47
+ if (shouldIgnore(next)) {
45
48
  yield 'null';
46
49
  continue;
47
50
  }
@@ -61,7 +64,7 @@ function* jsonStreamStringifyWithDepth(value, replacer, indent = 0, currentDepth
61
64
  for (let i = 0; i < len; i++) {
62
65
  const key = keys[i];
63
66
  const next = value[key];
64
- if (next === undefined) {
67
+ if (shouldIgnore(next)) {
65
68
  continue;
66
69
  }
67
70
  if (count > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-stream-lite",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
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",