web-csv-toolbox 0.14.0-next-386eebeaafe5857e28c876345c14c9fe5f1a3774 → 0.14.0-next-978b88933762ecc27270ce746b80a3fa7ed8c4f7

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 (80) hide show
  1. package/README.md +28 -48
  2. package/dist/CSVLexer.js +8 -5
  3. package/dist/CSVLexer.js.map +1 -1
  4. package/dist/CSVLexerTransformer.d.ts +10 -12
  5. package/dist/CSVLexerTransformer.js +12 -16
  6. package/dist/CSVLexerTransformer.js.map +1 -1
  7. package/dist/CSVRecordAssembler.js +14 -4
  8. package/dist/CSVRecordAssembler.js.map +1 -1
  9. package/dist/CSVRecordAssemblerTransformer.d.ts +8 -14
  10. package/dist/CSVRecordAssemblerTransformer.js +10 -16
  11. package/dist/CSVRecordAssemblerTransformer.js.map +1 -1
  12. package/dist/assertCommonOptions.d.ts +1 -1
  13. package/dist/assertCommonOptions.js.map +1 -1
  14. package/dist/common/errors.d.ts +32 -0
  15. package/dist/common/errors.js +18 -0
  16. package/dist/common/errors.js.map +1 -1
  17. package/dist/common/types.d.ts +292 -66
  18. package/dist/constants.d.ts +12 -0
  19. package/dist/constants.js +2 -1
  20. package/dist/constants.js.map +1 -1
  21. package/dist/execution/EnginePresets.d.ts +52 -12
  22. package/dist/execution/EnginePresets.js +1 -1
  23. package/dist/execution/EnginePresets.js.map +1 -1
  24. package/dist/execution/InternalEngineConfig.js +40 -18
  25. package/dist/execution/InternalEngineConfig.js.map +1 -1
  26. package/dist/execution/worker/parseBinaryInWorker.node.js +3 -4
  27. package/dist/execution/worker/parseBinaryInWorker.node.js.map +1 -1
  28. package/dist/execution/worker/parseBinaryInWorker.web.js +3 -4
  29. package/dist/execution/worker/parseBinaryInWorker.web.js.map +1 -1
  30. package/dist/execution/worker/parseBinaryInWorkerWASM.node.js +3 -4
  31. package/dist/execution/worker/parseBinaryInWorkerWASM.node.js.map +1 -1
  32. package/dist/execution/worker/parseBinaryInWorkerWASM.web.js +3 -4
  33. package/dist/execution/worker/parseBinaryInWorkerWASM.web.js.map +1 -1
  34. package/dist/execution/worker/parseStreamInWorker.node.js +3 -4
  35. package/dist/execution/worker/parseStreamInWorker.node.js.map +1 -1
  36. package/dist/execution/worker/parseStreamInWorker.web.js +3 -4
  37. package/dist/execution/worker/parseStreamInWorker.web.js.map +1 -1
  38. package/dist/execution/worker/parseStringInWorker.node.js +3 -4
  39. package/dist/execution/worker/parseStringInWorker.node.js.map +1 -1
  40. package/dist/execution/worker/parseStringInWorker.web.js +3 -4
  41. package/dist/execution/worker/parseStringInWorker.web.js.map +1 -1
  42. package/dist/execution/worker/parseStringInWorkerWASM.node.js +3 -4
  43. package/dist/execution/worker/parseStringInWorkerWASM.node.js.map +1 -1
  44. package/dist/execution/worker/parseStringInWorkerWASM.web.js +3 -4
  45. package/dist/execution/worker/parseStringInWorkerWASM.web.js.map +1 -1
  46. package/dist/execution/worker/parseUint8ArrayStreamInWorker.node.js +3 -4
  47. package/dist/execution/worker/parseUint8ArrayStreamInWorker.node.js.map +1 -1
  48. package/dist/execution/worker/parseUint8ArrayStreamInWorker.web.js +3 -4
  49. package/dist/execution/worker/parseUint8ArrayStreamInWorker.web.js.map +1 -1
  50. package/dist/getCharsetValidation.constants.node.d.ts +11 -0
  51. package/dist/getCharsetValidation.constants.node.js +53 -0
  52. package/dist/getCharsetValidation.constants.node.js.map +1 -0
  53. package/dist/getCharsetValidation.constants.web.d.ts +36 -0
  54. package/dist/getCharsetValidation.constants.web.js +53 -0
  55. package/dist/getCharsetValidation.constants.web.js.map +1 -0
  56. package/dist/getOptionsFromFile.d.ts +14 -0
  57. package/dist/getOptionsFromFile.js +12 -0
  58. package/dist/getOptionsFromFile.js.map +1 -0
  59. package/dist/getOptionsFromResponse.js +17 -1
  60. package/dist/getOptionsFromResponse.js.map +1 -1
  61. package/dist/parseBlob.js +9 -1
  62. package/dist/parseBlob.js.map +1 -1
  63. package/dist/parseFile.d.ts +3 -2
  64. package/dist/parseFile.js +7 -3
  65. package/dist/parseFile.js.map +1 -1
  66. package/dist/parseFileToArray.d.ts +27 -0
  67. package/dist/parseFileToArray.js +12 -0
  68. package/dist/parseFileToArray.js.map +1 -0
  69. package/dist/parseFileToStream.d.ts +33 -0
  70. package/dist/parseFileToStream.js +10 -0
  71. package/dist/parseFileToStream.js.map +1 -0
  72. package/dist/utils/convertBinaryToString.js +17 -4
  73. package/dist/utils/convertBinaryToString.js.map +1 -1
  74. package/dist/utils/parseMime.js +3 -1
  75. package/dist/utils/parseMime.js.map +1 -1
  76. package/dist/utils/types.d.ts +21 -10
  77. package/dist/web-csv-toolbox.d.ts +3 -0
  78. package/dist/web-csv-toolbox.js +3 -0
  79. package/dist/web-csv-toolbox.js.map +1 -1
  80. package/package.json +7 -1
@@ -1,16 +1,21 @@
1
+ import { CSVString } from '../common/types.ts';
1
2
  import { DEFAULT_DELIMITER, DEFAULT_QUOTATION, Newline } from '../constants.ts';
2
- import { CSVString } from '../web-csv-toolbox.ts';
3
3
  /**
4
- * Generate new string by concatenating all of the elements in array.
4
+ * Join CSV field array into a CSV-formatted string with proper escaping.
5
5
  *
6
6
  * @category Types
7
7
  *
8
+ * @remarks
9
+ * This type handles CSV-specific formatting:
10
+ * - Quotes fields containing delimiters, quotations, or newlines
11
+ * - Joins fields with the specified delimiter
12
+ *
8
13
  * @example Default
9
14
  *
10
15
  * ```ts
11
16
  * const header = ["name", "age", "city", "zip"];
12
17
  *
13
- * type _ = Join<typeof header>
18
+ * type _ = JoinCSVFields<typeof header>
14
19
  * // `name,age,city,zip`
15
20
  * ```
16
21
  *
@@ -19,22 +24,28 @@ import { CSVString } from '../web-csv-toolbox.ts';
19
24
  * ```ts
20
25
  * const header = ["name", "a\nge", "city", "zip"];
21
26
  *
22
- * type _ = Join<typeof header, "@", "$">
27
+ * type _ = JoinCSVFields<typeof header, "@", "$">
23
28
  * // `name@$a\nge$@city@zip`
24
29
  * ```
25
30
  */
26
- export type Join<Chars extends ReadonlyArray<string | number | boolean | bigint>, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION, Nl extends string = Exclude<Newline, Delimiter | Quotation>> = Chars extends readonly [infer F, ...infer R] ? F extends string ? R extends string[] ? `${F extends `${string}${Nl | Delimiter | Quotation}${string}` ? `${Quotation}${F}${Quotation}` : F}${R extends [] ? "" : Delimiter}${Join<R, Delimiter, Quotation>}` : string : string : "";
31
+ export type JoinCSVFields<Chars extends ReadonlyArray<string | number | boolean | bigint>, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION, Nl extends string = Exclude<Newline, Delimiter | Quotation>> = Chars extends readonly [infer F, ...infer R] ? F extends string ? R extends string[] ? `${F extends `${string}${Nl | Delimiter | Quotation}${string}` ? `${Quotation}${F}${Quotation}` : F}${R extends [] ? "" : Delimiter}${JoinCSVFields<R, Delimiter, Quotation>}` : string : string : "";
27
32
  /**
28
- * Generate a delimiter-separated tuple from a string.
33
+ * Split CSV-formatted string into field array with proper unescaping.
29
34
  *
30
35
  * @category Types
31
36
  *
37
+ * @remarks
38
+ * This type handles CSV-specific parsing:
39
+ * - Unquotes quoted fields
40
+ * - Handles escaped quotation marks
41
+ * - Splits by the specified delimiter
42
+ *
32
43
  * @example Default
33
44
  *
34
45
  * ```ts
35
46
  * const header = `name,age,city,zip`;
36
47
  *
37
- * type _ = Split<typeof header>
48
+ * type _ = SplitCSVFields<typeof header>
38
49
  * // ["name", "age", "city", "zip"]
39
50
  * ```
40
51
  *
@@ -44,11 +55,11 @@ export type Join<Chars extends ReadonlyArray<string | number | boolean | bigint>
44
55
  * const header = `name@$a
45
56
  * ge$@city@zip`;
46
57
  *
47
- * type _ = Split<typeof header, "@", "$">
58
+ * type _ = SplitCSVFields<typeof header, "@", "$">
48
59
  * // ["name", "a\nge", "city", "zip"]
49
60
  * ```
50
61
  */
51
- export type Split<Char extends string, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION, Escaping extends boolean = false, Col extends string = "", Result extends string[] = []> = Char extends `${Delimiter}${infer R}` ? Escaping extends true ? Split<R, Delimiter, Quotation, true, `${Col}${Delimiter}`, Result> : Split<R, Delimiter, Quotation, false, "", [...Result, Col]> : Char extends `${Quotation}${infer R}` ? Escaping extends true ? R extends "" | Delimiter | `${Delimiter}${string}` ? Split<R, Delimiter, Quotation, false, Col, Result> : Split<R, Delimiter, Quotation, true, `${Col}${Quotation}`, Result> : Split<R, Delimiter, Quotation, true, Col, Result> : Char extends `${infer F}${infer R}` ? Split<R, Delimiter, Quotation, Escaping, `${Col}${F}`, Result> : [...Result, Col] extends [""] ? readonly string[] : readonly [...Result, Col];
62
+ export type SplitCSVFields<Char extends string, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION, Escaping extends boolean = false, Col extends string = "", Result extends string[] = []> = Char extends `${Delimiter}${infer R}` ? Escaping extends true ? SplitCSVFields<R, Delimiter, Quotation, true, `${Col}${Delimiter}`, Result> : SplitCSVFields<R, Delimiter, Quotation, false, "", [...Result, Col]> : Char extends `${Quotation}${infer R}` ? Escaping extends true ? R extends "" | Delimiter | `${Delimiter}${string}` ? SplitCSVFields<R, Delimiter, Quotation, false, Col, Result> : SplitCSVFields<R, Delimiter, Quotation, true, `${Col}${Quotation}`, Result> : SplitCSVFields<R, Delimiter, Quotation, true, Col, Result> : Char extends `${infer F}${infer R}` ? SplitCSVFields<R, Delimiter, Quotation, Escaping, `${Col}${F}`, Result> : [...Result, Col] extends [""] ? readonly string[] : readonly [...Result, Col];
52
63
  type ExtractString<Source extends CSVString> = Source extends `${infer S}` | ReadableStream<infer S> ? S : string;
53
64
  type ExtractCSVBody<CSVSource extends CSVString, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION, Nl extends string = Exclude<Newline, Delimiter | Quotation>, Escaping extends boolean = false> = ExtractString<CSVSource> extends `${Quotation}${infer R}` ? Escaping extends true ? R extends Delimiter | Nl | `${Delimiter | Nl}${string}` ? ExtractCSVBody<R, Delimiter, Quotation, Nl, false> : ExtractCSVBody<R, Delimiter, Quotation, Nl, true> : ExtractCSVBody<R, Delimiter, Quotation, Nl, true> : ExtractString<CSVSource> extends `${infer _ extends Nl}${infer R}` ? Escaping extends true ? ExtractCSVBody<R, Delimiter, Quotation, Nl, true> : R : ExtractString<CSVSource> extends `${infer _}${infer R}` ? ExtractCSVBody<R, Delimiter, Quotation, Nl, Escaping> : "";
54
65
  /**
@@ -110,5 +121,5 @@ export type ExtractCSVHeader<CSVSource extends CSVString, Delimiter extends stri
110
121
  * // ["name", "a\nge"]
111
122
  * ```
112
123
  */
113
- export type PickCSVHeader<CSVSource extends CSVString, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION> = ExtractString<CSVSource> extends `${infer S}` ? Split<ExtractCSVHeader<S, Delimiter, Quotation>, Delimiter, Quotation> : ReadonlyArray<string>;
124
+ export type PickCSVHeader<CSVSource extends CSVString, Delimiter extends string = DEFAULT_DELIMITER, Quotation extends string = DEFAULT_QUOTATION> = ExtractString<CSVSource> extends `${infer S}` ? SplitCSVFields<ExtractCSVHeader<S, Delimiter, Quotation>, Delimiter, Quotation> : ReadonlyArray<string>;
114
125
  export {};
@@ -8,6 +8,9 @@ export * from './parse.ts';
8
8
  export * from './parseBinary.ts';
9
9
  export * from './parseBlob.ts';
10
10
  export * from './parseFile.ts';
11
+ export * from './parseFileToArray.ts';
12
+ export * from './parseFileToStream.ts';
13
+ export * from './getOptionsFromFile.ts';
11
14
  export * from './parseRequest.ts';
12
15
  export * from './parseResponse.ts';
13
16
  export * from './parseString.ts';
@@ -7,6 +7,9 @@ export { parse } from './parse.js';
7
7
  export { parseBinary } from './parseBinary.js';
8
8
  export { parseBlob } from './parseBlob.js';
9
9
  export { parseFile } from './parseFile.js';
10
+ export { parseFileToArray } from './parseFileToArray.js';
11
+ export { parseFileToStream } from './parseFileToStream.js';
12
+ export { getOptionsFromFile } from './getOptionsFromFile.js';
10
13
  export { parseRequest } from './parseRequest.js';
11
14
  export { parseResponse } from './parseResponse.js';
12
15
  export { parseString } from './parseString.js';
@@ -1 +1 @@
1
- {"version":3,"file":"web-csv-toolbox.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"web-csv-toolbox.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-csv-toolbox",
3
- "version": "0.14.0-next-386eebeaafe5857e28c876345c14c9fe5f1a3774",
3
+ "version": "0.14.0-next-978b88933762ecc27270ce746b80a3fa7ed8c4f7",
4
4
  "description": "A CSV Toolbox utilizing Web Standard APIs.",
5
5
  "type": "module",
6
6
  "module": "dist/web-csv-toolbox.js",
@@ -56,6 +56,12 @@
56
56
  "browser": "./dist/getOptionsFromResponse.constants.web.js",
57
57
  "default": "./dist/getOptionsFromResponse.constants.web.js"
58
58
  },
59
+ "#getCharsetValidation.constants.js": {
60
+ "types": "./dist/getCharsetValidation.constants.d.ts",
61
+ "node": "./dist/getCharsetValidation.constants.node.js",
62
+ "browser": "./dist/getCharsetValidation.constants.web.js",
63
+ "default": "./dist/getCharsetValidation.constants.web.js"
64
+ },
59
65
  "#execution/worker/parseStringInWorker.js": {
60
66
  "types": "./dist/execution/worker/parseStringInWorker.d.ts",
61
67
  "node": "./dist/execution/worker/parseStringInWorker.node.js",