🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@streamparser/json

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@streamparser/json - npm Package Compare versions

Comparing version

to
0.0.21

13

dist/cjs/tokenparser.js

@@ -269,4 +269,15 @@ "use strict";

}
// Edge case in which the separator is just whitespace and it's found in the middle of the JSON
if (token === tokenType_js_1.default.SEPARATOR &&
this.state !== 6 /* TokenParserState.SEPARATOR */ &&
Array.from(value)
.map((n) => n.charCodeAt(0))
.every((n) => n === 32 /* charset.SPACE */ ||
n === 10 /* charset.NEWLINE */ ||
n === 13 /* charset.CARRIAGE_RETURN */ ||
n === 9 /* charset.TAB */)) {
// whitespace
return;
}
throw new TokenParserError(`Unexpected ${tokenType_js_1.default[token]} (${JSON.stringify(value)}) in state ${TokenParserStateToString(this.state)}`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}

@@ -273,0 +284,0 @@ catch (err) {

18

dist/deno/README.md

@@ -13,3 +13,3 @@ # @streamparser/json

```javascript
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -56,3 +56,3 @@ const parser = new JSONParser();

```javascript
import { Tokenizer } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { Tokenizer } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -170,3 +170,3 @@ const tokenizer = new Tokenizer(opts);

```javascript
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -231,3 +231,3 @@ const parser = new JSONParser();

```javascript
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -250,3 +250,3 @@ const parser = new JSONParser({ stringBufferSize: undefined, paths: ['$'] });

```javascript
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -266,3 +266,3 @@ const parser = new JSONParser({ stringBufferSize: undefined });

```javascript
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -305,3 +305,3 @@ const parser = new JSONParser({ stringBufferSize: undefined });

```js
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -327,3 +327,3 @@ const jsonparser = new JSONParser({ stringBufferSize: undefined, paths: ['$.*'] });

```js
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.20/index.ts";/
import { JSONParser } from "https://deno.land/x/streamparser_json@v0.0.21/index.ts";/

@@ -377,3 +377,3 @@ const jsonparser = new JSONParser({ emitPartialTokens: true, emitPartialValues: true });

See [LICENSE.md].
See [LICENSE.md](../../LICENSE).

@@ -380,0 +380,0 @@ [npm-version-badge]: https://badge.fury.io/js/@streamparser%2Fjson.svg

@@ -774,4 +774,4 @@ import { charset, escapedSequences } from "./utils/utf-8.ts";

}
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}

@@ -778,0 +778,0 @@ }

@@ -0,1 +1,2 @@

import { charset } from "./utils/utf-8.ts";
import TokenType from "./utils/types/tokenType.ts";

