web-csv-toolbox 0.11.0-next-3e76d727a5e0c4f1fbd537e0a89bed474495294b → 0.11.0-next-0d717debabfdae743295c1993013538ce0a3176e

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 (74) hide show
  1. package/dist/cjs/Lexer.cjs +1 -1
  2. package/dist/cjs/Lexer.cjs.map +1 -1
  3. package/dist/cjs/LexerTransformer.cjs.map +1 -1
  4. package/dist/cjs/_virtual/web_csv_toolbox_wasm_bg.wasm.cjs +1 -1
  5. package/dist/cjs/assertCommonOptions.cjs +1 -1
  6. package/dist/cjs/assertCommonOptions.cjs.map +1 -1
  7. package/dist/cjs/common/errors.cjs +1 -1
  8. package/dist/cjs/common/errors.cjs.map +1 -1
  9. package/dist/cjs/commonParseErrorHandling.cjs +1 -1
  10. package/dist/cjs/commonParseErrorHandling.cjs.map +1 -1
  11. package/dist/cjs/constants.cjs +1 -1
  12. package/dist/cjs/constants.cjs.map +1 -1
  13. package/dist/cjs/parse.cjs.map +1 -1
  14. package/dist/cjs/parseString.cjs.map +1 -1
  15. package/dist/cjs/parseStringStream.cjs.map +1 -1
  16. package/dist/cjs/parseStringStreamToStream.cjs.map +1 -1
  17. package/dist/cjs/parseStringToArraySync.cjs.map +1 -1
  18. package/dist/cjs/parseStringToArraySyncWASM.cjs +1 -1
  19. package/dist/cjs/parseStringToArraySyncWASM.cjs.map +1 -1
  20. package/dist/cjs/parseStringToIterableIterator.cjs.map +1 -1
  21. package/dist/cjs/parseStringToStream.cjs.map +1 -1
  22. package/dist/cjs/web-csv-toolbox.cjs +1 -1
  23. package/dist/es/Lexer.js +7 -6
  24. package/dist/es/Lexer.js.map +1 -1
  25. package/dist/es/LexerTransformer.js.map +1 -1
  26. package/dist/es/_virtual/web_csv_toolbox_wasm_bg.wasm.js +1 -1
  27. package/dist/es/assertCommonOptions.js +4 -5
  28. package/dist/es/assertCommonOptions.js.map +1 -1
  29. package/dist/es/common/errors.js +1 -7
  30. package/dist/es/common/errors.js.map +1 -1
  31. package/dist/es/commonParseErrorHandling.js +2 -2
  32. package/dist/es/commonParseErrorHandling.js.map +1 -1
  33. package/dist/es/constants.js +3 -1
  34. package/dist/es/constants.js.map +1 -1
  35. package/dist/es/parse.js.map +1 -1
  36. package/dist/es/parseString.js.map +1 -1
  37. package/dist/es/parseStringStream.js.map +1 -1
  38. package/dist/es/parseStringStreamToStream.js.map +1 -1
  39. package/dist/es/parseStringToArraySync.js.map +1 -1
  40. package/dist/es/parseStringToArraySyncWASM.js +4 -7
  41. package/dist/es/parseStringToArraySyncWASM.js.map +1 -1
  42. package/dist/es/parseStringToIterableIterator.js.map +1 -1
  43. package/dist/es/parseStringToStream.js.map +1 -1
  44. package/dist/es/web-csv-toolbox.js +1 -1
  45. package/dist/types/Lexer.d.ts +3 -2
  46. package/dist/types/LexerTransformer.d.ts +4 -3
  47. package/dist/types/assertCommonOptions.d.ts +2 -2
  48. package/dist/types/common/errors.d.ts +0 -6
  49. package/dist/types/common/types.d.ts +8 -6
  50. package/dist/types/commonParseErrorHandling.d.ts +2 -1
  51. package/dist/types/constants.d.ts +8 -0
  52. package/dist/types/escapeField.d.ts +2 -2
  53. package/dist/types/parse.d.ts +7 -2
  54. package/dist/types/parse.test-d.d.ts +1 -0
  55. package/dist/types/parseString.d.ts +7 -1
  56. package/dist/types/parseString.test-d.d.ts +1 -0
  57. package/dist/types/parseStringStream.d.ts +5 -1
  58. package/dist/types/parseStringStream.test-d.d.ts +1 -0
  59. package/dist/types/parseStringStreamToStream.d.ts +5 -1
  60. package/dist/types/parseStringStreamToStream.test-d.d.ts +1 -0
  61. package/dist/types/parseStringToArraySync.d.ts +5 -1
  62. package/dist/types/parseStringToArraySync.test-d.d.ts +1 -0
  63. package/dist/types/parseStringToArraySyncWASM.d.ts +6 -1
  64. package/dist/types/parseStringToArraySyncWASM.test-d.d.ts +1 -0
  65. package/dist/types/parseStringToIterableIterator.d.ts +5 -1
  66. package/dist/types/parseStringToIterableIterator.test-d.d.ts +1 -0
  67. package/dist/types/parseStringToStream.d.ts +5 -1
  68. package/dist/types/parseStringToStream.test-d.d.ts +1 -0
  69. package/dist/types/utils/types.d.ts +115 -0
  70. package/dist/types/utils/types.test-d.d.ts +1 -0
  71. package/dist/web-csv-toolbox.umd.cjs +1 -1
  72. package/dist/web-csv-toolbox.umd.cjs.map +1 -1
  73. package/dist/web_csv_toolbox_wasm_bg.wasm +0 -0
  74. package/package.json +1 -1
