json-seq-stream 1.0.5 → 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.
@@ -0,0 +1,24 @@
1
+ export type InputJsonSequenceParseStreamOptions<T> = {
2
+ parse?: (text: string) => (T | undefined);
3
+ errorFallback?: false | ((error: unknown, args: {
4
+ error: (reason: unknown) => void;
5
+ chunk: string;
6
+ enqueue: (arg: T) => void;
7
+ }) => (void | Promise<void>));
8
+ };
9
+ /**
10
+ * string の sequence を 連続した `T` の sequence に変換する TransformStream
11
+ */
12
+ export declare class InputJsonSequenceParseStream<T> extends TransformStream<string, T> {
13
+ constructor(options?: InputJsonSequenceParseStreamOptions<T>);
14
+ }
15
+ /**
16
+ * @deprecated rename to InputJsonSequenceFormatStreamOptions
17
+ * @see InputJsonSequenceParseStreamOptions
18
+ */
19
+ export type JsonSequenceFormatStreamOptions<T> = InputJsonSequenceParseStreamOptions<T>;
20
+ /**
21
+ * @deprecated rename to InputJsonSequenceFormatStream
22
+ * @see InputJsonSequenceParseStream
23
+ */
24
+ export declare const JsonSequenceFormatStream: typeof InputJsonSequenceParseStream;
@@ -0,0 +1,25 @@
1
+ import type { InputJsonSequenceParseStreamOptions } from "./InputJsonSequenceParseStream";
2
+ import type { InputSequenceStreamOptions } from "./InputSequenceStream";
3
+ export type InputJsonSequenceStreamOptions<T> = {
4
+ label?: string;
5
+ } & TextDecoderOptions & InputJsonSequenceParseStreamOptions<T> & InputSequenceStreamOptions;
6
+ /**
7
+ * fetch 等の stream() に接続する目的の application/json-seq フォーマットを T型の json として パースする Stream
8
+ */
9
+ declare class InputJsonSequenceStream<T> extends TransformStream<BufferSource, T> {
10
+ #private;
11
+ get writable(): WritableStream<BufferSource>;
12
+ get readable(): ReadableStream<T>;
13
+ constructor(options?: InputJsonSequenceStreamOptions<T>);
14
+ }
15
+ export { InputJsonSequenceStream, InputJsonSequenceStream as default, };
16
+ /**
17
+ * @deprecated rename to InputJsonSequenceStream
18
+ * @see InputJsonSequenceStream
19
+ */
20
+ export declare const JsonSequenceStream: typeof InputJsonSequenceStream;
21
+ /**
22
+ * @deprecated rename to InputJsonSequenceStreamOptions
23
+ * @see InputJsonSequenceStreamOptions
24
+ */
25
+ export type JsonSequenceStreamOptions<T> = InputJsonSequenceStreamOptions<T>;
@@ -0,0 +1,20 @@
1
+ export type InputSequenceStreamOptions = {
2
+ lineBegin?: string;
3
+ lineEnd?: string;
4
+ };
5
+ /**
6
+ * RS で始まって LF で1行を表す 連続した文字列データを 行データとして整形して返す
7
+ */
8
+ export declare class InputSequenceStream extends TransformStream<string, string> {
9
+ constructor(options?: InputSequenceStreamOptions);
10
+ }
11
+ /**
12
+ * @deprecated rename to InputSequenceStreamOptions
13
+ * @see InputSequenceStreamOptions
14
+ */
15
+ export type SequenceStreamOptions = InputSequenceStreamOptions;
16
+ /**
17
+ * @deprecated rename to InputSequenceStream
18
+ * @see InputSequenceStream
19
+ */
20
+ export declare const SequenceStream: typeof InputSequenceStream;
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.
@@ -0,0 +1,14 @@
1
+ export type OutputJsonSequenceStringifyStreamOptions<T> = {
2
+ stringify?: (value: T) => (string | undefined);
3
+ errorFallback?: false | ((error: unknown, args: {
4
+ error: (reason: unknown) => void;
5
+ chunk: T;
6
+ enqueue: (arg: string) => void;
7
+ }) => (void | Promise<void>));
8
+ };
9
+ /**
10
+ * 連続した `T` の sequence を string の sequence に変換する TransformStream
11
+ */
12
+ export declare class OutputJsonSequenceStringifyStream<T> extends TransformStream<T, string> {
13
+ constructor(options?: OutputJsonSequenceStringifyStreamOptions<T>);
14
+ }
@@ -0,0 +1,12 @@
1
+ import type { OutputJsonSequenceStringifyStreamOptions } from "./OutputJsonSequenceStfingifyStream";
2
+ import type { OutputSequenceStreamOptions } from "./OutputSequenceStream";
3
+ export type OutputJsonSequenceStreamOptions<T> = OutputJsonSequenceStringifyStreamOptions<T> & OutputSequenceStreamOptions;
4
+ /**
5
+ * T型 を application/json-seq フォーマットに変換する Stream
6
+ */
7
+ export declare class OutputJsonSequenceStream<T> extends TransformStream<T, BufferSource> {
8
+ #private;
9
+ get writable(): WritableStream<T>;
10
+ get readable(): ReadableStream<BufferSource>;
11
+ constructor(options?: OutputJsonSequenceStreamOptions<T>);
12
+ }
@@ -0,0 +1,10 @@
1
+ export type OutputSequenceStreamOptions = {
2
+ lineBegin?: string;
3
+ lineEnd?: string;
4
+ };
5
+ /**
6
+ * 行データを RS で始まって LF で1行を表す 連続した文字列データに変換する
7
+ */
8
+ export declare class OutputSequenceStream extends TransformStream<string, string> {
9
+ constructor(options?: OutputSequenceStreamOptions);
10
+ }
package/README.md CHANGED
@@ -1,22 +1,27 @@
1
- # json-seq-stream
2
-
3
- application/json-seq support stream / async iterator library
4
-
5
- ## usage
6
-
7
- ```ts
8
- import { JsonSequenceStream } from "json-seq-stream";
9
-
10
- type Value = {
11
- value: number;
12
- };
13
-
14
- const sequenceStream = new JsonSequenceStream<Value>();
15
-
16
- const response = await fetch(url);
17
- if (!response.ok) throw new Error();
18
- const readable = response.body!.pipeThrough(sequenceStream);
19
- for await (const value of readable) {
20
- console.log(value);
21
- }
22
- ```
1
+ # json-seq-stream
2
+
3
+ application/json-seq support stream / async iterator library
4
+
5
+ ## usage
6
+
7
+ ```ts
8
+ import { InputJsonSequenceStream as JsonSequenceStream } from "json-seq-stream";
9
+
10
+ type Value = {
11
+ value: number;
12
+ };
13
+
14
+ const sequenceStream = new JsonSequenceStream<Value>();
15
+
16
+ const response = await fetch(url);
17
+ if (!response.ok) throw new Error();
18
+ const readable = response.body!.pipeThrough(sequenceStream);
19
+ for await (const value of readable) {
20
+ console.log(value);
21
+ }
22
+ ```
23
+
24
+ ## see also
25
+
26
+ - rfc7464 - JavaScript Object Notation (JSON) Text Sequences \
27
+ [https://datatracker.ietf.org/doc/html/rfc7464](https://datatracker.ietf.org/doc/html/rfc7464)
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import JsonSequenceStream from "./JsonSequenceStream";
2
- export * from "./SequenceStream";
3
- export * from "./JsonSequenceFormatStream";
4
- export { JsonSequenceStream } from "./JsonSequenceStream";
5
- export default JsonSequenceStream;
1
+ export * from "./InputSequenceStream";
2
+ export * from "./InputJsonSequenceParseStream";
3
+ export * from "./InputJsonSequenceStream";
4
+ export * from "./OutputSequenceStream";
5
+ export * from "./OutputJsonSequenceStfingifyStream";
6
+ export * from "./OutputJsonSequenceStream";
package/index.js CHANGED
@@ -1,15 +1,52 @@
1
- function S({ parse: n, errorFallback: e } = {}) {
2
- return n ??= JSON.parse, e ??= !1, { args: [
1
+ const S = "á", m = `
2
+ `, d = S, h = m;
3
+ function l({ lineBegin: t, lineEnd: e } = {}) {
4
+ t ??= d, e ??= h;
5
+ const n = [], c = new RegExp(`(${RegExp.escape(t)}|${RegExp.escape(e)})`, "u");
6
+ return {
7
+ args: [
8
+ {
9
+ transform(u, a) {
10
+ for (const o of u.split(c)) {
11
+ if (o === t) {
12
+ const i = s(n);
13
+ if (i.length <= 0) continue;
14
+ a.enqueue(i);
15
+ continue;
16
+ }
17
+ o !== e && n.push(o);
18
+ }
19
+ },
20
+ flush(u) {
21
+ const a = s(n);
22
+ a.length <= 0 || u.enqueue(a);
23
+ }
24
+ }
25
+ ]
26
+ };
27
+ function s(u) {
28
+ return u.splice(0, u.length).join("");
29
+ }
30
+ }
31
+ class f extends TransformStream {
32
+ constructor(e) {
33
+ const { args: n } = l(e);
34
+ super(...n);
35
+ }
36
+ }
37
+ const y = f;
38
+ function b({ parse: t, errorFallback: e } = {}) {
39
+ return t ??= JSON.parse, e ??= !1, { args: [
3
40
  {
4
- transform(o, u) {
41
+ transform(c, r) {
5
42
  try {
6
- const s = n(o);
7
- s && u.enqueue(s);
43
+ const s = t(c);
44
+ s && r.enqueue(s);
8
45
  } catch (s) {
9
46
  if (!e) return;
10
- const r = u.error.bind(u), a = u.enqueue.bind(u), c = e(s, { chunk: o, error: r, enqueue: a });
11
- if (c?.then)
12
- return c.catch(() => {
47
+ const u = r.error.bind(r), a = r.enqueue.bind(r), o = e(s, { chunk: c, error: u, enqueue: a });
48
+ if (o?.then)
49
+ return o.catch(() => {
13
50
  });
14
51
  }
15
52
  }
@@ -18,69 +55,101 @@ function S({ parse: n, errorFallback: e } = {}) {
18
55
  }
19
56
  class p extends TransformStream {
20
57
  constructor(e = {}) {
21
- const { args: t } = S(e);
22
- super(...t);
58
+ const { args: n } = b(e);
59
+ super(...n);
23
60
  }
24
61
  }
25
- const q = "á", l = `
26
- `;
27
- function g({ lineBegin: n, lineEnd: e } = {}) {
28
- n ??= q, e ??= l;
29
- const t = [], o = new RegExp(`(${RegExp.escape(n)}|${RegExp.escape(e)})`, "u");
30
- return {
62
+ const L = p;
63
+ function I(t) {
64
+ const { label: e, fatal: n, lineBegin: c, lineEnd: r, parse: s, errorFallback: u } = t, a = new TextDecoderStream(e, { fatal: n }), o = new f({ lineBegin: c, lineEnd: r }), i = new p({ parse: s, errorFallback: u }), { writable: q } = a, g = a.readable.pipeThrough(o).pipeThrough(i);
65
+ return { writable: q, readable: g };
66
+ }
67
+ class w extends TransformStream {
68
+ #e;
69
+ #t;
70
+ get writable() {
71
+ return this.#e;
72
+ }
73
+ get readable() {
74
+ return this.#t;
75
+ }
76
+ constructor(e = {}) {
77
+ super(), {
78
+ readable: this.#t,
79
+ writable: this.#e
80
+ } = I(e);
81
+ }
82
+ }
83
+ const R = w, x = S, J = m;
84
+ function T({ lineBegin: t, lineEnd: e } = {}) {
85
+ return t ??= x, e ??= J, {
31
86
  args: [
32
87
  {
33
- transform(r, a) {
34
- for (const c of r.split(o)) {
35
- if (c === n) {
36
- const i = s(t);
37
- if (i.length <= 0) continue;
38
- a.enqueue(i);
39
- continue;
40
- }
41
- c !== e && t.push(c);
42
- }
43
- },
44
- flush(r) {
45
- const a = s(t);
46
- a.length <= 0 || r.enqueue(a);
88
+ transform(c, r) {
89
+ r.enqueue(`${t}${c}${e}`);
47
90
  }
48
91
  }
49
92
  ]
50
93
  };
51
- function s(r) {
52
- return r.splice(0, r.length).join("");
53
- }
54
94
  }
55
- class h extends TransformStream {
95
+ class E extends TransformStream {
56
96
  constructor(e) {
57
- const { args: t } = g(e);
58
- super(...t);
97
+ const { args: n } = T(e);
98
+ super(...n);
99
+ }
100
+ }
101
+ function N({ stringify: t, errorFallback: e } = {}) {
102
+ return t ??= JSON.stringify, e ??= !1, { args: [
103
+ {
104
+ transform(c, r) {
105
+ try {
106
+ const s = t(c);
107
+ (s?.length ?? 0) > 0 && r.enqueue(s);
108
+ } catch (s) {
109
+ if (!e) return;
110
+ const u = r.error.bind(r), a = r.enqueue.bind(r), o = e(s, { chunk: c, error: u, enqueue: a });
111
+ if (o?.then)
112
+ return o.catch(() => {
113
+ });
114
+ }
115
+ }
116
+ }
117
+ ] };
118
+ }
119
+ class O extends TransformStream {
120
+ constructor(e = {}) {
121
+ const { args: n } = N(e);
122
+ super(...n);
59
123
  }
60
124
  }
61
- function d(n) {
62
- const { label: e, fatal: t, lineBegin: o, lineEnd: u, parse: s, errorFallback: r } = n, a = new TextDecoderStream(e, { fatal: t }), c = new h({ lineBegin: o, lineEnd: u }), i = new p({ parse: s, errorFallback: r }), { writable: f } = a, m = a.readable.pipeThrough(c).pipeThrough(i);
63
- return { writable: f, readable: m };
125
+ function $(t) {
126
+ const { lineBegin: e, lineEnd: n, stringify: c, errorFallback: r } = t, s = new TextEncoderStream(), u = new E({ lineBegin: e, lineEnd: n }), a = new O({ stringify: c, errorFallback: r }), { writable: o } = a, i = a.readable.pipeThrough(u).pipeThrough(s);
127
+ return { writable: o, readable: i };
64
128
  }
65
- class b extends TransformStream {
129
+ class _ extends TransformStream {
66
130
  #e;
67
- #n;
131
+ #t;
68
132
  get writable() {
69
133
  return this.#e;
70
134
  }
71
135
  get readable() {
72
- return this.#n;
136
+ return this.#t;
73
137
  }
74
138
  constructor(e = {}) {
75
139
  super(), {
76
- readable: this.#n,
140
+ readable: this.#t,
77
141
  writable: this.#e
78
- } = d(e);
142
+ } = $(e);
79
143
  }
80
144
  }
81
145
  export {
82
- p as JsonSequenceFormatStream,
83
- b as JsonSequenceStream,
84
- h as SequenceStream,
85
- b as default
146
+ p as InputJsonSequenceParseStream,
147
+ w as InputJsonSequenceStream,
148
+ f as InputSequenceStream,
149
+ L as JsonSequenceFormatStream,
150
+ R as JsonSequenceStream,
151
+ _ as OutputJsonSequenceStream,
152
+ O as OutputJsonSequenceStringifyStream,
153
+ E as OutputSequenceStream,
154
+ y as SequenceStream
86
155
  };
package/index.umd.cjs CHANGED
@@ -1,2 +1,2 @@
1
- (function(s,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(s=typeof globalThis<"u"?globalThis:s||self,f(s.index={}))})(this,function(s){"use strict";function f({parse:n,errorFallback:e}={}){return n??=JSON.parse,e??=!1,{args:[{transform(i,o){try{const u=n(i);u&&o.enqueue(u)}catch(u){if(!e)return;const r=o.error.bind(o),a=o.enqueue.bind(o),c=e(u,{chunk:i,error:r,enqueue:a});if(c?.then)return c.catch(()=>{})}}}]}}class m extends TransformStream{constructor(e={}){const{args:t}=f(e);super(...t)}}const p="á",q=`
2
- `;function h({lineBegin:n,lineEnd:e}={}){n??=p,e??=q;const t=[],i=new RegExp(`(${RegExp.escape(n)}|${RegExp.escape(e)})`,"u");return{args:[{transform(r,a){for(const c of r.split(i)){if(c===n){const d=u(t);if(d.length<=0)continue;a.enqueue(d);continue}c!==e&&t.push(c)}},flush(r){const a=u(t);a.length<=0||r.enqueue(a)}}]};function u(r){return r.splice(0,r.length).join("")}}class S extends TransformStream{constructor(e){const{args:t}=h(e);super(...t)}}function g(n){const{label:e,fatal:t,lineBegin:i,lineEnd:o,parse:u,errorFallback:r}=n,a=new TextDecoderStream(e,{fatal:t}),c=new S({lineBegin:i,lineEnd:o}),d=new m({parse:u,errorFallback:r}),{writable:b}=a,T=a.readable.pipeThrough(c).pipeThrough(d);return{writable:b,readable:T}}class l extends TransformStream{#e;#n;get writable(){return this.#e}get readable(){return this.#n}constructor(e={}){super(),{readable:this.#n,writable:this.#e}=g(e)}}s.JsonSequenceFormatStream=m,s.JsonSequenceStream=l,s.SequenceStream=S,s.default=l,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(u,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(u=typeof globalThis<"u"?globalThis:u||self,S(u.index={}))})(this,function(u){"use strict";const S="á",p=`
2
+ `,l=S,b=p;function I({lineBegin:n,lineEnd:e}={}){n??=l,e??=b;const t=[],o=new RegExp(`(${RegExp.escape(n)}|${RegExp.escape(e)})`,"u");return{args:[{transform(a,c){for(const i of a.split(o)){if(i===n){const m=s(t);if(m.length<=0)continue;c.enqueue(m);continue}i!==e&&t.push(i)}},flush(a){const c=s(t);c.length<=0||a.enqueue(c)}}]};function s(a){return a.splice(0,a.length).join("")}}class f extends TransformStream{constructor(e){const{args:t}=I(e);super(...t)}}const J=f;function w({parse:n,errorFallback:e}={}){return n??=JSON.parse,e??=!1,{args:[{transform(o,r){try{const s=n(o);s&&r.enqueue(s)}catch(s){if(!e)return;const a=r.error.bind(r),c=r.enqueue.bind(r),i=e(s,{chunk:o,error:a,enqueue:c});if(i?.then)return i.catch(()=>{})}}}]}}class q extends TransformStream{constructor(e={}){const{args:t}=w(e);super(...t)}}const T=q;function O(n){const{label:e,fatal:t,lineBegin:o,lineEnd:r,parse:s,errorFallback:a}=n,c=new TextDecoderStream(e,{fatal:t}),i=new f({lineBegin:o,lineEnd:r}),m=new q({parse:s,errorFallback:a}),{writable:P}=c,R=c.readable.pipeThrough(i).pipeThrough(m);return{writable:P,readable:R}}class d extends TransformStream{#e;#n;get writable(){return this.#e}get readable(){return this.#n}constructor(e={}){super(),{readable:this.#n,writable:this.#e}=O(e)}}const E=d,y=S,N=p;function $({lineBegin:n,lineEnd:e}={}){return n??=y,e??=N,{args:[{transform(o,r){r.enqueue(`${n}${o}${e}`)}}]}}class g extends TransformStream{constructor(e){const{args:t}=$(e);super(...t)}}function x({stringify:n,errorFallback:e}={}){return n??=JSON.stringify,e??=!1,{args:[{transform(o,r){try{const s=n(o);(s?.length??0)>0&&r.enqueue(s)}catch(s){if(!e)return;const a=r.error.bind(r),c=r.enqueue.bind(r),i=e(s,{chunk:o,error:a,enqueue:c});if(i?.then)return i.catch(()=>{})}}}]}}class h extends TransformStream{constructor(e={}){const{args:t}=x(e);super(...t)}}function j(n){const{lineBegin:e,lineEnd:t,stringify:o,errorFallback:r}=n,s=new TextEncoderStream,a=new g({lineBegin:e,lineEnd:t}),c=new h({stringify:o,errorFallback:r}),{writable:i}=c,m=c.readable.pipeThrough(a).pipeThrough(s);return{writable:i,readable:m}}class L extends TransformStream{#e;#n;get writable(){return this.#e}get readable(){return this.#n}constructor(e={}){super(),{readable:this.#n,writable:this.#e}=j(e)}}u.InputJsonSequenceParseStream=q,u.InputJsonSequenceStream=d,u.InputSequenceStream=f,u.JsonSequenceFormatStream=T,u.JsonSequenceStream=E,u.OutputJsonSequenceStream=L,u.OutputJsonSequenceStringifyStream=h,u.OutputSequenceStream=g,u.SequenceStream=J,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,59 +1,62 @@
1
- {
2
- "name": "json-seq-stream",
3
- "version": "1.0.5",
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:run": "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
- "bugs": {
42
- "url": "https://github.com/juner/json-seq-stream/issues"
43
- },
44
- "homepage": "https://github.com/juner/json-seq-stream#readme",
45
- "devDependencies": {
46
- "@eslint/js": "^9.30.1",
47
- "@eslint/json": "^0.12.0",
48
- "@eslint/markdown": "^6.6.0",
49
- "@vitest/coverage-v8": "^3.2.4",
50
- "cpx": "^1.2.1",
51
- "eslint": "^9.30.1",
52
- "globals": "^16.3.0",
53
- "path": "^0.12.7",
54
- "typescript": "^5.8.3",
55
- "typescript-eslint": "^8.36.0",
56
- "vite": "^7.0.3",
57
- "vitest": "^3.2.4"
58
- }
59
- }
1
+ {
2
+ "name": "json-seq-stream",
3
+ "version": "1.0.6",
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.30.1",
50
+ "@eslint/json": "^0.12.0",
51
+ "@eslint/markdown": "^6.6.0",
52
+ "@vitest/coverage-v8": "^3.2.4",
53
+ "cpx": "^1.2.1",
54
+ "eslint": "^9.30.1",
55
+ "globals": "^16.3.0",
56
+ "path": "^0.12.7",
57
+ "typescript": "^5.8.3",
58
+ "typescript-eslint": "^8.36.0",
59
+ "vite": "^7.0.3",
60
+ "vitest": "^3.2.4"
61
+ }
62
+ }
package/rfc7464.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * JavaScript Object Notation (JSON) Text Sequences
3
+ * @see https://datatracker.ietf.org/doc/html/rfc7464
4
+ */
5
+ /**
6
+ * RS = %x1E; "record separator" (RS), see RFC 20
7
+ * @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
8
+ * @see https://datatracker.ietf.org/doc/html/rfc20
9
+ */
10
+ export declare const RS = "\u00E1";
11
+ /**
12
+ * LF = %x0A; "line feed" (LF), see RFC 20
13
+ * @see https://datatracker.ietf.org/doc/html/rfc7464#section-2.2
14
+ * @see https://datatracker.ietf.org/doc/html/rfc20
15
+ */
16
+ export declare const LF = "\n";
@@ -1,14 +0,0 @@
1
- export type JsonSequenceFormatStreamOptions<T> = {
2
- parse?: (text: string) => (T | undefined);
3
- errorFallback?: false | ((error: unknown, args: {
4
- error: (reason: unknown) => void;
5
- chunk: string;
6
- enqueue: (arg: T) => void;
7
- }) => (void | Promise<void>));
8
- };
9
- /**
10
- * string の sequence を 連続した `T` の sequence に変換する TransformStream
11
- */
12
- export declare class JsonSequenceFormatStream<T> extends TransformStream<string, T> {
13
- constructor(options?: JsonSequenceFormatStreamOptions<T>);
14
- }
@@ -1,17 +0,0 @@
1
- import { type JsonSequenceFormatStreamOptions } from "./JsonSequenceFormatStream";
2
- import type { SequenceStreamOptions } from "./SequenceStream";
3
- export type JsonSequenceStreamOptions<T> = {
4
- label?: string;
5
- } & TextDecoderOptions & JsonSequenceFormatStreamOptions<T> & SequenceStreamOptions;
6
- /**
7
- * fetch 等の stream() に接続する目的の application/json-seq フォーマットを T型の json として パースする Stream
8
- */
9
- declare class JsonSequenceStream<T> extends TransformStream<BufferSource, T> {
10
- #private;
11
- get writable(): WritableStream<BufferSource>;
12
- get readable(): ReadableStream<T>;
13
- constructor(options?: {
14
- label?: string;
15
- } & TextDecoderOptions & JsonSequenceFormatStreamOptions<T> & SequenceStreamOptions);
16
- }
17
- export { JsonSequenceStream, JsonSequenceStream as default, };
@@ -1,10 +0,0 @@
1
- export type SequenceStreamOptions = {
2
- lineBegin?: string;
3
- lineEnd?: string;
4
- };
5
- /**
6
- * RS で始まって LF で1行を表す 連続した文字列データを 行データとして整形して返す
7
- */
8
- export declare class SequenceStream extends TransformStream<string, string> {
9
- constructor(options?: SequenceStreamOptions);
10
- }