@@ -328,2 +329,20 @@ import type {

// Edge case in which the separator is just whitespace and it's found in the middle of the JSON
if (
token === TokenType.SEPARATOR &&
this.state !== TokenParserState.SEPARATOR &&
Array.from(value as string)
.map((n) => n.charCodeAt(0))
.every(
(n) =>
n === charset.SPACE ||
n === charset.NEWLINE ||
n === charset.CARRIAGE_RETURN ||
n === charset.TAB,
)
) {
// whitespace
return;
}
throw new TokenParserError(

@@ -334,5 +353,4 @@ `Unexpected ${TokenType[token]} (${JSON.stringify(

);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}

@@ -339,0 +357,0 @@ }

@@ -0,1 +1,2 @@

import { charset } from "./utils/utf-8.js";
import TokenType from "./utils/types/tokenType.js";

@@ -263,4 +264,15 @@ import { TokenParserMode, } from "./utils/types/stackElement.js";

}
// Edge case in which the separator is just whitespace and it's found in the middle of the JSON
if (token === TokenType.SEPARATOR &&
this.state !== TokenParserState.SEPARATOR &&
Array.from(value)
.map((n) => n.charCodeAt(0))
.every((n) => n === charset.SPACE ||
n === charset.NEWLINE ||
n === charset.CARRIAGE_RETURN ||
n === charset.TAB)) {
// whitespace
return;
}
throw new TokenParserError(`Unexpected ${TokenType[token]} (${JSON.stringify(value)}) in state ${TokenParserStateToString(this.state)}`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}

@@ -267,0 +279,0 @@ catch (err) {

{
"name": "@streamparser/json",
"description": "Streaming JSON parser in Javascript for Node.js, Deno and the browser",
"version": "0.0.20",
"version": "0.0.21",
"main": "./dist/mjs/index.js",

@@ -6,0 +6,0 @@ "module": "./dist/mjs/index.js",

@@ -369,3 +369,3 @@ # @streamparser/json

See [LICENSE.md].
See [LICENSE.md](../../LICENSE).

@@ -372,0 +372,0 @@ [npm-version-badge]: https://badge.fury.io/js/@streamparser%2Fjson.svg

@@ -774,4 +774,4 @@ import { charset, escapedSequences } from "./utils/utf-8.js";

}
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}

@@ -778,0 +778,0 @@ }

@@ -0,1 +1,2 @@

import { charset } from "./utils/utf-8.js";
import TokenType from "./utils/types/tokenType.js";

@@ -328,2 +329,20 @@ import type {

// Edge case in which the separator is just whitespace and it's found in the middle of the JSON
if (
token === TokenType.SEPARATOR &&
this.state !== TokenParserState.SEPARATOR &&
Array.from(value as string)
.map((n) => n.charCodeAt(0))
.every(
(n) =>
n === charset.SPACE ||
n === charset.NEWLINE ||
n === charset.CARRIAGE_RETURN ||
n === charset.TAB,
)
) {
// whitespace
return;
}
throw new TokenParserError(

@@ -334,5 +353,4 @@ `Unexpected ${TokenType[token]} (${JSON.stringify(

);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
this.error(err);
} catch (err: unknown) {
this.error(err as Error);
}

@@ -339,0 +357,0 @@ }

@@ -54,3 +54,5 @@ import JSONParser from "../src/jsonparser.js";

expect(onValueCb.mock.calls).toHaveLength(1);
expect((onValueCb.mock.calls[0] as any)[0].value).toBe("test");
expect(
(onValueCb.mock.calls[0] as unknown as [{ value: string }])[0].value,
).toBe("test");
});

@@ -57,0 +59,0 @@

@@ -79,4 +79,5 @@ import { runJSONParserTest, type TestData } from "./utils/testRunner.js";

fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(expectedError);
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(expectedError);
}

@@ -83,0 +84,0 @@ });

@@ -43,7 +43,24 @@ import {

test("support multiple whitespace separators", async () => {
let i = 0;
const value = "1 2\t3\n4\n\r5 \n6\n\n7\n\r\n\r8 \t\n\n\r9";
const expected = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const separator = "";
await runJSONParserTest(
new JSONParser({ separator }),
value,
({ value }) => {
expect(value).toEqual(expected[i]);
i += 1;
},
);
});
test(`separator: fail on invalid value`, async () => {
try {
await runJSONParserTest(new JSONParser({ separator: "abc" }), ["abe"]);
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected "e" at position "2" in state SEPARATOR',

@@ -61,4 +78,7 @@ );

fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual("Unexpected TRUE (true) in state SEPARATOR");
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
"Unexpected TRUE (true) in state SEPARATOR",
);
}

@@ -74,4 +94,5 @@ });

fail("Error expected on invalid selector");
} catch (err: any) {
expect(err.message).toEqual(
} catch (err: unknown) {
expect(err).toBeInstanceOf(Error);
expect((err as Error).message).toEqual(
'Unexpected SEPARATOR ("\\r\\n") in state SEPARATOR',

@@ -81,2 +102,22 @@ );

});
test("not fail when whitespaces match separator", async () => {
let i = 0;
const value = `{
"a": 0,
"b": 1,
"c": -1
}`;
const expected = [0, 1, -1, { a: 0, b: 1, c: -1 }];
const separator = "\n";
await runJSONParserTest(
new JSONParser({ separator }),
value,
({ value }) => {
expect(value).toEqual(expected[i]);
i += 1;
},
);
});
});

@@ -10,3 +10,3 @@ import JSONParser from "../../src/jsonparser.js";

paths?: string[];
expected: any[];
expected: unknown[];
};

@@ -13,0 +13,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet