web-csv-toolbox 0.0.0-next-20240116142901 → 0.0.0-next-20240116163455

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 (167) hide show
  1. package/dist/cjs/Lexer.cjs +2 -0
  2. package/dist/cjs/Lexer.cjs.map +1 -0
  3. package/dist/cjs/LexerTransformer.cjs +2 -0
  4. package/dist/cjs/LexerTransformer.cjs.map +1 -0
  5. package/dist/cjs/RecordAssembler.cjs +2 -0
  6. package/dist/cjs/RecordAssembler.cjs.map +1 -0
  7. package/dist/cjs/RecordAssemblerTransformer.cjs +2 -0
  8. package/dist/cjs/RecordAssemblerTransformer.cjs.map +1 -0
  9. package/dist/cjs/assertCommonOptions.cjs +2 -0
  10. package/dist/cjs/assertCommonOptions.cjs.map +1 -0
  11. package/dist/cjs/common/constants.cjs +2 -0
  12. package/dist/cjs/common/constants.cjs.map +1 -0
  13. package/dist/cjs/constants.cjs +2 -0
  14. package/dist/cjs/constants.cjs.map +1 -0
  15. package/dist/cjs/convertBinaryToString.cjs +2 -0
  16. package/dist/cjs/convertBinaryToString.cjs.map +1 -0
  17. package/dist/cjs/getOptionsFromResponse.cjs +2 -0
  18. package/dist/cjs/getOptionsFromResponse.cjs.map +1 -0
  19. package/dist/cjs/parse.cjs +2 -0
  20. package/dist/cjs/parse.cjs.map +1 -0
  21. package/dist/cjs/parseBinary.cjs +2 -0
  22. package/dist/cjs/parseBinary.cjs.map +1 -0
  23. package/dist/cjs/parseBinaryToArraySync.cjs +2 -0
  24. package/dist/cjs/parseBinaryToArraySync.cjs.map +1 -0
  25. package/dist/cjs/parseBinaryToIterableIterator.cjs +2 -0
  26. package/dist/cjs/parseBinaryToIterableIterator.cjs.map +1 -0
  27. package/dist/cjs/parseBinaryToStream.cjs +2 -0
  28. package/dist/cjs/parseBinaryToStream.cjs.map +1 -0
  29. package/dist/cjs/parseResponse.cjs +2 -0
  30. package/dist/cjs/parseResponse.cjs.map +1 -0
  31. package/dist/cjs/parseResponseToStream.cjs +2 -0
  32. package/dist/cjs/parseResponseToStream.cjs.map +1 -0
  33. package/dist/cjs/parseString.cjs +2 -0
  34. package/dist/cjs/parseString.cjs.map +1 -0
  35. package/dist/cjs/parseStringStream.cjs +2 -0
  36. package/dist/cjs/parseStringStream.cjs.map +1 -0
  37. package/dist/cjs/parseStringStreamToStream.cjs +2 -0
  38. package/dist/cjs/parseStringStreamToStream.cjs.map +1 -0
  39. package/dist/cjs/parseStringToArraySync.cjs +2 -0
  40. package/dist/cjs/parseStringToArraySync.cjs.map +1 -0
  41. package/dist/cjs/parseStringToIterableIterator.cjs +2 -0
  42. package/dist/cjs/parseStringToIterableIterator.cjs.map +1 -0
  43. package/dist/cjs/parseStringToStream.cjs +2 -0
  44. package/dist/cjs/parseStringToStream.cjs.map +1 -0
  45. package/dist/cjs/parseUint8ArrayStream.cjs +2 -0
  46. package/dist/cjs/parseUint8ArrayStream.cjs.map +1 -0
  47. package/dist/cjs/parseUint8ArrayStreamToStream.cjs +2 -0
  48. package/dist/cjs/parseUint8ArrayStreamToStream.cjs.map +1 -0
  49. package/dist/cjs/utils/convertIterableIteratorToAsync.cjs +2 -0
  50. package/dist/cjs/utils/convertIterableIteratorToAsync.cjs.map +1 -0
  51. package/dist/cjs/utils/convertStreamToAsyncIterableIterator.cjs +2 -0
  52. package/dist/cjs/utils/convertStreamToAsyncIterableIterator.cjs.map +1 -0
  53. package/dist/cjs/utils/convertThisAsyncIterableIteratorToArray.cjs +2 -0
  54. package/dist/cjs/utils/convertThisAsyncIterableIteratorToArray.cjs.map +1 -0
  55. package/dist/cjs/utils/escapeRegExp.cjs +2 -0
  56. package/dist/cjs/utils/escapeRegExp.cjs.map +1 -0
  57. package/dist/cjs/utils/parseMime.cjs +2 -0
  58. package/dist/cjs/utils/parseMime.cjs.map +1 -0
  59. package/dist/cjs/utils/pipeline.cjs +2 -0
  60. package/dist/cjs/utils/pipeline.cjs.map +1 -0
  61. package/dist/cjs/web-csv-toolbox.cjs +2 -0
  62. package/dist/cjs/web-csv-toolbox.cjs.map +1 -0
  63. package/dist/es/Lexer.js +151 -0
  64. package/dist/es/Lexer.js.map +1 -0
  65. package/dist/es/LexerTransformer.js +20 -0
  66. package/dist/es/LexerTransformer.js.map +1 -0
  67. package/dist/es/RecordAssembler.js +72 -0
  68. package/dist/es/RecordAssembler.js.map +1 -0
  69. package/dist/es/RecordAssemblerTransformer.js +22 -0
  70. package/dist/es/RecordAssemblerTransformer.js.map +1 -0
  71. package/dist/es/assertCommonOptions.js +24 -0
  72. package/dist/es/assertCommonOptions.js.map +1 -0
  73. package/dist/es/common/constants.js +6 -0
  74. package/dist/es/common/constants.js.map +1 -0
  75. package/dist/es/constants.js +8 -0
  76. package/dist/es/constants.js.map +1 -0
  77. package/dist/es/convertBinaryToString.js +9 -0
  78. package/dist/es/convertBinaryToString.js.map +1 -0
  79. package/dist/es/getOptionsFromResponse.js +20 -0
  80. package/dist/es/getOptionsFromResponse.js.map +1 -0
  81. package/dist/es/parse.js +39 -0
  82. package/dist/es/parse.js.map +1 -0
  83. package/dist/es/parseBinary.js +35 -0
  84. package/dist/es/parseBinary.js.map +1 -0
  85. package/dist/es/parseBinaryToArraySync.js +10 -0
  86. package/dist/es/parseBinaryToArraySync.js.map +1 -0
  87. package/dist/es/parseBinaryToIterableIterator.js +10 -0
  88. package/dist/es/parseBinaryToIterableIterator.js.map +1 -0
  89. package/dist/es/parseBinaryToStream.js +10 -0
  90. package/dist/es/parseBinaryToStream.js.map +1 -0
  91. package/dist/es/parseResponse.js +27 -0
  92. package/dist/es/parseResponse.js.map +1 -0
  93. package/dist/es/parseResponseToStream.js +13 -0
  94. package/dist/es/parseResponseToStream.js.map +1 -0
  95. package/dist/es/parseString.js +33 -0
  96. package/dist/es/parseString.js.map +1 -0
  97. package/dist/es/parseStringStream.js +23 -0
  98. package/dist/es/parseStringStream.js.map +1 -0
  99. package/dist/es/parseStringStreamToStream.js +14 -0
  100. package/dist/es/parseStringStreamToStream.js.map +1 -0
  101. package/dist/es/parseStringToArraySync.js +12 -0
  102. package/dist/es/parseStringToArraySync.js.map +1 -0
  103. package/dist/es/parseStringToIterableIterator.js +12 -0
  104. package/dist/es/parseStringToIterableIterator.js.map +1 -0
  105. package/dist/es/parseStringToStream.js +19 -0
  106. package/dist/es/parseStringToStream.js.map +1 -0
  107. package/dist/es/parseUint8ArrayStream.js +23 -0
  108. package/dist/es/parseUint8ArrayStream.js.map +1 -0
  109. package/dist/es/parseUint8ArrayStreamToStream.js +22 -0
  110. package/dist/es/parseUint8ArrayStreamToStream.js.map +1 -0
  111. package/dist/es/utils/convertIterableIteratorToAsync.js +14 -0
  112. package/dist/es/utils/convertIterableIteratorToAsync.js.map +1 -0
  113. package/dist/es/utils/convertStreamToAsyncIterableIterator.js +12 -0
  114. package/dist/es/utils/convertStreamToAsyncIterableIterator.js.map +1 -0
  115. package/dist/es/utils/convertThisAsyncIterableIteratorToArray.js +10 -0
  116. package/dist/es/utils/convertThisAsyncIterableIteratorToArray.js.map +1 -0
  117. package/dist/es/utils/escapeRegExp.js +6 -0
  118. package/dist/es/utils/escapeRegExp.js.map +1 -0
  119. package/dist/es/utils/parseMime.js +15 -0
  120. package/dist/es/utils/parseMime.js.map +1 -0
  121. package/dist/es/utils/pipeline.js +18 -0
  122. package/dist/es/utils/pipeline.js.map +1 -0
  123. package/dist/es/web-csv-toolbox.js +10 -0
  124. package/dist/es/web-csv-toolbox.js.map +1 -0
  125. package/dist/types/Lexer.d.ts +7 -0
  126. package/dist/types/LexerTransformer.d.ts +34 -0
  127. package/dist/types/RecordAssembler.d.ts +7 -0
  128. package/dist/types/RecordAssemblerTransformer.d.ts +47 -0
  129. package/dist/types/assertCommonOptions.d.ts +7 -0
  130. package/dist/types/common/constants.d.ts +15 -0
  131. package/dist/types/common/types.d.ts +163 -0
  132. package/dist/types/constants.d.ts +11 -0
  133. package/dist/types/convertBinaryToString.d.ts +2 -0
  134. package/dist/types/escapeField.d.ts +13 -0
  135. package/dist/types/getOptionsFromResponse.d.ts +2 -0
  136. package/dist/types/parse.d.ts +182 -0
  137. package/dist/types/parseBinary.d.ts +113 -0
  138. package/dist/types/parseBinaryToArraySync.d.ts +2 -0
  139. package/dist/types/parseBinaryToIterableIterator.d.ts +2 -0
  140. package/dist/types/parseBinaryToStream.d.ts +2 -0
  141. package/dist/types/parseResponse.d.ts +80 -0
  142. package/dist/types/parseResponseToStream.d.ts +2 -0
  143. package/dist/types/parseString.d.ts +120 -0
  144. package/dist/types/parseStringStream.d.ts +98 -0
  145. package/dist/types/parseStringStreamToStream.d.ts +2 -0
  146. package/dist/types/parseStringToArraySync.d.ts +2 -0
  147. package/dist/types/parseStringToIterableIterator.d.ts +2 -0
  148. package/dist/types/parseStringToStream.d.ts +2 -0
  149. package/dist/types/parseUint8ArrayStream.d.ts +94 -0
  150. package/dist/types/parseUint8ArrayStreamToStream.d.ts +2 -0
  151. package/dist/types/utils/SingleValueReadableStream.d.ts +3 -0
  152. package/dist/types/utils/convertIterableIteratorToAsync.d.ts +1 -0
  153. package/dist/types/utils/convertStreamToAsyncIterableIterator.d.ts +1 -0
  154. package/dist/types/utils/convertThisAsyncIterableIteratorToArray.d.ts +1 -0
  155. package/dist/types/utils/escapeRegExp.d.ts +8 -0
  156. package/dist/types/utils/occurrences.d.ts +7 -0
  157. package/dist/types/utils/parseMime.d.ts +7 -0
  158. package/dist/types/utils/pipeline.d.ts +3 -0
  159. package/dist/types/web-csv-toolbox.d.ts +10 -0
  160. package/dist/web-csv-toolbox.umd.cjs +1 -1
  161. package/dist/web-csv-toolbox.umd.cjs.map +1 -1
  162. package/package.json +31 -10
  163. package/dist/web-csv-toolbox.cjs +0 -2
  164. package/dist/web-csv-toolbox.cjs.map +0 -1
  165. package/dist/web-csv-toolbox.d.ts +0 -982
  166. package/dist/web-csv-toolbox.js +0 -576
  167. package/dist/web-csv-toolbox.js.map +0 -1
@@ -0,0 +1,182 @@
1
+ import { CSVBinary, CSVRecord, CSVString, ParseBinaryOptions, ParseOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse CSV to records.
4
+ *
5
+ * {@link !String}, {@link !ReadableStream}<string | {@link !Uint8Array}> and {@link !Response} are supported.
6
+ *
7
+ *
8
+ * @typeParam Header Header type like `['name', 'age']`.
9
+ *
10
+ * @param csv CSV string to parse.
11
+ * @param options Parsing options for CSV string parsing.
12
+ * @returns Async iterable iterator of records.
13
+ *
14
+ * If you want array of records, use {@link parse.toArray} function.
15
+ * @category High-level API
16
+ *
17
+ * @remarks
18
+ * {@link parseString}, {@link parseBinary}, {@link parseUint8ArrayStream},
19
+ * {@link parseStringStream} and {@link parseResponse} are used internally.
20
+ *
21
+ * If you known the type of the CSV, it performs better to use them directly.
22
+ *
23
+ * | If you want to parse a... | Use... | Options... |
24
+ * | -------------------------------------------- | ----------------------------- | -------------------------- |
25
+ * | {@link !String} | {@link parseString} | {@link ParseOptions} |
26
+ * | {@link !ReadableStream}<{@link !String}> | {@link parseStringStream} | {@link ParseOptions} |
27
+ * | {@link !Uint8Array} \| {@link !ArrayBuffer} | {@link parseBinary} | {@link ParseBinaryOptions} |
28
+ * | {@link !ReadableStream}<{@link !Uint8Array}> | {@link parseUint8ArrayStream} | {@link ParseBinaryOptions} |
29
+ * | {@link !Response} | {@link parseResponse} | {@link ParseBinaryOptions} |
30
+ *
31
+ * @example Parsing CSV files from strings
32
+ *
33
+ * ```ts
34
+ * import { parse } from 'web-csv-toolbox';
35
+ *
36
+ * const csv = `name,age
37
+ * Alice,42
38
+ * Bob,69`;
39
+ *
40
+ * for await (const record of parse(csv)) {
41
+ * console.log(record);
42
+ * }
43
+ * // Prints:
44
+ * // { name: 'Alice', age: '42' }
45
+ * // { name: 'Bob', age: '69' }
46
+ * ```
47
+ *
48
+ * @example Parsing CSV files from streams
49
+ *
50
+ * ```ts
51
+ * import { parse } from 'web-csv-toolbox';
52
+ *
53
+ * const csv = `name,age
54
+ * Alice,42
55
+ * Bob,69`;
56
+ *
57
+ * const stream = new ReadableStream({
58
+ * start(controller) {
59
+ * controller.enqueue(csv);
60
+ * controller.close();
61
+ * }
62
+ * });
63
+ *
64
+ * for await (const record of parse(stream)) {
65
+ * console.log(record);
66
+ * }
67
+ * // Prints:
68
+ * // { name: 'Alice', age: '42' }
69
+ * // { name: 'Bob', age: '69' }
70
+ * ```
71
+ *
72
+ *
73
+ * @example Parsing CSV files with headers
74
+ *
75
+ * ```ts
76
+ * import { parse } from 'web-csv-toolbox';
77
+ *
78
+ * // This CSV has no header.
79
+ * const csv = `Alice,42
80
+ * Bob,69`;
81
+ *
82
+ * for await (const record of parse(csv, { header: ['name', 'age'] })) {
83
+ * console.log(record);
84
+ * }
85
+ * // Prints:
86
+ * // { name: 'Alice', age: '42' }
87
+ * // { name: 'Bob', age: '69' }
88
+ * ```
89
+ *
90
+ * @example Parsing CSV files with different delimiters characters
91
+ *
92
+ * ```ts
93
+ * import { parse } from 'web-csv-toolbox';
94
+ *
95
+ * const csv = `name\tage
96
+ * Alice\t42
97
+ * Bob\t69`;
98
+ *
99
+ * for await (const record of parse(csv, { delimiter: '\t' })) {
100
+ * console.log(record);
101
+ * }
102
+ * // Prints:
103
+ * // { name: 'Alice', age: '42' }
104
+ * // { name: 'Bob', age: '69' }
105
+ * ```
106
+ */
107
+ export declare function parse<Header extends ReadonlyArray<string>>(csv: CSVString, options?: ParseOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
108
+ /**
109
+ * Parse CSV binary to records.
110
+ *
111
+ * @param csv CSV binary to parse.
112
+ * @param options Parsing options for CSV binary parsing.
113
+ *
114
+ * @example Parsing CSV files from responses
115
+ *
116
+ * ```ts
117
+ * import { parse } from 'web-csv-toolbox';
118
+ *
119
+ * // This CSV data is not gzipped and encoded in utf-8.
120
+ * const response = await fetch('https://example.com/data.csv');
121
+ *
122
+ * for await (const record of parse(response)) {
123
+ * // ...
124
+ * }
125
+ * ```
126
+ *
127
+ * @example Parsing CSV files with options spcialized for binary
128
+ *
129
+ * ```ts
130
+ * import { parse } from 'web-csv-toolbox';
131
+ *
132
+ * // This CSV data is gzipped and encoded in shift-jis and has BOM.
133
+ * const response = await fetch('https://example.com/data.csv.gz');
134
+ *
135
+ * for await (const record of parse(response, {
136
+ * charset: 'shift-jis',
137
+ * ignoreBOM: true,
138
+ * decomposition: 'gzip',
139
+ * })) {
140
+ * // ...
141
+ * }
142
+ * ```
143
+ */
144
+ export declare function parse<Header extends ReadonlyArray<string>>(csv: CSVBinary, options?: ParseBinaryOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
145
+ export declare namespace parse {
146
+ /**
147
+ * Parse CSV string to array of records,
148
+ * ideal for smaller data sets.
149
+ *
150
+ * @example Parse a CSV as array of records
151
+ *
152
+ * ```ts
153
+ * import { parse } from 'web-csv-toolbox';
154
+ *
155
+ * const csv = `name,age
156
+ * Alice,42
157
+ * Bob,69`;
158
+ *
159
+ * const records = await parse.toArray(csv);
160
+ * console.log(records);
161
+ * // Prints:
162
+ * // [ { name: 'Alice', age: '42' }, { name: 'Bob', age: '69' } ]
163
+ * ```
164
+ */
165
+ function toArray<Header extends ReadonlyArray<string>>(csv: CSVString, options?: ParseOptions<Header>): Promise<CSVRecord<Header>[]>;
166
+ /**
167
+ * Parse CSV string to array of records,
168
+ * ideal for smaller data sets.
169
+ *
170
+ * @example Parse a CSV as array of records
171
+ *
172
+ * ```ts
173
+ * import { parse } from 'web-csv-toolbox';
174
+ *
175
+ * const response = await fetch('https://example.com/data.csv');
176
+ *
177
+ * const records = await parse.toArray(response);
178
+ * console.log(records);
179
+ * ```
180
+ */
181
+ function toArray<Header extends ReadonlyArray<string>>(csv: CSVBinary, options?: ParseBinaryOptions<Header>): Promise<CSVRecord<Header>[]>;
182
+ }
@@ -0,0 +1,113 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse a binary from an {@link !Uint8Array}.
4
+ *
5
+ * @category Middle-level API
6
+ *
7
+ * @param bytes CSV bytes to parse.
8
+ * @param options Parsing options
9
+ * @returns Async iterable iterator of records.
10
+ *
11
+ * @example Parsing CSV binary
12
+ *
13
+ * ```ts
14
+ * import { parseUint8Array } from 'web-csv-toolbox';
15
+ *
16
+ * const csv = Uint8Array.from([
17
+ * // ...
18
+ * ]);
19
+ *
20
+ * for await (const record of parseUint8Array(csv)) {
21
+ * console.log(record);
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function parseBinary<Header extends ReadonlyArray<string>>(bytes: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
26
+ export declare namespace parseBinary {
27
+ /**
28
+ * Parse a binary from an {@link !Uint8Array} to an array of records.
29
+ *
30
+ * @param bytes CSV bytes to parse.
31
+ * @param options Parsing options
32
+ * @returns Array of records
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { parseUint8Array } from 'web-csv-toolbox';
37
+ *
38
+ * const csv = Uint8Array.from([
39
+ * // ...
40
+ * ]);
41
+ *
42
+ * const records = await parseUint8Array.toArray(csv);
43
+ * ```
44
+ */
45
+ function toArray<Header extends ReadonlyArray<string>>(bytes: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): Promise<CSVRecord<Header>[]>;
46
+ /**
47
+ * Parse a binary from an {@link !Uint8Array} to an array of records.
48
+ *
49
+ * @param bytes CSV bytes to parse.
50
+ * @param options Parsing options
51
+ * @returns Array of records
52
+ * @example
53
+ *
54
+ * ```ts
55
+ * import { parseUint8Array } from 'web-csv-toolbox';
56
+ *
57
+ * const csv = Uint8Array.from([
58
+ * // ...
59
+ * ]);
60
+ *
61
+ * const records = parseUint8Array.toArraySync(csv);
62
+ * ```
63
+ */
64
+ function toArraySync<Header extends ReadonlyArray<string>>(bytes: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): CSVRecord<Header>[];
65
+ /**
66
+ * Parse a binary from an {@link !Uint8Array} to an iterable iterator of records.
67
+ *
68
+ * @param bytes CSV bytes to parse.
69
+ * @param options Parsing options
70
+ * @returns Async iterable iterator of records.
71
+ * @example
72
+ * ```ts
73
+ * import { parseUint8Array } from 'web-csv-toolbox';
74
+ *
75
+ * const csv = Uint8Array.from([
76
+ * // ...
77
+ * ]);
78
+ *
79
+ * for (const record of parseUint8Array.toIterableIterator(csv)) {
80
+ * console.log(record);
81
+ * }
82
+ * ```
83
+ */
84
+ function toIterableIterator<Header extends ReadonlyArray<string>>(bytes: Uint8Array, options?: ParseBinaryOptions<Header>): IterableIterator<CSVRecord<Header>>;
85
+ /**
86
+ * Parse a binary from an {@link !Uint8Array} to a stream of records.
87
+ *
88
+ * @param bytes CSV bytes to parse.
89
+ * @param options Parsing options
90
+ * @returns Stream of records.
91
+ *
92
+ * @example
93
+ *
94
+ * ```ts
95
+ * import { parseUint8Array } from 'web-csv-toolbox';
96
+ *
97
+ * const csv = Uint8Array.from([
98
+ * // ...
99
+ * ]);
100
+ *
101
+ * const stream = parseUint8Array.toStream(csv);
102
+ *
103
+ * await stream.pipeTo(
104
+ * new WritableStream({
105
+ * write(record) {
106
+ * console.log(record);
107
+ * },
108
+ * }),
109
+ * );
110
+ * ```
111
+ */
112
+ function toStream<Header extends ReadonlyArray<string>>(bytes: Uint8Array, options?: ParseBinaryOptions<Header>): ReadableStream<CSVRecord<Header>>;
113
+ }
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ export declare function parseBinaryToArraySync<Header extends ReadonlyArray<string>>(binary: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): CSVRecord<Header>[];
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ export declare function parseBinaryToIterableIterator<Header extends ReadonlyArray<string>>(binary: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): IterableIterator<CSVRecord<Header>>;
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ export declare function parseBinaryToStream<Header extends ReadonlyArray<string>>(binary: Uint8Array | ArrayBuffer, options?: ParseBinaryOptions<Header>): ReadableStream<CSVRecord<Header>>;
@@ -0,0 +1,80 @@
1
+ import { CSVRecord, ParseOptions } from "./common/types.ts";
2
+ /**
3
+ * Parse HTTP Response what contains CSV to records,
4
+ * ideal for smaller data sets.
5
+ *
6
+ * @remarks
7
+ * This function automatically treats response headers.
8
+ *
9
+ * - If `Content-Type` header is not set, it assumes `text/csv`.
10
+ * - If `Content-Type` header is not `text/csv`, it throws an error.
11
+ * - If `Content-Type` header has charset parameter, it uses it for decoding.
12
+ * - If `Content-Encoding` header is set, it decompresses the response.
13
+ * - Should there be any conflicting information between the header and the options, the option's value will take precedence.
14
+ *
15
+ * @category Middle-level API
16
+ * @param response
17
+ * @param options
18
+ * @returns Async iterable iterator of records.
19
+ *
20
+ * If you want array of records, use {@link parseResponse.toArray} function.
21
+ *
22
+ * @example Parsing CSV Response
23
+ *
24
+ * ```ts
25
+ * import { parseResponse } from 'web-csv-toolbox';
26
+ *
27
+ * const response = await fetch('https://example.com/data.csv');
28
+ *
29
+ * for await (const record of parseResponse(response)) {
30
+ * console.log(record);
31
+ * }
32
+ * ```
33
+ */
34
+ export declare function parseResponse<Header extends ReadonlyArray<string>>(response: Response, options?: ParseOptions<Header>): AsyncIterableIterator<CSVRecord<Header>>;
35
+ export declare namespace parseResponse {
36
+ /**
37
+ * Parse CSV Response to array of records.
38
+ *
39
+ * @returns Array of records
40
+ *
41
+ * @example Parsing CSV Response
42
+ *
43
+ * ```ts
44
+ * import { parseResponse } from 'web-csv-toolbox';
45
+ *
46
+ * const response = await fetch('https://example.com/data.csv');
47
+ *
48
+ * const records = await parseResponse.toArray(response);
49
+ * console.log(records);
50
+ * ```
51
+ */
52
+ function toArray<Header extends ReadonlyArray<string>>(response: Response, options?: ParseOptions<Header>): Promise<CSVRecord<Header>[]>;
53
+ /**
54
+ * Parse CSV Response to stream of records.
55
+ *
56
+ * @param response Response to parse
57
+ * @returns Stream of records
58
+ *
59
+ * @example Parsing CSV Response
60
+ *
61
+ * ```ts
62
+ * import { parseResponse } from 'web-csv-toolbox';
63
+ *
64
+ * const response = await fetch('https://example.com/data.csv');
65
+ *
66
+ * await parseResponse.toStream(response)
67
+ * .pipeTo(
68
+ * new WritableStream({
69
+ * write(record) {
70
+ * console.log(record);
71
+ * },
72
+ * }),
73
+ * );
74
+ * // Prints:
75
+ * // { name: 'Alice', age: '42' }
76
+ * // { name: 'Bob', age: '69' }
77
+ * ```
78
+ */
79
+ function toStream<Header extends ReadonlyArray<string>>(response: Response, options?: ParseOptions<Header>): ReadableStream<CSVRecord<Header>[]>;
80
+ }
@@ -0,0 +1,2 @@
1
+ import { CSVRecord, ParseBinaryOptions } from "./common/types.ts";
2
+ export declare function parseResponseToStream<Header extends ReadonlyArray<string>>(response: Response, options?: ParseBinaryOptions<Header>): ReadableStream<CSVRecord<Header>>;
@@ -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>>;