json-seq-stream 1.0.7 → 1.0.9
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/InputJsonLinesStream.d.ts +2 -2
- package/InputJsonSequenceParseStream.d.ts +2 -2
- package/InputJsonSequenceStream.d.ts +2 -2
- package/InputLineFeedSeparattedSequenceStream.d.ts +1 -1
- package/InputRecordSequenceStream.d.ts +2 -2
- package/LICENSE +21 -21
- package/OutputJsonLinesStream.d.ts +2 -2
- package/OutputJsonSequenceStream.d.ts +2 -2
- package/OutputJsonSequenceStringifyStream.d.ts +2 -2
- package/OutputRecordSequenceStream.d.ts +2 -2
- package/OutputTextJoinLineFeedSequenceStream.d.ts +2 -2
- package/README.md +78 -78
- package/index.d.ts +16 -16
- package/index.js +2 -2
- package/index.umd.cjs +2 -2
- package/package.json +63 -62
- package/rfc7464.d.ts +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream";
|
|
2
|
-
import type { InputLineFeedSeparattedSequenceStreamOptions } from "./InputLineFeedSeparattedSequenceStream";
|
|
1
|
+
import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream.js";
|
|
2
|
+
import type { InputLineFeedSeparattedSequenceStreamOptions } from "./InputLineFeedSeparattedSequenceStream.js";
|
|
3
3
|
export type InputJsonLinesStreamOptions<T> = {
|
|
4
4
|
label?: string;
|
|
5
5
|
} & TextDecoderOptions & InputLineFeedSeparattedSequenceStreamOptions & InputJsonSequenceParseStreamOptions<T>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ParseStream } from "./ParseStream";
|
|
2
|
-
import type { ParseStreamOptions } from "./ParseStream";
|
|
1
|
+
import { ParseStream } from "./ParseStream.js";
|
|
2
|
+
import type { ParseStreamOptions } from "./ParseStream.js";
|
|
3
3
|
export type InputJsonSequenceParseStreamOptions<T> = Partial<ParseStreamOptions<T>>;
|
|
4
4
|
/**
|
|
5
5
|
* string の sequence を 連続した `T` の sequence に変換する TransformStream
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream";
|
|
2
|
-
import type { InputRecordSequenceStreamOptions } from "./InputRecordSequenceStream";
|
|
1
|
+
import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream.js";
|
|
2
|
+
import type { InputRecordSequenceStreamOptions } from "./InputRecordSequenceStream.js";
|
|
3
3
|
export type InputJsonSequenceStreamOptions<T> = {
|
|
4
4
|
label?: string;
|
|
5
5
|
} & TextDecoderOptions & InputJsonSequenceParseStreamOptions<T> & InputRecordSequenceStreamOptions;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TextSplitStream, TextSplitStreamOptions } from "./TextSplitStream";
|
|
1
|
+
import { TextSplitStream, TextSplitStreamOptions } from "./TextSplitStream.js";
|
|
2
2
|
export type InputLineFeedSeparattedSequenceStreamOptions = Partial<TextSplitStreamOptions>;
|
|
3
3
|
/**
|
|
4
4
|
* Stream to convert to LF or CRLF delimited sequence
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RecordToSequenceStream } from "./RecordToSequenceStream";
|
|
2
|
-
import type { RecordToSequenceStreamOptions } from "./RecordToSequenceStream";
|
|
1
|
+
import { RecordToSequenceStream } from "./RecordToSequenceStream.js";
|
|
2
|
+
import type { RecordToSequenceStreamOptions } from "./RecordToSequenceStream.js";
|
|
3
3
|
export type InputRecordSequenceStreamOptions = Partial<RecordToSequenceStreamOptions>;
|
|
4
4
|
/**
|
|
5
5
|
* RS で始まって LF で1行を表す 連続した文字列データを 行データとして整形して返す
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 juner
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 juner
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStringifyStream";
|
|
2
|
-
import type { OutputTextJoinLineFeedSequenceStreamOptions } from "./OutputTextJoinLineFeedSequenceStream";
|
|
1
|
+
import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStringifyStream.js";
|
|
2
|
+
import type { OutputTextJoinLineFeedSequenceStreamOptions } from "./OutputTextJoinLineFeedSequenceStream.js";
|
|
3
3
|
export type OutputJsonLinesStreamOptions<T> = OutputJsonSequenceStringifyStreamOptions<T> & OutputTextJoinLineFeedSequenceStreamOptions;
|
|
4
4
|
/**
|
|
5
5
|
* A composite stream that serializes typed values (`T`) into the NDJSON / JSON Lines format
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStringifyStream";
|
|
2
|
-
import type { OutputRecordSequenceStreamOptions } from "./OutputRecordSequenceStream";
|
|
1
|
+
import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStringifyStream.js";
|
|
2
|
+
import type { OutputRecordSequenceStreamOptions } from "./OutputRecordSequenceStream.js";
|
|
3
3
|
export type OutputJsonSequenceStreamOptions<T> = OutputJsonSequenceStringifyStreamOptions<T> & OutputRecordSequenceStreamOptions;
|
|
4
4
|
/**
|
|
5
5
|
* A composite stream that serializes typed values (`T`) into the `application/json-seq` format
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { StringifyStream } from "./StringifyStream";
|
|
2
|
-
import type { StringifyStreamOptions } from "./StringifyStream";
|
|
1
|
+
import { StringifyStream } from "./StringifyStream.js";
|
|
2
|
+
import type { StringifyStreamOptions } from "./StringifyStream.js";
|
|
3
3
|
export type OutputJsonSequenceStringifyStreamOptions<T> = Partial<StringifyStreamOptions<T>>;
|
|
4
4
|
/**
|
|
5
5
|
* 連続した `T` の sequence を string の sequence に変換する TransformStream
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SequenceToRecordStream } from "./SequenceToRecordStream";
|
|
2
|
-
import type { SequenceToRecordStreamOptions } from "./SequenceToRecordStream";
|
|
1
|
+
import { SequenceToRecordStream } from "./SequenceToRecordStream.js";
|
|
2
|
+
import type { SequenceToRecordStreamOptions } from "./SequenceToRecordStream.js";
|
|
3
3
|
export type OutputRecordSequenceStreamOptions = Partial<SequenceToRecordStreamOptions>;
|
|
4
4
|
/**
|
|
5
5
|
* Converts line data into continuous string data starting with RS and each LF represents one line.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TextJoinStream } from "./TextJoinStream";
|
|
2
|
-
import type { TextJoinStreamOptions } from "./TextJoinStream";
|
|
1
|
+
import { TextJoinStream } from "./TextJoinStream.js";
|
|
2
|
+
import type { TextJoinStreamOptions } from "./TextJoinStream.js";
|
|
3
3
|
export type OutputTextJoinLineFeedSequenceStreamOptions = Partial<TextJoinStreamOptions>;
|
|
4
4
|
/**
|
|
5
5
|
* Put LF between sequences Convert to a stream
|
package/README.md
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
# json-seq-stream
|
|
2
|
-
|
|
3
|
-
application/json-seq / jsonl (NDJSON) support stream / async iterator library
|
|
4
|
-
|
|
5
|
-
This library provides composable `TransformStream` / `ReadableWritablePair` utilities to work with streaming JSON data formats.
|
|
6
|
-
|
|
7
|
-
## Features
|
|
8
|
-
|
|
9
|
-
- [x] Supports [RFC7464](https://datatracker.ietf.org/doc/html/rfc7464) (application/json-seq)
|
|
10
|
-
- [x] Supports JSON Lines / NDJSON (application/jsonl, application/x-ndjson)
|
|
11
|
-
- [x] Fully stream-compatible (Fetch API, File API, Bun/Deno, etc.)
|
|
12
|
-
- [x] Composable with standard Web Streams (`pipeThrough()`)
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Usage Examples
|
|
17
|
-
|
|
18
|
-
### JSON Sequence (RFC 7464)
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { InputJsonSequenceStream } from "json-seq-stream";
|
|
22
|
-
|
|
23
|
-
type Value = { value: number };
|
|
24
|
-
|
|
25
|
-
const sequenceStream = new InputJsonSequenceStream<Value>();
|
|
26
|
-
|
|
27
|
-
const response = await fetch(url);
|
|
28
|
-
const readable = response.body!.pipeThrough(sequenceStream);
|
|
29
|
-
|
|
30
|
-
for await (const value of readable) {
|
|
31
|
-
console.log(value);
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## JSON Lines / NDJSON
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { InputJsonLinesStream } from "json-seq-stream";
|
|
39
|
-
|
|
40
|
-
type Value = { value: number };
|
|
41
|
-
|
|
42
|
-
const linesStream = new InputJsonLinesStream<Value>();
|
|
43
|
-
|
|
44
|
-
const response = await fetch("https://example.com/data.jsonl");
|
|
45
|
-
const readable = response.body!.pipeThrough(linesStream);
|
|
46
|
-
|
|
47
|
-
for await (const value of readable) {
|
|
48
|
-
console.log(value);
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Output Example
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
import { OutputJsonLinesStream } from "json-seq-stream";
|
|
56
|
-
|
|
57
|
-
type Value = { value: number };
|
|
58
|
-
|
|
59
|
-
const { readable, writable } = new OutputJsonLinesStream<Value>();
|
|
60
|
-
|
|
61
|
-
const writer = writable.getWriter();
|
|
62
|
-
writer.write({ value: 1 });
|
|
63
|
-
writer.write({ value: 2 });
|
|
64
|
-
writer.close();
|
|
65
|
-
|
|
66
|
-
for await (const chunk of readable) {
|
|
67
|
-
console.log(new TextDecoder().decode(chunk)); // NDJSON text lines
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## See also
|
|
72
|
-
|
|
73
|
-
- RFC 7464 - JavaScript Object Notation (JSON) Text Sequences \
|
|
74
|
-
[https://datatracker.ietf.org/doc/html/rfc7464](https://datatracker.ietf.org/doc/html/rfc7464)
|
|
75
|
-
- JSON Lines \
|
|
76
|
-
[https://jsonlines.org](https://jsonlines.org)
|
|
77
|
-
- JSON streaming - Wikipedia (en) \
|
|
78
|
-
[https://en.wikipedia.org/wiki/JSON_streaming](https://en.wikipedia.org/wiki/JSON_streaming)
|
|
1
|
+
# json-seq-stream
|
|
2
|
+
|
|
3
|
+
application/json-seq / jsonl (NDJSON) support stream / async iterator library
|
|
4
|
+
|
|
5
|
+
This library provides composable `TransformStream` / `ReadableWritablePair` utilities to work with streaming JSON data formats.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- [x] Supports [RFC7464](https://datatracker.ietf.org/doc/html/rfc7464) (application/json-seq)
|
|
10
|
+
- [x] Supports JSON Lines / NDJSON (application/jsonl, application/x-ndjson)
|
|
11
|
+
- [x] Fully stream-compatible (Fetch API, File API, Bun/Deno, etc.)
|
|
12
|
+
- [x] Composable with standard Web Streams (`pipeThrough()`)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Usage Examples
|
|
17
|
+
|
|
18
|
+
### JSON Sequence (RFC 7464)
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { InputJsonSequenceStream } from "json-seq-stream";
|
|
22
|
+
|
|
23
|
+
type Value = { value: number };
|
|
24
|
+
|
|
25
|
+
const sequenceStream = new InputJsonSequenceStream<Value>();
|
|
26
|
+
|
|
27
|
+
const response = await fetch(url);
|
|
28
|
+
const readable = response.body!.pipeThrough(sequenceStream);
|
|
29
|
+
|
|
30
|
+
for await (const value of readable) {
|
|
31
|
+
console.log(value);
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## JSON Lines / NDJSON
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { InputJsonLinesStream } from "json-seq-stream";
|
|
39
|
+
|
|
40
|
+
type Value = { value: number };
|
|
41
|
+
|
|
42
|
+
const linesStream = new InputJsonLinesStream<Value>();
|
|
43
|
+
|
|
44
|
+
const response = await fetch("https://example.com/data.jsonl");
|
|
45
|
+
const readable = response.body!.pipeThrough(linesStream);
|
|
46
|
+
|
|
47
|
+
for await (const value of readable) {
|
|
48
|
+
console.log(value);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Output Example
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { OutputJsonLinesStream } from "json-seq-stream";
|
|
56
|
+
|
|
57
|
+
type Value = { value: number };
|
|
58
|
+
|
|
59
|
+
const { readable, writable } = new OutputJsonLinesStream<Value>();
|
|
60
|
+
|
|
61
|
+
const writer = writable.getWriter();
|
|
62
|
+
writer.write({ value: 1 });
|
|
63
|
+
writer.write({ value: 2 });
|
|
64
|
+
writer.close();
|
|
65
|
+
|
|
66
|
+
for await (const chunk of readable) {
|
|
67
|
+
console.log(new TextDecoder().decode(chunk)); // NDJSON text lines
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## See also
|
|
72
|
+
|
|
73
|
+
- RFC 7464 - JavaScript Object Notation (JSON) Text Sequences \
|
|
74
|
+
[https://datatracker.ietf.org/doc/html/rfc7464](https://datatracker.ietf.org/doc/html/rfc7464)
|
|
75
|
+
- JSON Lines \
|
|
76
|
+
[https://jsonlines.org](https://jsonlines.org)
|
|
77
|
+
- JSON streaming - Wikipedia (en) \
|
|
78
|
+
[https://en.wikipedia.org/wiki/JSON_streaming](https://en.wikipedia.org/wiki/JSON_streaming)
|
package/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export * from "./TextSplitStream";
|
|
2
|
-
export * from "./TextJoinStream";
|
|
3
|
-
export * from "./InputJsonSequenceStream";
|
|
4
|
-
export * from "./OutputJsonSequenceStream";
|
|
5
|
-
export * from "./InputJsonSequenceParseStream";
|
|
6
|
-
export * from "./OutputJsonSequenceStringifyStream";
|
|
7
|
-
export * from "./InputRecordSequenceStream";
|
|
8
|
-
export * from "./OutputRecordSequenceStream";
|
|
9
|
-
export * from "./InputJsonLinesStream";
|
|
10
|
-
export * from "./OutputJsonLinesStream";
|
|
11
|
-
export * from "./InputLineFeedSeparattedSequenceStream";
|
|
12
|
-
export * from "./OutputTextJoinLineFeedSequenceStream";
|
|
13
|
-
export * from "./SequenceToRecordStream";
|
|
14
|
-
export * from "./RecordToSequenceStream";
|
|
15
|
-
export * from "./StringifyStream";
|
|
16
|
-
export * from "./ParseStream";
|
|
1
|
+
export * from "./TextSplitStream.js";
|
|
2
|
+
export * from "./TextJoinStream.js";
|
|
3
|
+
export * from "./InputJsonSequenceStream.js";
|
|
4
|
+
export * from "./OutputJsonSequenceStream.js";
|
|
5
|
+
export * from "./InputJsonSequenceParseStream.js";
|
|
6
|
+
export * from "./OutputJsonSequenceStringifyStream.js";
|
|
7
|
+
export * from "./InputRecordSequenceStream.js";
|
|
8
|
+
export * from "./OutputRecordSequenceStream.js";
|
|
9
|
+
export * from "./InputJsonLinesStream.js";
|
|
10
|
+
export * from "./OutputJsonLinesStream.js";
|
|
11
|
+
export * from "./InputLineFeedSeparattedSequenceStream.js";
|
|
12
|
+
export * from "./OutputTextJoinLineFeedSequenceStream.js";
|
|
13
|
+
export * from "./SequenceToRecordStream.js";
|
|
14
|
+
export * from "./RecordToSequenceStream.js";
|
|
15
|
+
export * from "./StringifyStream.js";
|
|
16
|
+
export * from "./ParseStream.js";
|
package/index.js
CHANGED
|
@@ -100,7 +100,7 @@ const X = m, f = {
|
|
|
100
100
|
flush: "flush"
|
|
101
101
|
};
|
|
102
102
|
function y({ begin: r, end: e, chunkEndSplit: t, fallbackSkip: s }) {
|
|
103
|
-
const n = [], c = new RegExp(`(${RegExp.escape(r)}|${RegExp.escape(e)})`, "u"), u = s === !0 ? () => !0 : s === !1 ? () => !1 : s;
|
|
103
|
+
const n = [], c = new RegExp(`(${RegExp.escape(r)}|${RegExp.escape(e)})`, "u"), u = s === !0 ? (() => !0) : s === !1 ? (() => !1) : s;
|
|
104
104
|
let a = f.init;
|
|
105
105
|
return {
|
|
106
106
|
args: [
|
|
@@ -141,7 +141,7 @@ class j extends TransformStream {
|
|
|
141
141
|
super(...t);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const q = "
|
|
144
|
+
const q = "", w = `
|
|
145
145
|
`, N = q, D = w;
|
|
146
146
|
class b extends j {
|
|
147
147
|
constructor(e) {
|
package/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(o,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(o=typeof globalThis<"u"?globalThis:o||self,g(o.index={}))})(this,function(o){"use strict";function g({splitter:r,chunkEndSplit:e}){const{separator:t,checker:s}=D(r),n=[];return{args:[{transform(c,a){e||(c=[...n.splice(0,n.length),c].join(""));for(const i of c.split(t))if(!(i.length<=0)){if(s.test(i)){h(n,a);continue}n.push(i)}e&&h(n,a)},flush(c){h(n,c)}}]}}function D(r){typeof r=="string"&&(r=[r]);const e=r.map(t=>RegExp.escape(t)).join("|");return{separator:new RegExp(`(${e})`,"ug"),checker:new RegExp(`^(${e})$`)}}function h(r,e){if(r.length<=0)return;const t=r.splice(0,r.length).join("");e.enqueue(t)}class I extends TransformStream{constructor(e){const{args:t}=g(e);super(...t)}}function $({delimiter:r,start:e,end:t,skip:s}){let n=!0;return{args:[{transform(c,a){s&&c.length<=0||(n?(e&&a.enqueue(r),n=!1):a.enqueue(r),a.enqueue(c))},flush(c){n||t&&c.enqueue(r)}}]}}class J extends TransformStream{constructor(e){const{args:t}=$(e);super(...t)}}function C({parse:r,errorFallback:e}){return{args:[{transform(s,n){try{const u=r(s);u&&n.enqueue(u)}catch(u){if(!e)return;const c=n.error.bind(n),a=n.enqueue.bind(n),i=e(u,{chunk:s,error:c,enqueue:a});if(i?.then)return i.catch(()=>{})}}}]}}class R extends TransformStream{constructor(e){const{args:t}=C(e);super(...t)}}class b extends R{constructor(e){let{errorFallback:t,parse:s}=e??{};s??=JSON.parse,t??=!1,super({parse:s,errorFallback:t})}}const _=b,d={begin:"begin",end:"end",record:"record",init:"init",flush:"flush"};function v({begin:r,end:e,chunkEndSplit:t,fallbackSkip:s}){const n=[],u=new RegExp(`(${RegExp.escape(r)}|${RegExp.escape(e)})`,"u"),c=s===!0?()=>!0:s===!1?()=>!1:s;let a=d.init;return{args:[{transform(S,f){t||(S=[...n.splice(0,n.length),S].join(""));for(const l of S.split(u)){if(l===r){const m=d.begin;a===d.end||a===void 0?(p(n,f),a=m):c(l,a,m)||(p(n,f),a=m);continue}if(l===e){const m=d.end;a===d.record||a===d.begin?(p(n,f),a=m):c(l,a,m)||(p(n,f),a=m);continue}const P=d.record;a===d.begin||a===d.record?(n.push(l),a=P):c(l,a,d.record)||(n.push(l),a=P)}t&&(p(n,f),a=d.end)},flush(S){c("",a,d.flush)||p(n,S)}}]}}function p(r,e){if(r.length<=0)return;const t=r.splice(0,r.length).join("");t.length<=0||e.enqueue(t)}class E extends TransformStream{constructor(e){const{args:t}=v(e);super(...t)}}const O="
|
|
1
|
+
(function(o,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(o=typeof globalThis<"u"?globalThis:o||self,g(o.index={}))})(this,(function(o){"use strict";function g({splitter:r,chunkEndSplit:e}){const{separator:t,checker:s}=D(r),n=[];return{args:[{transform(c,a){e||(c=[...n.splice(0,n.length),c].join(""));for(const i of c.split(t))if(!(i.length<=0)){if(s.test(i)){h(n,a);continue}n.push(i)}e&&h(n,a)},flush(c){h(n,c)}}]}}function D(r){typeof r=="string"&&(r=[r]);const e=r.map(t=>RegExp.escape(t)).join("|");return{separator:new RegExp(`(${e})`,"ug"),checker:new RegExp(`^(${e})$`)}}function h(r,e){if(r.length<=0)return;const t=r.splice(0,r.length).join("");e.enqueue(t)}class I extends TransformStream{constructor(e){const{args:t}=g(e);super(...t)}}function $({delimiter:r,start:e,end:t,skip:s}){let n=!0;return{args:[{transform(c,a){s&&c.length<=0||(n?(e&&a.enqueue(r),n=!1):a.enqueue(r),a.enqueue(c))},flush(c){n||t&&c.enqueue(r)}}]}}class J extends TransformStream{constructor(e){const{args:t}=$(e);super(...t)}}function C({parse:r,errorFallback:e}){return{args:[{transform(s,n){try{const u=r(s);u&&n.enqueue(u)}catch(u){if(!e)return;const c=n.error.bind(n),a=n.enqueue.bind(n),i=e(u,{chunk:s,error:c,enqueue:a});if(i?.then)return i.catch(()=>{})}}}]}}class R extends TransformStream{constructor(e){const{args:t}=C(e);super(...t)}}class b extends R{constructor(e){let{errorFallback:t,parse:s}=e??{};s??=JSON.parse,t??=!1,super({parse:s,errorFallback:t})}}const _=b,d={begin:"begin",end:"end",record:"record",init:"init",flush:"flush"};function v({begin:r,end:e,chunkEndSplit:t,fallbackSkip:s}){const n=[],u=new RegExp(`(${RegExp.escape(r)}|${RegExp.escape(e)})`,"u"),c=s===!0?(()=>!0):s===!1?(()=>!1):s;let a=d.init;return{args:[{transform(S,f){t||(S=[...n.splice(0,n.length),S].join(""));for(const l of S.split(u)){if(l===r){const m=d.begin;a===d.end||a===void 0?(p(n,f),a=m):c(l,a,m)||(p(n,f),a=m);continue}if(l===e){const m=d.end;a===d.record||a===d.begin?(p(n,f),a=m):c(l,a,m)||(p(n,f),a=m);continue}const P=d.record;a===d.begin||a===d.record?(n.push(l),a=P):c(l,a,d.record)||(n.push(l),a=P)}t&&(p(n,f),a=d.end)},flush(S){c("",a,d.flush)||p(n,S)}}]}}function p(r,e){if(r.length<=0)return;const t=r.splice(0,r.length).join("");t.length<=0||e.enqueue(t)}class E extends TransformStream{constructor(e){const{args:t}=v(e);super(...t)}}const O="",L=`
|
|
2
2
|
`,A=O,B=L;class q extends E{constructor(e){let{begin:t,end:s,chunkEndSplit:n,fallbackSkip:u}=e??{};t??=A,s??=B,n??=!1,u??=!1,super({begin:t,end:s,chunkEndSplit:n,fallbackSkip:u})}}const G=q,K=q;function M(r){const{label:e,fatal:t,begin:s,end:n,parse:u,errorFallback:c}=r,a=new TextDecoderStream(e,{fatal:t}),i=new q({begin:s,end:n}),S=new b({parse:u,errorFallback:c}),{writable:f}=a,l=a.readable.pipeThrough(i).pipeThrough(S);return{writable:f,readable:l}}class x{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e={}){({readable:this.#t,writable:this.#e}=M(e))}}const z=x;function H({stringify:r,errorFallback:e}){return{args:[{transform(s,n){try{const u=r(s);(u?.length??0)>0&&n.enqueue(u)}catch(u){if(!e)return;const c=n.error.bind(n),a=n.enqueue.bind(n),i=e(u,{chunk:s,error:c,enqueue:a});if(i?.then)return i.catch(()=>{})}}}]}}class y extends TransformStream{constructor(e){const{args:t}=H(e);super(...t)}}class T extends y{constructor(e){let{errorFallback:t,stringify:s}=e??{};t??=!1,s??=JSON.stringify,super({stringify:s,errorFallback:t})}}function Q({begin:r,end:e,skip:t}){return{args:[{transform(n,u){t&&n.length<=0||(u.enqueue(r),u.enqueue(n),u.enqueue(e))}}]}}class k extends TransformStream{constructor(e){const{args:t}=Q(e);super(...t)}}const U=O,V=L,W=!1;class w extends k{constructor(e){let{begin:t,end:s,skip:n,...u}=e??{};t??=U,s??=V,n??=W,super({begin:t,end:s,skip:n,...u})}}const X=w;function Y(r){const{begin:e,end:t,stringify:s,errorFallback:n}=r,u=new TextEncoderStream,c=new w({begin:e,end:t}),a=new T({stringify:s,errorFallback:n}),{writable:i}=a,S=a.readable.pipeThrough(c).pipeThrough(u);return{writable:i,readable:S}}class Z{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e={}){({readable:this.#t,writable:this.#e}=Y(e))}}const F=`
|
|
3
3
|
`,ee=[F,`\r
|
|
4
|
-
`];class j extends I{constructor(e){let{splitter:t,chunkEndSplit:s}=e??{};t??=ee,s??=!1,super({splitter:t,chunkEndSplit:s})}}function te(r){const{label:e,fatal:t,splitter:s,chunkEndSplit:n,parse:u,errorFallback:c}=r??{},a=new TextDecoderStream(e,{fatal:t}),i=new j({splitter:s,chunkEndSplit:n}),S=new b({parse:u,errorFallback:c}),{writable:f}=a,l=a.readable.pipeThrough(i).pipeThrough(S);return{writable:f,readable:l}}class ne{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e){({readable:this.#t,writable:this.#e}=te(e))}}class N extends J{constructor(e){let{delimiter:t,start:s,end:n,skip:u}=e??{};t??=F,s??=!1,n??=!1,u??=!0,super({delimiter:t,start:s,end:n,skip:u})}}function re(r){const{delimiter:e,skip:t,start:s,end:n,stringify:u,errorFallback:c}=r,a=new TextEncoderStream,i=new N({delimiter:e,end:n,skip:t,start:s}),S=new T({stringify:u,errorFallback:c}),{writable:f}=S,l=S.readable.pipeThrough(i).pipeThrough(a);return{writable:f,readable:l}}class se{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e={}){({readable:this.#t,writable:this.#e}=re(e))}}o.InputJsonLinesStream=ne,o.InputJsonSequenceParseStream=b,o.InputJsonSequenceStream=x,o.InputLineFeedSeparattedSequenceStream=j,o.InputRecordSequenceStream=q,o.InputSequenceStream=K,o.JsonSequenceFormatStream=_,o.JsonSequenceStream=z,o.OutputJsonLinesStream=se,o.OutputJsonSequenceStream=Z,o.OutputJsonSequenceStringifyStream=T,o.OutputRecordSequenceStream=w,o.OutputSequenceStream=X,o.OutputTextJoinLineFeedSequenceStream=N,o.ParseStream=R,o.RecordToSequenceStream=E,o.SequenceStream=G,o.SequenceToRecordStream=k,o.StringifyStream=y,o.TextJoinStream=J,o.TextSplitStream=I,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
|
4
|
+
`];class j extends I{constructor(e){let{splitter:t,chunkEndSplit:s}=e??{};t??=ee,s??=!1,super({splitter:t,chunkEndSplit:s})}}function te(r){const{label:e,fatal:t,splitter:s,chunkEndSplit:n,parse:u,errorFallback:c}=r??{},a=new TextDecoderStream(e,{fatal:t}),i=new j({splitter:s,chunkEndSplit:n}),S=new b({parse:u,errorFallback:c}),{writable:f}=a,l=a.readable.pipeThrough(i).pipeThrough(S);return{writable:f,readable:l}}class ne{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e){({readable:this.#t,writable:this.#e}=te(e))}}class N extends J{constructor(e){let{delimiter:t,start:s,end:n,skip:u}=e??{};t??=F,s??=!1,n??=!1,u??=!0,super({delimiter:t,start:s,end:n,skip:u})}}function re(r){const{delimiter:e,skip:t,start:s,end:n,stringify:u,errorFallback:c}=r,a=new TextEncoderStream,i=new N({delimiter:e,end:n,skip:t,start:s}),S=new T({stringify:u,errorFallback:c}),{writable:f}=S,l=S.readable.pipeThrough(i).pipeThrough(a);return{writable:f,readable:l}}class se{#e;#t;get writable(){return this.#e}get readable(){return this.#t}constructor(e={}){({readable:this.#t,writable:this.#e}=re(e))}}o.InputJsonLinesStream=ne,o.InputJsonSequenceParseStream=b,o.InputJsonSequenceStream=x,o.InputLineFeedSeparattedSequenceStream=j,o.InputRecordSequenceStream=q,o.InputSequenceStream=K,o.JsonSequenceFormatStream=_,o.JsonSequenceStream=z,o.OutputJsonLinesStream=se,o.OutputJsonSequenceStream=Z,o.OutputJsonSequenceStringifyStream=T,o.OutputRecordSequenceStream=w,o.OutputSequenceStream=X,o.OutputTextJoinLineFeedSequenceStream=N,o.ParseStream=R,o.RecordToSequenceStream=E,o.SequenceStream=G,o.SequenceToRecordStream=k,o.StringifyStream=y,o.TextJoinStream=J,o.TextSplitStream=I,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "json-seq-stream",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "application/json-seq support stream / async iterator library",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./index.js",
|
|
7
|
-
"exports": {
|
|
8
|
-
".": {
|
|
9
|
-
"import": {
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
|
-
"default": "./index.js"
|
|
12
|
-
},
|
|
13
|
-
"require": {
|
|
14
|
-
"types": "./index.d.ts",
|
|
15
|
-
"default": "./index.umd.cjs"
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"test:watch": "vitest watch --coverage",
|
|
21
|
-
"test": "vitest run --coverage --coverage.reporter=cobertura --coverage.reporter=text",
|
|
22
|
-
"lint": "eslint .",
|
|
23
|
-
"lint:fix": "eslint . --fix",
|
|
24
|
-
"build": "vite build && tsc --project tsconfig.build.json && cpx ./package.json dist && cpx README.md dist && cpx LICENSE dist"
|
|
25
|
-
},
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/juner/json-seq-stream.git"
|
|
29
|
-
},
|
|
30
|
-
"keywords": [
|
|
31
|
-
"application/json-seq",
|
|
32
|
-
"TransformStream",
|
|
33
|
-
"web streams",
|
|
34
|
-
"asyncIterator",
|
|
35
|
-
"Symbol.asyncIterator",
|
|
36
|
-
"rfc7464",
|
|
37
|
-
"json-seq"
|
|
38
|
-
],
|
|
39
|
-
"author": "juners",
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"engines": {
|
|
42
|
-
"node": "^24.x"
|
|
43
|
-
},
|
|
44
|
-
"bugs": {
|
|
45
|
-
"url": "https://github.com/juner/json-seq-stream/issues"
|
|
46
|
-
},
|
|
47
|
-
"homepage": "https://github.com/juner/json-seq-stream#readme",
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@eslint/js": "^9.
|
|
50
|
-
"@eslint/json": "^0.
|
|
51
|
-
"@eslint/markdown": "^
|
|
52
|
-
"@
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"typescript
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "json-seq-stream",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "application/json-seq support stream / async iterator library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./index.d.ts",
|
|
15
|
+
"default": "./index.umd.cjs"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test:watch": "vitest watch --coverage",
|
|
21
|
+
"test": "vitest run --coverage --coverage.reporter=cobertura --coverage.reporter=text",
|
|
22
|
+
"lint": "eslint .",
|
|
23
|
+
"lint:fix": "eslint . --fix",
|
|
24
|
+
"build": "vite build && tsc --project tsconfig.build.json && cpx ./package.json dist && cpx README.md dist && cpx LICENSE dist"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/juner/json-seq-stream.git"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"application/json-seq",
|
|
32
|
+
"TransformStream",
|
|
33
|
+
"web streams",
|
|
34
|
+
"asyncIterator",
|
|
35
|
+
"Symbol.asyncIterator",
|
|
36
|
+
"rfc7464",
|
|
37
|
+
"json-seq"
|
|
38
|
+
],
|
|
39
|
+
"author": "juners",
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": "^24.x"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/juner/json-seq-stream/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/juner/json-seq-stream#readme",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@eslint/js": "^9.39.1",
|
|
50
|
+
"@eslint/json": "^0.14.0",
|
|
51
|
+
"@eslint/markdown": "^7.5.1",
|
|
52
|
+
"@stylistic/eslint-plugin": "^5.5.0",
|
|
53
|
+
"@vitest/coverage-v8": "^4.0.8",
|
|
54
|
+
"cpx": "^1.2.1",
|
|
55
|
+
"eslint": "^9.39.1",
|
|
56
|
+
"globals": "^16.5.0",
|
|
57
|
+
"path": "^0.12.7",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"typescript-eslint": "^8.46.4",
|
|
60
|
+
"vite": "^7.2.2",
|
|
61
|
+
"vitest": "^4.0.8"
|
|
62
|
+
}
|
|
63
|
+
}
|
package/rfc7464.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
|
|
8
8
|
* @see https://datatracker.ietf.org/doc/html/rfc20
|
|
9
9
|
*/
|
|
10
|
-
export declare const RS = "\
|
|
10
|
+
export declare const RS = "\u001E";
|
|
11
11
|
/**
|
|
12
12
|
* LF = %x0A; "line feed" (LF), see RFC 20
|
|
13
13
|
* @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
|