@@ -0,0 +1,115 @@
1
+ import { DEFAULT_DELIMITER, DEFAULT_QUOTATION, Newline } from '../constants.ts';
2
+ import { CSVString } from '../web-csv-toolbox.ts';
3
+
4
+ /**
5
+ * Generate new string by concatenating all of the elements in array.
6
+ *
7
+ * @category Types
8
+ *
9
+ * @example Default
10
+ *
11
+ * ```ts
12
+ * const header = ["name", "age", "city", "zip"];
13
+ *
14
+ * type _ = Join<typeof header>
15
+ * // `name,age,city,zip`
16
+ * ```
17
+ *
18
+ * @example With different delimiter and quotation
19
+ *
20
+ * ```ts
21
+ * const header = ["name", "a\nge", "city", "zip"];
22
+ *
23
+ * type _ = Join<typeof header, "@", "$">
24
+ * // `name@$a\nge$@city@zip`
25
+ * ```
26
+ */
27
+ 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 : "";
28
+ /**
29
+ * Generate a delimiter-separated tuple from a string.
30
+ *
31
+ * @category Types
32
+ *
33
+ * @example Default
34
+ *
35
+ * ```ts
36
+ * const header = `name,age,city,zip`;
37
+ *
38
+ * type _ = Split<typeof header>
39
+ * // ["name", "age", "city", "zip"]
40
+ * ```
41
+ *
42
+ * @example With different delimiter and quotation
43
+ *
44
+ * ```ts
45
+ * const header = `name@$a
46
+ * ge$@city@zip`;
47
+ *
48
+ * type _ = Split<typeof header, "@", "$">
49
+ * // ["name", "a\nge", "city", "zip"]
50
+ * ```
51
+ */
52
+ 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];
53
+ type ExtractString<Source extends CSVString> = Source extends `${infer S}` | ReadableStream<infer S> ? S : string;
54
+ 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> : "";
55
+ /**
56
+ * Extract a CSV header string from a CSVString.
57
+ *
58
+ * @category Types
59
+ *
60
+ * @example Default
61
+ *
62
+ * ```ts
63
+ * const csv = `name,age
64
+ * Alice,42
65
+ * Bob,69`;
66
+ *
67
+ * type _ = ExtractCSVHeader<typeof csv>
68
+ * // "name,age"
69
+ * ```
70
+ *
71
+ * @example With different delimiter and quotation
72
+ *
73
+ * ```ts
74
+ * const csv = `name@$a
75
+ * ge$
76
+ * $Ali
77
+ * ce$@42
78
+ * Bob@69`;
79
+ *
80
+ * type _ = ExtractCSVHeader<typeof csv, "@", "$">
81
+ * // "name@$a\nge$"
82
+ * ```
83
+ */
84
+ export type ExtractCSVHeader<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 `${infer Header}${Newline}${ExtractCSVBody<CSVSource, Delimiter, Quotation, Nl, Escaping>}` ? Header : ExtractString<CSVSource>;
85
+ /**
86
+ * Generates a delimiter-separated tuple of CSV headers from a CSVString.
87
+ *
88
+ * @category Types
89
+ *
90
+ * @example Default
91
+ *
92
+ * ```ts
93
+ * const csv = `name,age
94
+ * Alice,42
95
+ * Bob,69`;
96
+ *
97
+ * type _ = PickCSVHeader<typeof csv>
98
+ * // ["name", "age"]
99
+ * ```
100
+ *
101
+ * @example With different delimiter and quotation
102
+ *
103
+ * ```ts
104
+ * const csv = `name@$a
105
+ * ge$
106
+ * $Ali
107
+ * ce$@42
108
+ * Bob@69`;
109
+ *
110
+ * type _ = PickCSVHeader<typeof csv, "@", "$">
111
+ * // ["name", "a\nge"]
112
+ * ```
113
+ */
114
+ 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>;
115
+ export {};
@@ -0,0 +1 @@
1
+ export {};