web-csv-toolbox 0.5.2 → 0.6.0

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.
Files changed (168) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/Lexer.cjs +2 -0
  3. package/dist/cjs/Lexer.cjs.map +1 -0
  4. package/dist/cjs/LexerTransformer.cjs +2 -0
  5. package/dist/cjs/LexerTransformer.cjs.map +1 -0
  6. package/dist/cjs/RecordAssembler.cjs +2 -0
  7. package/dist/cjs/RecordAssembler.cjs.map +1 -0
  8. package/dist/cjs/RecordAssemblerTransformer.cjs +2 -0
  9. package/dist/cjs/RecordAssemblerTransformer.cjs.map +1 -0
  10. package/dist/cjs/assertCommonOptions.cjs +2 -0
  11. package/dist/cjs/assertCommonOptions.cjs.map +1 -0
  12. package/dist/cjs/common/constants.cjs +2 -0
  13. package/dist/cjs/common/constants.cjs.map +1 -0
  14. package/dist/cjs/constants.cjs +2 -0
  15. package/dist/cjs/constants.cjs.map +1 -0
  16. package/dist/cjs/convertBinaryToString.cjs +2 -0
  17. package/dist/cjs/convertBinaryToString.cjs.map +1 -0
  18. package/dist/cjs/getOptionsFromResponse.cjs +2 -0
  19. package/dist/cjs/getOptionsFromResponse.cjs.map +1 -0
  20. package/dist/cjs/parse.cjs +2 -0
  21. package/dist/cjs/parse.cjs.map +1 -0
  22. package/dist/cjs/parseBinary.cjs +2 -0
  23. package/dist/cjs/parseBinary.cjs.map +1 -0
  24. package/dist/cjs/parseBinaryToArraySync.cjs +2 -0
  25. package/dist/cjs/parseBinaryToArraySync.cjs.map +1 -0
  26. package/dist/cjs/parseBinaryToIterableIterator.cjs +2 -0
  27. package/dist/cjs/parseBinaryToIterableIterator.cjs.map +1 -0
  28. package/dist/cjs/parseBinaryToStream.cjs +2 -0
  29. package/dist/cjs/parseBinaryToStream.cjs.map +1 -0
  30. package/dist/cjs/parseResponse.cjs +2 -0
  31. package/dist/cjs/parseResponse.cjs.map +1 -0
  32. package/dist/cjs/parseResponseToStream.cjs +2 -0
  33. package/dist/cjs/parseResponseToStream.cjs.map +1 -0
  34. package/dist/cjs/parseString.cjs +2 -0
  35. package/dist/cjs/parseString.cjs.map +1 -0
  36. package/dist/cjs/parseStringStream.cjs +2 -0
  37. package/dist/cjs/parseStringStream.cjs.map +1 -0
  38. package/dist/cjs/parseStringStreamToStream.cjs +2 -0
  39. package/dist/cjs/parseStringStreamToStream.cjs.map +1 -0
  40. package/dist/cjs/parseStringToArraySync.cjs +2 -0
  41. package/dist/cjs/parseStringToArraySync.cjs.map +1 -0
  42. package/dist/cjs/parseStringToIterableIterator.cjs +2 -0
  43. package/dist/cjs/parseStringToIterableIterator.cjs.map +1 -0
  44. package/dist/cjs/parseStringToStream.cjs +2 -0
  45. package/dist/cjs/parseStringToStream.cjs.map +1 -0
  46. package/dist/cjs/parseUint8ArrayStream.cjs +2 -0
  47. package/dist/cjs/parseUint8ArrayStream.cjs.map +1 -0
  48. package/dist/cjs/parseUint8ArrayStreamToStream.cjs +2 -0
  49. package/dist/cjs/parseUint8ArrayStreamToStream.cjs.map +1 -0
  50. package/dist/cjs/utils/convertIterableIteratorToAsync.cjs +2 -0
  51. package/dist/cjs/utils/convertIterableIteratorToAsync.cjs.map +1 -0
  52. package/dist/cjs/utils/convertStreamToAsyncIterableIterator.cjs +2 -0
  53. package/dist/cjs/utils/convertStreamToAsyncIterableIterator.cjs.map +1 -0
  54. package/dist/cjs/utils/convertThisAsyncIterableIteratorToArray.cjs +2 -0
  55. package/dist/cjs/utils/convertThisAsyncIterableIteratorToArray.cjs.map +1 -0
  56. package/dist/cjs/utils/escapeRegExp.cjs +2 -0
  57. package/dist/cjs/utils/escapeRegExp.cjs.map +1 -0
  58. package/dist/cjs/utils/parseMime.cjs +2 -0
  59. package/dist/cjs/utils/parseMime.cjs.map +1 -0
  60. package/dist/cjs/utils/pipeline.cjs +2 -0
  61. package/dist/cjs/utils/pipeline.cjs.map +1 -0
  62. package/dist/cjs/web-csv-toolbox.cjs +2 -0
  63. package/dist/cjs/web-csv-toolbox.cjs.map +1 -0
  64. package/dist/es/Lexer.js +151 -0
  65. package/dist/es/Lexer.js.map +1 -0
  66. package/dist/es/LexerTransformer.js +20 -0
  67. package/dist/es/LexerTransformer.js.map +1 -0
  68. package/dist/es/RecordAssembler.js +72 -0
  69. package/dist/es/RecordAssembler.js.map +1 -0
  70. package/dist/es/RecordAssemblerTransformer.js +22 -0
  71. package/dist/es/RecordAssemblerTransformer.js.map +1 -0
  72. package/dist/es/assertCommonOptions.js +24 -0
  73. package/dist/es/assertCommonOptions.js.map +1 -0
  74. package/dist/es/common/constants.js +6 -0
  75. package/dist/es/common/constants.js.map +1 -0
  76. package/dist/es/constants.js +8 -0
  77. package/dist/es/constants.js.map +1 -0
  78. package/dist/es/convertBinaryToString.js +9 -0
  79. package/dist/es/convertBinaryToString.js.map +1 -0
  80. package/dist/es/getOptionsFromResponse.js +20 -0
  81. package/dist/es/getOptionsFromResponse.js.map +1 -0
  82. package/dist/es/parse.js +39 -0
  83. package/dist/es/parse.js.map +1 -0
  84. package/dist/es/parseBinary.js +35 -0
  85. package/dist/es/parseBinary.js.map +1 -0
  86. package/dist/es/parseBinaryToArraySync.js +10 -0
  87. package/dist/es/parseBinaryToArraySync.js.map +1 -0
  88. package/dist/es/parseBinaryToIterableIterator.js +10 -0
  89. package/dist/es/parseBinaryToIterableIterator.js.map +1 -0
  90. package/dist/es/parseBinaryToStream.js +10 -0
  91. package/dist/es/parseBinaryToStream.js.map +1 -0
  92. package/dist/es/parseResponse.js +27 -0
  93. package/dist/es/parseResponse.js.map +1 -0
  94. package/dist/es/parseResponseToStream.js +13 -0
  95. package/dist/es/parseResponseToStream.js.map +1 -0
  96. package/dist/es/parseString.js +33 -0
  97. package/dist/es/parseString.js.map +1 -0
  98. package/dist/es/parseStringStream.js +23 -0
  99. package/dist/es/parseStringStream.js.map +1 -0
  100. package/dist/es/parseStringStreamToStream.js +14 -0
  101. package/dist/es/parseStringStreamToStream.js.map +1 -0
  102. package/dist/es/parseStringToArraySync.js +12 -0
  103. package/dist/es/parseStringToArraySync.js.map +1 -0
  104. package/dist/es/parseStringToIterableIterator.js +12 -0
  105. package/dist/es/parseStringToIterableIterator.js.map +1 -0
  106. package/dist/es/parseStringToStream.js +19 -0
  107. package/dist/es/parseStringToStream.js.map +1 -0
  108. package/dist/es/parseUint8ArrayStream.js +23 -0
  109. package/dist/es/parseUint8ArrayStream.js.map +1 -0
  110. package/dist/es/parseUint8ArrayStreamToStream.js +22 -0
  111. package/dist/es/parseUint8ArrayStreamToStream.js.map +1 -0
  112. package/dist/es/utils/convertIterableIteratorToAsync.js +14 -0
  113. package/dist/es/utils/convertIterableIteratorToAsync.js.map +1 -0
  114. package/dist/es/utils/convertStreamToAsyncIterableIterator.js +12 -0
  115. package/dist/es/utils/convertStreamToAsyncIterableIterator.js.map +1 -0
  116. package/dist/es/utils/convertThisAsyncIterableIteratorToArray.js +10 -0
  117. package/dist/es/utils/convertThisAsyncIterableIteratorToArray.js.map +1 -0
  118. package/dist/es/utils/escapeRegExp.js +6 -0
  119. package/dist/es/utils/escapeRegExp.js.map +1 -0
  120. package/dist/es/utils/parseMime.js +15 -0
  121. package/dist/es/utils/parseMime.js.map +1 -0
  122. package/dist/es/utils/pipeline.js +18 -0
  123. package/dist/es/utils/pipeline.js.map +1 -0
  124. package/dist/es/web-csv-toolbox.js +10 -0
  125. package/dist/es/web-csv-toolbox.js.map +1 -0
  126. package/dist/types/Lexer.d.ts +7 -0
  127. package/dist/types/LexerTransformer.d.ts +34 -0
  128. package/dist/types/RecordAssembler.d.ts +7 -0
  129. package/dist/types/RecordAssemblerTransformer.d.ts +47 -0
  130. package/dist/types/assertCommonOptions.d.ts +7 -0
  131. package/dist/types/common/constants.d.ts +15 -0
  132. package/dist/types/common/types.d.ts +163 -0
  133. package/dist/types/constants.d.ts +11 -0
  134. package/dist/types/convertBinaryToString.d.ts +2 -0
  135. package/dist/types/escapeField.d.ts +13 -0
  136. package/dist/types/getOptionsFromResponse.d.ts +2 -0
  137. package/dist/types/parse.d.ts +182 -0
  138. package/dist/types/parseBinary.d.ts +113 -0
  139. package/dist/types/parseBinaryToArraySync.d.ts +2 -0
  140. package/dist/types/parseBinaryToIterableIterator.d.ts +2 -0
  141. package/dist/types/parseBinaryToStream.d.ts +2 -0
  142. package/dist/types/parseResponse.d.ts +80 -0
  143. package/dist/types/parseResponseToStream.d.ts +2 -0
  144. package/dist/types/parseString.d.ts +120 -0
  145. package/dist/types/parseStringStream.d.ts +98 -0
  146. package/dist/types/parseStringStreamToStream.d.ts +2 -0
  147. package/dist/types/parseStringToArraySync.d.ts +2 -0
  148. package/dist/types/parseStringToIterableIterator.d.ts +2 -0
  149. package/dist/types/parseStringToStream.d.ts +2 -0
  150. package/dist/types/parseUint8ArrayStream.d.ts +94 -0
  151. package/dist/types/parseUint8ArrayStreamToStream.d.ts +2 -0
  152. package/dist/types/utils/SingleValueReadableStream.d.ts +3 -0
  153. package/dist/types/utils/convertIterableIteratorToAsync.d.ts +1 -0
  154. package/dist/types/utils/convertStreamToAsyncIterableIterator.d.ts +1 -0
  155. package/dist/types/utils/convertThisAsyncIterableIteratorToArray.d.ts +1 -0
  156. package/dist/types/utils/escapeRegExp.d.ts +8 -0
  157. package/dist/types/utils/occurrences.d.ts +7 -0
  158. package/dist/types/utils/parseMime.d.ts +7 -0
  159. package/dist/types/utils/pipeline.d.ts +3 -0
  160. package/dist/types/web-csv-toolbox.d.ts +10 -0
  161. package/dist/web-csv-toolbox.umd.cjs +1 -1
  162. package/dist/web-csv-toolbox.umd.cjs.map +1 -1
  163. package/package.json +31 -13
  164. package/dist/web-csv-toolbox.cjs +0 -2
  165. package/dist/web-csv-toolbox.cjs.map +0 -1
  166. package/dist/web-csv-toolbox.d.ts +0 -982
  167. package/dist/web-csv-toolbox.js +0 -576
  168. package/dist/web-csv-toolbox.js.map +0 -1
