-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64e44e8
commit 5d47e66
Showing
13 changed files
with
70 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,4 @@ export { | |
TokenParserMode, | ||
type StackElement, | ||
TokenType, | ||
} from "https://deno.land/x/[email protected].14/index.ts"; | ||
} from "https://deno.land/x/[email protected].15/index.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { | |
type TransformOptions, | ||
type TransformCallback, | ||
} from "stream"; | ||
import { JSONParser, type JSONParserOptions } from "https://deno.land/x/[email protected].14/index.ts"; | ||
import { JSONParser, type JSONParserOptions } from "https://deno.land/x/[email protected].15/index.ts"; | ||
|
||
export default class JSONParserTransform extends Transform { | ||
private jsonParser: JSONParser; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ import { | |
} from "stream"; | ||
import Tokenizer, { | ||
type TokenizerOptions, | ||
} from "https://deno.land/x/[email protected].14/tokenizer.ts"; | ||
} from "https://deno.land/x/[email protected].15/tokenizer.ts"; | ||
|
||
export default class TokenizerTransform extends Transform { | ||
private tokenizer: Tokenizer; | ||
|
@@ -55,7 +55,7 @@ export default class TokenizerTransform extends Transform { | |
|
||
override _final(done: any) { | ||
try { | ||
this.tokenizer.end(); | ||
if (!this.tokenizer.isEnded) this.tokenizer.end(); | ||
done(); | ||
} catch (err: unknown) { | ||
done(err); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { | |
type TransformOptions, | ||
type TransformCallback, | ||
} from "stream"; | ||
import { TokenParser, type TokenParserOptions } from "https://deno.land/x/[email protected].14/index.ts"; | ||
import { TokenParser, type TokenParserOptions } from "https://deno.land/x/[email protected].15/index.ts"; | ||
|
||
export default class TokenParserTransform extends Transform { | ||
private tokenParser: TokenParser; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import type { ParsedElementInfo } from "https://deno.land/x/[email protected].14/utils/types/parsedElementInfo.ts"; | ||
import type { ParsedElementInfo } from "https://deno.land/x/[email protected].15/utils/types/parsedElementInfo.ts"; | ||
|
||
export function cloneParsedElementInfo( | ||
parsedElementInfo: ParsedElementInfo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ Fast dependency-free library to parse a JSON stream using utf-8 encoding in Node | |
*tldr;* | ||
|
||
```javascript | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const parser = new JSONParser(); | ||
parser.onValue = ({ value }) => { /* process data */ }; | ||
|
@@ -27,12 +27,13 @@ try { | |
} | ||
``` | ||
|
||
## streamparser/json ecosystem | ||
## @streamparser/json ecosystem | ||
|
||
There are multiple flavours of @streamparser: | ||
|
||
* The **[@streamparser/json](https://www.npmjs.com/package/@streamparser/json)** package allows to parse any JSON string or stream using pure Javascript. | ||
* The **[@streamparser/json-whatwg](https://www.npmjs.com/package/@streamparser/json-whatwg)** wraps `@streamparser/json` into WHATWG `@streamparser/json-whatwg`. | ||
* The **[@streamparser/json-whatwg](https://www.npmjs.com/package/@streamparser/json-whatwg)** wraps `@streamparser/json` into a WHATWG TransformStream. | ||
* The **[@streamparser/json-node](https://www.npmjs.com/package/@streamparser/json-node)** wraps `@streamparser/json` into a node Transform stream. | ||
|
||
## Dependencies / Polyfilling | ||
|
||
|
@@ -51,7 +52,7 @@ If you are targeting browsers or systems in which these might be missing, you ne | |
A JSON compliant tokenizer that parses a utf-8 stream into JSON tokens | ||
|
||
```javascript | ||
import { Tokenizer } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { Tokenizer } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const tokenizer = new Tokenizer(opts); | ||
``` | ||
|
@@ -162,7 +163,7 @@ A drop-in replacement of `JSONparse` (with few ~~breaking changes~~ improvements | |
|
||
|
||
```javascript | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const parser = new JSONParser(); | ||
``` | ||
|
@@ -222,7 +223,7 @@ You push data using the `write` method which takes a string or an array-like obj | |
You can subscribe to the resulting data using the | ||
|
||
```javascript | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const parser = new JSONParser({ stringBufferSize: undefined, paths: ['$'] }); | ||
parser.onValue = console.log; | ||
|
@@ -240,7 +241,7 @@ parser.write('"');// logs "Hello world!" | |
Write is always a synchronous operation so any error during the parsing of the stream will be thrown during the write operation. After an error, the parser can't continue parsing. | ||
|
||
```javascript | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const parser = new JSONParser({ stringBufferSize: undefined }); | ||
parser.onValue = console.log; | ||
|
@@ -255,7 +256,7 @@ try { | |
You can also handle errors using callbacks: | ||
|
||
```javascript | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const parser = new JSONParser({ stringBufferSize: undefined }); | ||
parser.onValue = console.log; | ||
|
@@ -293,7 +294,7 @@ Imagine an endpoint that send a large amount of JSON objects one after the other | |
Imagine an endpoint that send a large amount of JSON objects one after the other (`[{"id":1},{"id":2},{"id":3},...]`). | ||
|
||
```js | ||
import { JSONParser } from "https://deno.land/x/[email protected].14/index.ts";/ | ||
import { JSONParser } from "https://deno.land/x/[email protected].15/index.ts";/ | ||
|
||
const jsonparser = new JSONParser({ stringBufferSize: undefined, paths: ['$.*'] }); | ||
jsonparser.onValue = ({ value, key, parent, stack }) => { | ||
|
Oops, something went wrong.