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.
- package/dist/cjs/Lexer.cjs +1 -1
- package/dist/cjs/Lexer.cjs.map +1 -1
- package/dist/cjs/LexerTransformer.cjs.map +1 -1
- package/dist/cjs/_virtual/web_csv_toolbox_wasm_bg.wasm.cjs +1 -1
- package/dist/cjs/assertCommonOptions.cjs +1 -1
- package/dist/cjs/assertCommonOptions.cjs.map +1 -1
- package/dist/cjs/common/errors.cjs +1 -1
- package/dist/cjs/common/errors.cjs.map +1 -1
- package/dist/cjs/commonParseErrorHandling.cjs +1 -1
- package/dist/cjs/commonParseErrorHandling.cjs.map +1 -1
- package/dist/cjs/constants.cjs +1 -1
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/parse.cjs.map +1 -1
- package/dist/cjs/parseString.cjs.map +1 -1
- package/dist/cjs/parseStringStream.cjs.map +1 -1
- package/dist/cjs/parseStringStreamToStream.cjs.map +1 -1
- package/dist/cjs/parseStringToArraySync.cjs.map +1 -1
- package/dist/cjs/parseStringToArraySyncWASM.cjs +1 -1
- package/dist/cjs/parseStringToArraySyncWASM.cjs.map +1 -1
- package/dist/cjs/parseStringToIterableIterator.cjs.map +1 -1
- package/dist/cjs/parseStringToStream.cjs.map +1 -1
- package/dist/cjs/web-csv-toolbox.cjs +1 -1
- package/dist/es/Lexer.js +7 -6
- package/dist/es/Lexer.js.map +1 -1
- package/dist/es/LexerTransformer.js.map +1 -1
- package/dist/es/_virtual/web_csv_toolbox_wasm_bg.wasm.js +1 -1
- package/dist/es/assertCommonOptions.js +4 -5
- package/dist/es/assertCommonOptions.js.map +1 -1
- package/dist/es/common/errors.js +1 -7
- package/dist/es/common/errors.js.map +1 -1
- package/dist/es/commonParseErrorHandling.js +2 -2
- package/dist/es/commonParseErrorHandling.js.map +1 -1
- package/dist/es/constants.js +3 -1
- package/dist/es/constants.js.map +1 -1
- package/dist/es/parse.js.map +1 -1
- package/dist/es/parseString.js.map +1 -1
- package/dist/es/parseStringStream.js.map +1 -1
- package/dist/es/parseStringStreamToStream.js.map +1 -1
- package/dist/es/parseStringToArraySync.js.map +1 -1
- package/dist/es/parseStringToArraySyncWASM.js +4 -7
- package/dist/es/parseStringToArraySyncWASM.js.map +1 -1
- package/dist/es/parseStringToIterableIterator.js.map +1 -1
- package/dist/es/parseStringToStream.js.map +1 -1
- package/dist/es/web-csv-toolbox.js +1 -1
- package/dist/types/Lexer.d.ts +3 -2
- package/dist/types/LexerTransformer.d.ts +4 -3
- package/dist/types/assertCommonOptions.d.ts +2 -2
- package/dist/types/common/errors.d.ts +0 -6
- package/dist/types/common/types.d.ts +8 -6
- package/dist/types/commonParseErrorHandling.d.ts +2 -1
- package/dist/types/constants.d.ts +8 -0
- package/dist/types/escapeField.d.ts +2 -2
- package/dist/types/parse.d.ts +7 -2
- package/dist/types/parse.test-d.d.ts +1 -0
- package/dist/types/parseString.d.ts +7 -1
- package/dist/types/parseString.test-d.d.ts +1 -0
- package/dist/types/parseStringStream.d.ts +5 -1
- package/dist/types/parseStringStream.test-d.d.ts +1 -0
- package/dist/types/parseStringStreamToStream.d.ts +5 -1
- package/dist/types/parseStringStreamToStream.test-d.d.ts +1 -0
- package/dist/types/parseStringToArraySync.d.ts +5 -1
- package/dist/types/parseStringToArraySync.test-d.d.ts +1 -0
- package/dist/types/parseStringToArraySyncWASM.d.ts +6 -1
- package/dist/types/parseStringToArraySyncWASM.test-d.d.ts +1 -0
- package/dist/types/parseStringToIterableIterator.d.ts +5 -1
- package/dist/types/parseStringToIterableIterator.test-d.d.ts +1 -0
- package/dist/types/parseStringToStream.d.ts +5 -1
- package/dist/types/parseStringToStream.test-d.d.ts +1 -0
- package/dist/types/utils/types.d.ts +115 -0
- package/dist/types/utils/types.test-d.d.ts +1 -0
- package/dist/web-csv-toolbox.umd.cjs +1 -1
- package/dist/web-csv-toolbox.umd.cjs.map +1 -1
- package/dist/web_csv_toolbox_wasm_bg.wasm +0 -0
- 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 {};
|