@@ -0,0 +1,120 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse CSV string to records.
4
+ *
5
+ * @category Middle-level API
6
+ * @param csv CSV string to parse
7
+ * @param options Parsing options. See {@link ParseOptions}.
8
+ * @returns Async iterable iterator of records.
9
+ *
10
+ * If you want array of records, use {@link parseString.toArray} function.
11
+ * @example Parsing CSV files from strings
12
+ *
13
+ * ```ts
14
+ * import { parseString } from 'web-csv-toolbox';
15
+ *
16
+ * const csv = `name,age
17
+ * Alice,42
18
+ * Bob,69`;
19
+ *
20
+ * for await (const record of parseString(csv)) {
21
+ * console.log(record);
22
+ * }
23
+ * // Prints:
24
+ * // { name: 'Alice', age: '42' }
25
+ * // { name: 'Bob', age: '69' }
26
+ * ```
27
+ */
28
+ export declare function parseString<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
29
+ export declare namespace parseString {
30
+ /**
31
+ * Parse CSV string to records.
32
+ *
33
+ * @returns Array of records
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * import { parseString } from 'web-csv-toolbox';
38
+ *
39
+ * const csv = `name,age
40
+ * Alice,42
41
+ * Bob,69`;
42
+ *
43
+ * const records = await parseString.toArray(csv);
44
+ * console.log(records);
45
+ * // Prints:
46
+ * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ]
47
+ * ```
48
+ */
49
+ function toArray<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): Promise<CSVRecord<Header>[]>;
50
+ /**
51
+ * Parse CSV string to records.
52
+ *
53
+ * @returns Array of records
54
+ *
55
+ * @example
56
+ *
57
+ * ```ts
58
+ * import { parseString } from 'web-csv-toolbox';
59
+ *
60
+ * const csv = `name,age
61
+ * Alice,42
62
+ * Bob,69`;
63
+ *
64
+ * const records = parseString.toArraySync(csv);
65
+ * console.log(records);
66
+ * // Prints:
67
+ * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ]
68
+ * ```
69
+ */
70
+ function toArraySync<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[];
71
+ /**
72
+ * Parse CSV string to records.
73
+ *
74
+ * @returns Async iterable iterator of records
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import { parseString } from 'web-csv-toolbox';
79
+ *
80
+ * const csv = `name,age
81
+ * Alice,42
82
+ * Bob,69`;
83
+ *
84
+ * for (const record of parseString.toIterableIterator(csv)) {
85
+ * console.log(record);
86
+ * }
87
+ * // Prints:
88
+ * // { name: 'Alice', age: '42' }
89
+ * // { name: 'Bob', age: '69' }
90
+ * ```
91
+ */
92
+ function toIterableIterator<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): IterableIterator<CSVRecord<Header>>;
93
+ /**
94
+ * Parse CSV string to records.
95
+ *
96
+ * @returns Readable stream of records
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { parseString } from 'web-csv-toolbox';
101
+ *
102
+ * const csv = `name,age
103
+ * Alice,42
104
+ * Bob,69`;
105
+ *
106
+ * await parseString.toStream(csv)
107
+ * .pipeTo(
108
+ * new WritableStream({
109
+ * write(record) {
110
+ * console.log(record);
111
+ * },
112
+ * }),
113
+ * );
114
+ * // Prints:
115
+ * // { name: 'Alice', age: '42' }
116
+ * // { name: 'Bob', age: '69' }
117
+ * ```
118
+ */
119
+ function toStream<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): ReadableStream<CSVRecord<Header>>;
120
+ }
@@ -0,0 +1,98 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse CSV string stream to records.
4
+ *
5
+ * @category Middle-level API
6
+ * @param stream CSV string stream to parse
7
+ * @param options Parsing options.
8
+ * @returns Async iterable iterator of records.
9
+ *
10
+ * If you want array of records, use {@link parseStringStream.toArray} function.
11
+ *
12
+ * @example Parsing CSV files from strings
13
+ *
14
+ * ```ts
15
+ * import { parseStringStream } from 'web-csv-toolbox';
16
+ *
17
+ * const csv = `name,age
18
+ * Alice,42
19
+ * Bob,69`;
20
+ *
21
+ * const stream = new ReadableStream({
22
+ * start(controller) {
23
+ * controller.enqueue(csv);
24
+ * controller.close();
25
+ * },
26
+ * });
27
+ *
28
+ * for await (const record of parseStringStream(csv)) {
29
+ * console.log(record);
30
+ * }
31
+ * // Prints:
32
+ * // { name: 'Alice', age: '42' }
33
+ * // { name: 'Bob', age: '69' }
34
+ * ```
35
+ */
36
+ export declare function parseStringStream<Header extends ReadonlyArray<string>>(stream: ReadableStream<string>, options?: ParseOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
37
+ export declare namespace parseStringStream {
38
+ /**
39
+ * Parse CSV string stream to records.
40
+ *
41
+ * @returns Array of records
42
+ *
43
+ * @example
44
+ *
45
+ * ```ts
46
+ * import { parseStringStream } from 'web-csv-toolbox';
47
+ *
48
+ * const csv = `name,age
49
+ * Alice,42
50
+ * Bob,69`;
51
+ *
52
+ * const stream = new ReadableStream({
53
+ * start(controller) {
54
+ * controller.enqueue(csv);
55
+ * controller.close();
56
+ * },
57
+ * });
58
+ *
59
+ * const records = await parseStringStream.toArray(stream);
60
+ * console.log(records);
61
+ * // Prints:
62
+ * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ]
63
+ * ```
64
+ */
65
+ function toArray<Header extends ReadonlyArray<string>>(stream: ReadableStream<string>, options?: ParseOptions<Header>): Promise<CSVRecord<Header>[]>;
66
+ /**
67
+ * Parse CSV string stream to records.
68
+ *
69
+ * @returns Array of records
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * import { parseStringStream } from 'web-csv-toolbox';
75
+ *
76
+ * const csv = `name,age
77
+ * Alice,42
78
+ * Bob,69`;
79
+ *
80
+ * const stream = new ReadableStream({
81
+ * start(controller) {
82
+ * controller.enqueue(csv);
83
+ * controller.close();
84
+ * },
85
+ * });
86
+ *
87
+ * await parseStringStream.toStream(stream)
88
+ * .pipeTo(
89
+ * new WritableStream({
90
+ * write(record) {
91
+ * console.log(record);
92
+ * },
93
+ * }),
94
+ * );
95
+ * ```
96
+ */
97
+ function toStream<Header extends ReadonlyArray<string>>(stream: ReadableStream<string>, options?: ParseOptions<Header>): ReadableStream<CSVRecord<Header>>;
98
+ }
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ export declare function parseStringStreamToStream<Header extends ReadonlyArray<string>>(stream: ReadableStream<string>, options?: ParseOptions<Header>): ReadableStream<CSVRecord<Header>>;
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ export declare function parseStringToArraySync<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): CSVRecord<Header>[];
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ export declare function parseStringToIterableIterator<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): IterableIterator<CSVRecord<Header>>;
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ export declare function parseStringToStream<Header extends ReadonlyArray<string>>(csv: string, options?: ParseOptions<Header>): ReadableStream<CSVRecord<Header>>;
@@ -0,0 +1,94 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse CSV to records.
4
+ * This function is for parsing a binary stream.
5
+ *
6
+ * @category Middle-level API
7
+ * @remarks
8
+ * If you want to parse a string, use {@link parseStringStream}.
9
+ * @param stream CSV string to parse
10
+ * @param options Parsing options.
11
+ * @returns Async iterable iterator of records.
12
+ *
13
+ * If you want array of records, use {@link parseUint8ArrayStream.toArray} function.
14
+ *
15
+ * @example Parsing CSV binary
16
+ *
17
+ * ```ts
18
+ * import { parseUint8ArrayStream } from 'web-csv-toolbox';
19
+ *
20
+ * const csv = Uint8Array.from([
21
+ * // ...
22
+ * ]);
23
+ *
24
+ * const stream = new ReadableStream({
25
+ * start(controller) {
26
+ * controller.enqueue(csv);
27
+ * controller.close();
28
+ * },
29
+ * });
30
+ *
31
+ * for await (const record of parseUint8ArrayStream(csv)) {
32
+ * console.log(record);
33
+ * }
34
+ * ```
35
+ */
36
+ export declare function parseUint8ArrayStream<Header extends ReadonlyArray<string>>(stream: ReadableStream<Uint8Array>, options?: ParseBinaryOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
37
+ export declare namespace parseUint8ArrayStream {
38
+ /**
39
+ * Parse CSV binary to array of records,
40
+ * ideal for smaller data sets.
41
+ *
42
+ * @returns Array of records
43
+ *
44
+ * @example Parsing CSV binary
45
+ * ```ts
46
+ * import { parseUint8ArrayStream } from 'web-csv-toolbox';
47
+ *
48
+ * const csv = Uint8Array.from([
49
+ * // ...
50
+ * ]);
51
+ *
52
+ * const stream = new ReadableStream({
53
+ * start(controller) {
54
+ * controller.enqueue(csv);
55
+ * controller.close();
56
+ * },
57
+ * });
58
+ *
59
+ * const records = await parseUint8ArrayStream.toArray(stream);
60
+ * console.log(records);
61
+ * ```
62
+ */
63
+ function toArray<Header extends ReadonlyArray<string>>(stream: ReadableStream<Uint8Array>, options?: ParseBinaryOptions<Header>): Promise<CSVRecord<Header>[]>;
64
+ /**
65
+ * Parse CSV binary to array of records.
66
+ *
67
+ * @returns Stream of records
68
+ *
69
+ * @example Parsing CSV binary
70
+ * ```ts
71
+ * import { parseUint8ArrayStream } from 'web-csv-toolbox';
72
+ *
73
+ * const csv = Uint8Array.from([
74
+ * // ...
75
+ * ]);
76
+ *
77
+ * const stream = new ReadableStream({
78
+ * start(controller) {
79
+ * controller.enqueue(csv);
80
+ * controller.close();
81
+ * },
82
+ * });
83
+ *
84
+ * await parseUint8ArrayStream.toStream(stream)
85
+ * .pipeTo(new WritableStream({
86
+ * write(record) {
87
+ * console.log(record);
88
+ * },
89
+ * }),
90
+ * );
91
+ * ```
92
+ */
93
+ function toStream<Header extends ReadonlyArray<string>>(stream: ReadableStream<Uint8Array>, options?: ParseBinaryOptions<Header>): ReadableStream<CSVRecord<Header>[]>;
94
+ }
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ export declare function parseUint8ArrayStreamToStream<Header extends readonly string[]>(stream: ReadableStream<Uint8Array>, options?: ParseBinaryOptions<Header>): ReadableStream<CSVRecord<Header>>;
@@ -0,0 +1,3 @@
1
+ export declare class SingleValueReadableStream<T> extends ReadableStream<T> {
2
+ constructor(value: T);
3
+ }
@@ -0,0 +1 @@
1
+ export declare function convertIterableIteratorToAsync<T>(iterator: IterableIterator<T>): AsyncIterableIterator<T>;
@@ -0,0 +1 @@
1
+ export declare function convertStreamToAsyncIterableIterator<T>(stream: ReadableStream<T>): AsyncIterableIterator<T>;
@@ -0,0 +1 @@
1
+ export declare function convertThisAsyncIterableIteratorToArray<O, T extends (...args: any[]) => AsyncGenerator<O>>(this: T, ...args: Parameters<T>): Promise<O[]>;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Escape a string for use in a regular expression.
3
+ *
4
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#escaping Regular expressions#Escaping | MDN}
5
+ * @param v string to escape
6
+ * @returns escaped string
7
+ */
8
+ export declare function escapeRegExp(v: string): string;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Get the number of occurrences of a substring in a string.
3
+ * @param string The string.
4
+ * @param substring The substring.
5
+ * @returns The number of occurrences.
6
+ */
7
+ export declare function occurrences(string: string, substring: string): number;
@@ -0,0 +1,7 @@
1
+ export interface ParseMimeResult {
2
+ type: string;
3
+ parameters: {
4
+ [key: string]: string;
5
+ };
6
+ }
7
+ export declare function parseMime(contentType: string): ParseMimeResult;
@@ -0,0 +1,3 @@
1
+ export declare function pipeline<I, T, O>(stream: ReadableStream<I>, transformer1: TransformStream<I, T>, transformer2: TransformStream<T, O>): ReadableStream<O>;
2
+ export declare function pipeline<I, T1, T2, O>(stream: ReadableStream<I>, transformer1: TransformStream<I, T1>, transformer2: TransformStream<T1, T2>, transformer3: TransformStream<T2, O>): ReadableStream<O>;
3
+ export declare function pipeline<I, T1, T2, T3, O>(stream: ReadableStream<I>, transformer1: TransformStream<I, T1>, transformer2: TransformStream<T1, T2>, transformer3: TransformStream<T2, T3>, transformer4: TransformStream<T3, O>): ReadableStream<O>;
@@ -0,0 +1,10 @@
1
+ export * from "./common/constants.ts";
2
+ export * from "./common/types.ts";
3
+ export * from "./LexerTransformer.ts";
4
+ export * from "./RecordAssemblerTransformer.ts";
5
+ export * from "./parseString.ts";
6
+ export * from "./parseBinary.ts";
7
+ export * from "./parseUint8ArrayStream.ts";
8
+ export * from "./parseStringStream.ts";
9
+ export * from "./parseResponse.ts";
10
+ export * from "./parse.ts";
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["CSV "]={})}(this,(function(e){"use strict";const t=Symbol.for("web-csv-toolbox.FieldDelimiter"),r=Symbol.for("web-csv-toolbox.RecordDelimiter"),i=Symbol.for("web-csv-toolbox.Field"),n="\r\n",o="\n";function s(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}class a{#e;#t;#r;#i;#n;#o="";#s=!1;constructor({delimiter:e=",",quotation:t='"'}={}){!function(e){if("string"==typeof e.quotation&&0===e.quotation.length)throw new Error("quotation must not be empty");if("string"==typeof e.delimiter&&0===e.delimiter.length)throw new Error("delimiter must not be empty");if(e.quotation.includes(o)||e.quotation.includes("\r"))throw new Error("quotation must not include CR or LF");if(e.delimiter.includes(o)||e.delimiter.includes("\r"))throw new Error("delimiter must not include CR or LF");if(e.delimiter.includes(e.quotation)||e.quotation.includes(e.delimiter))throw new Error("delimiter and quotation must not include each other as a substring")}({delimiter:e,quotation:t}),this.#e=e,this.#t=e.length,this.#r=t,this.#i=t.length;const r=s(e),i=s(t);this.#n=new RegExp(`^(?:(?!${i})(?!${r})(?![\\r\\n]))([\\S\\s\\uFEFF\\xA0]+?)(?=${i}|${r}|\\r|\\n|$)`)}lex(e,t=!1){return t||(this.#s=!0),"string"==typeof e&&0!==e.length&&(this.#o+=e),this.#a()}flush(){return this.#s=!0,[...this.#a()]}*#a(){this.#s&&(this.#o.endsWith(n)?this.#o=this.#o.slice(0,-2):this.#o.endsWith(o)&&(this.#o=this.#o.slice(0,-1)));let e=null;for(let i;i=this.#u();)switch(i){case t:case r:e&&(yield e,e=null),yield i;break;default:e?e.value+=i.value:e=i}e&&(yield e)}#u(){if(0===this.#o.length)return null;if(!1===this.#s&&(this.#o===n||this.#o===o))return null;if(this.#o.startsWith(n))return this.#o=this.#o.slice(2),r;if(this.#o.startsWith(o))return this.#o=this.#o.slice(1),r;if(this.#o.startsWith(this.#e))return this.#o=this.#o.slice(this.#t),t;if(this.#o.startsWith(this.#r))return!1===this.#s&&this.#o.endsWith(this.#r)?null:this.#l();const e=this.#n.exec(this.#o);return e?!1===this.#s&&e[0].length===this.#o.length?null:(this.#o=this.#o.slice(e[0].length),{type:i,value:e[0]}):null}#l(){let e=this.#i,t="";for(;e<this.#o.length;)if(this.#o.slice(e,e+this.#i)!==this.#r||this.#o.slice(e+this.#i,e+2*this.#i)!==this.#r){if(this.#o.slice(e,e+this.#i)===this.#r)return!1===this.#s&&e+this.#i<this.#o.length&&this.#o.slice(e+this.#i,this.#t)!==this.#e&&this.#o.slice(e+this.#i,e+this.#i+2)!==n&&this.#o.slice(e+this.#i,e+this.#i+1)!==o?null:(this.#o=this.#o.slice(e+this.#i),{type:i,value:t});t+=this.#o[e],e++}else t+=this.#r,e+=2*this.#i;return null}}class u extends TransformStream{constructor(e={}){const t=new a(e);super({transform:(e,r)=>{0!==e.length&&r.enqueue([...t.lex(e,!0)])},flush:e=>{e.enqueue(t.flush())}})}}class l{#f=0;#h=[];#c;#d=!1;constructor(e={}){void 0!==e.header&&Array.isArray(e.header)&&this.#b(e.header)}*assemble(e,i=!0){for(const n of e)switch(n){case t:this.#f++,this.#d=!0;break;case r:void 0===this.#c?this.#b(this.#h):this.#d?yield Object.fromEntries(this.#c.map(((e,t)=>[e,this.#h.at(t)]))):yield Object.fromEntries(this.#c.map((e=>[e,""]))),this.#f=0,this.#h=new Array(this.#c?.length).fill(""),this.#d=!1;break;default:this.#d=!0,this.#h[this.#f]=n.value}i&&(yield*this.flush())}*flush(){void 0!==this.#c&&this.#d&&(yield Object.fromEntries(this.#c.filter((e=>e)).map(((e,t)=>[e,this.#h.at(t)]))))}#b(e){if(this.#c=e,0===this.#c.length)throw new Error("The header must not be empty.");if(new Set(this.#c).size!==this.#c.length)throw new Error("The header must not contain duplicate fields.")}}class f extends TransformStream{constructor(e={}){const t=new l(e);super({transform:(e,r)=>{for(const i of t.assemble(e,!1))r.enqueue(i)},flush:e=>{for(const r of t.flush())e.enqueue(r)}})}}function h(e,t){const r=new a(t),i=new l(t),n=r.lex(e);return[...i.assemble(n)]}function c(e,t){const r=new a(t),i=new l(t),n=r.lex(e);return i.assemble(n)}function d(e,t){const r=new a(t),i=new l(t);return new ReadableStream({start(t){const n=r.lex(e);for(const e of i.assemble(n))t.enqueue(e);t.close()}})}async function b(...e){const t=[];for await(const r of this(...e))t.push(r);return t}async function*m(e,t){yield*c(e,t)}var y,w,p,g,q,v;function x(e,t){return new TextDecoder(t?.charset,{ignoreBOM:t?.ignoreBOM,fatal:t?.fatal}).decode(e instanceof ArrayBuffer?new Uint8Array(e):e)}function S(e,t={}){return h(x(e,t),t)}function O(e,t={}){return c(x(e,t),t)}function L(e,t={}){return d(x(e,t),t)}function j(e,t){return function(e){return{async next(){const t=e.next();return Promise.resolve(t)},[Symbol.asyncIterator](){return this}}}(O(e,t))}function A(e,...t){return new ReadableStream({start:r=>{t.reduce(((e,t)=>e.pipeThrough(t)),e).pipeTo(new WritableStream({write:e=>r.enqueue(e),close:()=>r.close()}))}})}function P(e,t){const{charset:r,fatal:i,ignoreBOM:n,decomposition:o}=t??{};return o?A(e,new DecompressionStream(o),new TextDecoderStream(r,{fatal:i,ignoreBOM:n}),new u(t),new f(t)):A(e,new TextDecoderStream(r,{fatal:i,ignoreBOM:n}),new u(t),new f(t))}async function*T(e){const t=e.getReader();for(;;){const{done:e,value:r}=await t.read();if(e)break;yield r}}function E(e,t){return T(P(e,t))}function R(e,t){return A(e,new u(t),new f(t))}function k(e,t){return T(R(e,t))}function I(e,t={}){const{headers:r}=e,i=r.get("content-type")??"text/csv",n=function(e){const[t,...r]=e.split(";"),i={type:t.trim(),parameters:{}};for(const n of r){const[e,t]=n.split("=");i.parameters[e.trim()]=t.trim()}return i}(i);if("text/csv"!==n.type)throw new Error(`Invalid mime type: ${i}`);return{decomposition:r.get("content-encoding")??void 0,charset:n.parameters.charset??"utf-8",...t}}function F(e,t){const r=I(e,t);if(null===e.body)throw new Error("Response body is null");return P(e.body,r)}function B(e,t){const r=I(e,t);if(null===e.body)throw new Error("Response body is null");return E(e.body,r)}async function*D(e,t){if("string"==typeof e)yield*m(e,t);else if(e instanceof Uint8Array||e instanceof ArrayBuffer)yield*j(e,t);else if(e instanceof ReadableStream){const[r,i]=e.tee(),n=r.getReader(),{value:o}=await n.read();n.releaseLock(),"string"==typeof o?yield*k(i,t):o instanceof Uint8Array&&(yield*E(i,t))}else e instanceof Response&&(yield*B(e,t))}y=m||(m={}),Object.defineProperty(y,"toArray",{enumerable:!0,writable:!1,value:b}),Object.defineProperty(y,"toArraySync",{enumerable:!0,writable:!1,value:h}),Object.defineProperty(y,"toIterableIterator",{enumerable:!0,writable:!1,value:c}),Object.defineProperty(y,"toStream",{enumerable:!0,writable:!1,value:d}),w=j||(j={}),Object.defineProperty(w,"toArray",{enumerable:!0,writable:!1,value:b}),Object.defineProperty(w,"toArraySync",{enumerable:!0,writable:!1,value:S}),Object.defineProperty(w,"toIterableIterator",{enumerable:!0,writable:!1,value:O}),Object.defineProperty(w,"toStream",{enumerable:!0,writable:!1,value:L}),p=E||(E={}),Object.defineProperty(p,"toArray",{enumerable:!0,writable:!1,value:b}),Object.defineProperty(p,"toStream",{enumerable:!0,writable:!1,value:P}),g=k||(k={}),Object.defineProperty(g,"toArray",{enumerable:!0,writable:!1,value:b}),Object.defineProperty(g,"toStream",{enumerable:!0,writable:!1,value:R}),q=B||(B={}),Object.defineProperty(q,"toArray",{enumerable:!0,writable:!1,value:b}),Object.defineProperty(q,"toStream",{enumerable:!0,writable:!1,value:F}),v=D||(D={}),Object.defineProperty(v,"toArray",{enumerable:!0,writable:!1,value:b}),e.Field=i,e.FieldDelimiter=t,e.LexerTransformer=u,e.RecordAssemblerTransformer=f,e.RecordDelimiter=r,e.parse=D,e.parseBinary=j,e.parseResponse=B,e.parseString=m,e.parseStringStream=k,e.parseUint8ArrayStream=E,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CSV={})}(this,(function(e){"use strict";const t=Symbol.for("web-csv-toolbox.FieldDelimiter"),r=Symbol.for("web-csv-toolbox.RecordDelimiter"),i=Symbol.for("web-csv-toolbox.Field"),n="\r\n",s="\n";function o(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}class a{#e;#t;#r;#i;#n;#s="";#o=!1;constructor({delimiter:e=",",quotation:t='"'}={}){!function(e){if("string"==typeof e.quotation&&0===e.quotation.length)throw new Error("quotation must not be empty");if("string"==typeof e.delimiter&&0===e.delimiter.length)throw new Error("delimiter must not be empty");if(e.quotation.includes(s)||e.quotation.includes("\r"))throw new Error("quotation must not include CR or LF");if(e.delimiter.includes(s)||e.delimiter.includes("\r"))throw new Error("delimiter must not include CR or LF");if(e.delimiter.includes(e.quotation)||e.quotation.includes(e.delimiter))throw new Error("delimiter and quotation must not include each other as a substring")}({delimiter:e,quotation:t}),this.#e=e,this.#t=e.length,this.#r=t,this.#i=t.length;const r=o(e),i=o(t);this.#n=new RegExp(`^(?:(?!${i})(?!${r})(?![\\r\\n]))([\\S\\s\\uFEFF\\xA0]+?)(?=${i}|${r}|\\r|\\n|$)`)}lex(e,t=!1){return t||(this.#o=!0),"string"==typeof e&&0!==e.length&&(this.#s+=e),this.#a()}flush(){return this.#o=!0,[...this.#a()]}*#a(){this.#o&&(this.#s.endsWith(n)?this.#s=this.#s.slice(0,-2):this.#s.endsWith(s)&&(this.#s=this.#s.slice(0,-1)));let e=null;for(let i;i=this.#u();)switch(i){case t:case r:e&&(yield e,e=null),yield i;break;default:e?e.value+=i.value:e=i}e&&(yield e)}#u(){if(0===this.#s.length)return null;if(!1===this.#o&&(this.#s===n||this.#s===s))return null;if(this.#s.startsWith(n))return this.#s=this.#s.slice(2),r;if(this.#s.startsWith(s))return this.#s=this.#s.slice(1),r;if(this.#s.startsWith(this.#e))return this.#s=this.#s.slice(this.#t),t;if(this.#s.startsWith(this.#r))return!1===this.#o&&this.#s.endsWith(this.#r)?null:this.#l();const e=this.#n.exec(this.#s);return e?!1===this.#o&&e[0].length===this.#s.length?null:(this.#s=this.#s.slice(e[0].length),{type:i,value:e[0]}):null}#l(){let e=this.#i,t="";for(;e<this.#s.length;)if(this.#s.slice(e,e+this.#i)!==this.#r||this.#s.slice(e+this.#i,e+2*this.#i)!==this.#r){if(this.#s.slice(e,e+this.#i)===this.#r)return!1===this.#o&&e+this.#i<this.#s.length&&this.#s.slice(e+this.#i,this.#t)!==this.#e&&this.#s.slice(e+this.#i,e+this.#i+2)!==n&&this.#s.slice(e+this.#i,e+this.#i+1)!==s?null:(this.#s=this.#s.slice(e+this.#i),{type:i,value:t});t+=this.#s[e],e++}else t+=this.#r,e+=2*this.#i;return null}}class u extends TransformStream{constructor(e={}){const t=new a(e);super({transform:(e,r)=>{0!==e.length&&r.enqueue([...t.lex(e,!0)])},flush:e=>{e.enqueue(t.flush())}})}}class l{#f=0;#h=[];#c;#d=!1;constructor(e={}){void 0!==e.header&&Array.isArray(e.header)&&this.#b(e.header)}*assemble(e,i=!0){for(const n of e)switch(n){case t:this.#f++,this.#d=!0;break;case r:void 0===this.#c?this.#b(this.#h):this.#d?yield Object.fromEntries(this.#c.map(((e,t)=>[e,this.#h.at(t)]))):yield Object.fromEntries(this.#c.map((e=>[e,""]))),this.#f=0,this.#h=new Array(this.#c?.length).fill(""),this.#d=!1;break;default:this.#d=!0,this.#h[this.#f]=n.value}i&&(yield*this.flush())}*flush(){void 0!==this.#c&&this.#d&&(yield Object.fromEntries(this.#c.filter((e=>e)).map(((e,t)=>[e,this.#h.at(t)]))))}#b(e){if(this.#c=e,0===this.#c.length)throw new Error("The header must not be empty.");if(new Set(this.#c).size!==this.#c.length)throw new Error("The header must not contain duplicate fields.")}}class f extends TransformStream{constructor(e={}){const t=new l(e);super({transform:(e,r)=>{for(const i of t.assemble(e,!1))r.enqueue(i)},flush:e=>{for(const r of t.flush())e.enqueue(r)}})}}function h(e,t){const r=new a(t),i=new l(t),n=r.lex(e);return[...i.assemble(n)]}function c(e,t){const r=new a(t),i=new l(t),n=r.lex(e);return i.assemble(n)}function d(e,t){const r=new a(t),i=new l(t);return new ReadableStream({start(t){const n=r.lex(e);for(const e of i.assemble(n))t.enqueue(e);t.close()}})}async function b(...e){const t=[];for await(const r of this(...e))t.push(r);return t}async function*m(e,t){yield*c(e,t)}function y(e,t){return new TextDecoder(t?.charset,{ignoreBOM:t?.ignoreBOM,fatal:t?.fatal}).decode(e instanceof ArrayBuffer?new Uint8Array(e):e)}function w(e,t={}){return c(y(e,t),t)}function g(e,t){return function(e){return{async next(){const t=e.next();return Promise.resolve(t)},[Symbol.asyncIterator](){return this}}}(w(e,t))}function p(e,...t){return new ReadableStream({start:r=>{t.reduce(((e,t)=>e.pipeThrough(t)),e).pipeTo(new WritableStream({write:e=>r.enqueue(e),close:()=>r.close()}))}})}function q(e,t){const{charset:r,fatal:i,ignoreBOM:n,decomposition:s}=t??{};return s?p(e,new DecompressionStream(s),new TextDecoderStream(r,{fatal:i,ignoreBOM:n}),new u(t),new f(t)):p(e,new TextDecoderStream(r,{fatal:i,ignoreBOM:n}),new u(t),new f(t))}async function*v(e){const t=e.getReader();for(;;){const{done:e,value:r}=await t.read();if(e)break;yield r}}function x(e,t){return v(q(e,t))}function S(e,t){return p(e,new u(t),new f(t))}function L(e,t){return v(S(e,t))}function A(e,t={}){const{headers:r}=e,i=r.get("content-type")??"text/csv",n=function(e){const[t,...r]=e.split(";"),i={type:t.trim(),parameters:{}};for(const n of r){const[e,t]=n.split("=");i.parameters[e.trim()]=t.trim()}return i}(i);if("text/csv"!==n.type)throw new Error(`Invalid mime type: ${i}`);return{decomposition:r.get("content-encoding")??void 0,charset:n.parameters.charset??"utf-8",...t}}function T(e,t){const r=A(e,t);if(null===e.body)throw new Error("Response body is null");return x(e.body,r)}async function*E(e,t){if("string"==typeof e)yield*m(e,t);else if(e instanceof Uint8Array||e instanceof ArrayBuffer)yield*g(e,t);else if(e instanceof ReadableStream){const[r,i]=e.tee(),n=r.getReader(),{value:s}=await n.read();n.releaseLock(),"string"==typeof s?yield*L(i,t):s instanceof Uint8Array&&(yield*x(i,t))}else e instanceof Response&&(yield*T(e,t))}Object.defineProperties(m,{toArray:{enumerable:!0,writable:!1,value:b},toArraySync:{enumerable:!0,writable:!1,value:h},toIterableIterator:{enumerable:!0,writable:!1,value:c},toStream:{enumerable:!0,writable:!1,value:d}}),Object.defineProperties(g,{toArray:{enumerable:!0,writable:!1,value:b},toArraySync:{enumerable:!0,writable:!1,value:function(e,t={}){return h(y(e,t),t)}},toIterableIterator:{enumerable:!0,writable:!1,value:w},toStream:{enumerable:!0,writable:!1,value:function(e,t={}){return d(y(e,t),t)}}}),Object.defineProperties(x,{toArray:{enumerable:!0,writable:!1,value:b},toStream:{enumerable:!0,writable:!1,value:q}}),Object.defineProperties(L,{toArray:{enumerable:!0,writable:!1,value:b},toStream:{enumerable:!0,writable:!1,value:S}}),Object.defineProperties(T,{toArray:{enumerable:!0,writable:!1,value:b},toStreamSync:{enumerable:!0,writable:!1,value:function(e,t){const r=A(e,t);if(null===e.body)throw new Error("Response body is null");return q(e.body,r)}}}),Object.defineProperties(E,{toArray:{enumerable:!0,writable:!1,value:b}}),e.Field=i,e.FieldDelimiter=t,e.LexerTransformer=u,e.RecordAssemblerTransformer=f,e.RecordDelimiter=r,e.parse=E,e.parseBinary=g,e.parseResponse=T,e.parseString=m,e.parseStringStream=L,e.parseUint8ArrayStream=x,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
2
2
  //# sourceMappingURL=web-csv-toolbox.umd.cjs.map