@konstit/csv 0.4.3 → 0.5.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.
- package/README.md +42 -26
- package/THIRD_PARTY_NOTICES.md +7 -1
- package/dist/api.d.ts +39 -249
- package/dist/api.js +40 -304
- package/dist/batches.d.ts +5 -53
- package/dist/batches.js +66 -43
- package/dist/cli-command.d.ts +7 -0
- package/dist/cli-command.js +350 -0
- package/dist/cli-schema.d.ts +111 -0
- package/dist/cli-schema.js +219 -0
- package/dist/cli.js +2 -604
- package/dist/file-stream.d.ts +57 -2
- package/dist/file-stream.js +241 -36
- package/dist/files.d.ts +11 -11
- package/dist/files.js +11 -9
- package/dist/filter.d.ts +4 -6
- package/dist/format-bytes.d.ts +1 -0
- package/dist/format-bytes.js +11 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -14
- package/dist/inspect-file.d.ts +12 -0
- package/dist/inspect-file.js +88 -0
- package/dist/latin1-rows.d.ts +3 -1
- package/dist/latin1-rows.js +61 -23
- package/dist/materialize-field.d.ts +2 -0
- package/dist/materialize-field.js +20 -15
- package/dist/native.d.ts +29 -9
- package/dist/native.js +27 -29
- package/dist/normalize.d.ts +15 -2
- package/dist/normalize.js +41 -2
- package/dist/options-snapshot.js +3 -2
- package/dist/options.d.ts +4 -30
- package/dist/options.js +0 -6
- package/dist/parser.d.ts +14 -15
- package/dist/parser.js +38 -54
- package/dist/strict-schema.d.ts +5 -3
- package/dist/types.d.ts +88 -222
- package/dist/zip-reader.d.ts +11 -1
- package/dist/zip-reader.js +12 -3
- package/package.json +34 -32
- package/prebuilds/darwin-arm64/libcsv_native.dylib +0 -0
- package/prebuilds/darwin-x64/libcsv_native.dylib +0 -0
- package/prebuilds/linux-x64/libcsv_native.so +0 -0
- package/prebuilds/manifest.json +9 -8
- package/prebuilds/provenance/darwin-arm64.json +1 -1
- package/prebuilds/provenance/darwin-x64.json +1 -1
- package/prebuilds/provenance/linux-x64.json +1 -1
- package/dist/worker-count.d.ts +0 -34
- package/dist/worker-count.js +0 -101
- package/dist/worker-factory.d.ts +0 -3
- package/dist/worker-factory.js +0 -9
- package/dist/worker-filter.d.ts +0 -29
- package/dist/worker-filter.js +0 -46
- package/dist/worker-module.d.ts +0 -1
- package/dist/worker-module.js +0 -4
- package/dist/worker-pool.d.ts +0 -93
- package/dist/worker-pool.js +0 -298
- package/dist/worker-rows.d.ts +0 -36
- package/dist/worker-rows.js +0 -127
- package/dist/workers/count.worker.d.ts +0 -1
- package/dist/workers/count.worker.js +0 -36
- package/dist/workers/rows.worker.d.ts +0 -1
- package/dist/workers/rows.worker.js +0 -56
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type Infer } from '@konstit/cli';
|
|
2
|
+
declare const count: import("@konstit/cli").HandledCommand<"count", {
|
|
3
|
+
path: string;
|
|
4
|
+
"zip-entry": string | undefined;
|
|
5
|
+
delimiter: string | undefined;
|
|
6
|
+
encoding: "utf8" | "utf-16le" | "latin1" | "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic" | "gbk" | "gb18030" | "big5" | "euc-jp" | "iso-2022-jp" | "shift_jis" | "euc-kr" | "utf-16be" | "x-user-defined" | "auto" | undefined;
|
|
7
|
+
compression: "auto" | "zip" | "gzip" | "deflate" | "deflate-raw" | "brotli" | "zstd" | "none" | undefined;
|
|
8
|
+
"chunk-size": number | undefined;
|
|
9
|
+
"max-compression-ratio": number | undefined;
|
|
10
|
+
"max-decompressed-bytes": number | undefined;
|
|
11
|
+
strict: boolean;
|
|
12
|
+
"fixed-columns": number | undefined;
|
|
13
|
+
columns: string | undefined;
|
|
14
|
+
"expected-header": readonly string[];
|
|
15
|
+
"require-header": boolean;
|
|
16
|
+
"min-data-rows": number | undefined;
|
|
17
|
+
where: unknown;
|
|
18
|
+
"where-eq": readonly import("@konstit/cli").KeyValuePair[];
|
|
19
|
+
"where-neq": readonly import("@konstit/cli").KeyValuePair[];
|
|
20
|
+
"where-in": readonly import("@konstit/cli").KeyValuePair[];
|
|
21
|
+
"where-noin": readonly import("@konstit/cli").KeyValuePair[];
|
|
22
|
+
"where-prefix": readonly import("@konstit/cli").KeyValuePair[];
|
|
23
|
+
"where-regex": readonly import("@konstit/cli").KeyValuePair[];
|
|
24
|
+
}, {}, false, "filters" | "zip-limits" | "schema">;
|
|
25
|
+
declare const lines: import("@konstit/cli").HandledCommand<"lines", {
|
|
26
|
+
path: string;
|
|
27
|
+
"zip-entry": string | undefined;
|
|
28
|
+
delimiter: string | undefined;
|
|
29
|
+
encoding: "utf8" | "utf-16le" | "latin1" | "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic" | "gbk" | "gb18030" | "big5" | "euc-jp" | "iso-2022-jp" | "shift_jis" | "euc-kr" | "utf-16be" | "x-user-defined" | "auto" | undefined;
|
|
30
|
+
compression: "auto" | "zip" | "gzip" | "deflate" | "deflate-raw" | "brotli" | "zstd" | "none" | undefined;
|
|
31
|
+
"chunk-size": number | undefined;
|
|
32
|
+
"max-compression-ratio": number | undefined;
|
|
33
|
+
"max-decompressed-bytes": number | undefined;
|
|
34
|
+
strict: boolean;
|
|
35
|
+
"fixed-columns": number | undefined;
|
|
36
|
+
columns: string | undefined;
|
|
37
|
+
"expected-header": readonly string[];
|
|
38
|
+
"require-header": boolean;
|
|
39
|
+
"min-data-rows": number | undefined;
|
|
40
|
+
where: unknown;
|
|
41
|
+
"where-eq": readonly import("@konstit/cli").KeyValuePair[];
|
|
42
|
+
"where-neq": readonly import("@konstit/cli").KeyValuePair[];
|
|
43
|
+
"where-in": readonly import("@konstit/cli").KeyValuePair[];
|
|
44
|
+
"where-noin": readonly import("@konstit/cli").KeyValuePair[];
|
|
45
|
+
"where-prefix": readonly import("@konstit/cli").KeyValuePair[];
|
|
46
|
+
"where-regex": readonly import("@konstit/cli").KeyValuePair[];
|
|
47
|
+
json: boolean;
|
|
48
|
+
"output-delimiter": string;
|
|
49
|
+
limit: number | undefined;
|
|
50
|
+
}, {}, false, "filters" | "zip-limits" | "schema">;
|
|
51
|
+
export type CountArguments = Infer<typeof count>;
|
|
52
|
+
export type LinesArguments = Infer<typeof lines>;
|
|
53
|
+
export declare const csvCommand: import("@konstit/cli").HandledCommand<"csv", {}, {
|
|
54
|
+
count: import("@konstit/cli").HandledCommand<"count", {
|
|
55
|
+
path: string;
|
|
56
|
+
"zip-entry": string | undefined;
|
|
57
|
+
delimiter: string | undefined;
|
|
58
|
+
encoding: "utf8" | "utf-16le" | "latin1" | "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic" | "gbk" | "gb18030" | "big5" | "euc-jp" | "iso-2022-jp" | "shift_jis" | "euc-kr" | "utf-16be" | "x-user-defined" | "auto" | undefined;
|
|
59
|
+
compression: "auto" | "zip" | "gzip" | "deflate" | "deflate-raw" | "brotli" | "zstd" | "none" | undefined;
|
|
60
|
+
"chunk-size": number | undefined;
|
|
61
|
+
"max-compression-ratio": number | undefined;
|
|
62
|
+
"max-decompressed-bytes": number | undefined;
|
|
63
|
+
strict: boolean;
|
|
64
|
+
"fixed-columns": number | undefined;
|
|
65
|
+
columns: string | undefined;
|
|
66
|
+
"expected-header": readonly string[];
|
|
67
|
+
"require-header": boolean;
|
|
68
|
+
"min-data-rows": number | undefined;
|
|
69
|
+
where: unknown;
|
|
70
|
+
"where-eq": readonly import("@konstit/cli").KeyValuePair[];
|
|
71
|
+
"where-neq": readonly import("@konstit/cli").KeyValuePair[];
|
|
72
|
+
"where-in": readonly import("@konstit/cli").KeyValuePair[];
|
|
73
|
+
"where-noin": readonly import("@konstit/cli").KeyValuePair[];
|
|
74
|
+
"where-prefix": readonly import("@konstit/cli").KeyValuePair[];
|
|
75
|
+
"where-regex": readonly import("@konstit/cli").KeyValuePair[];
|
|
76
|
+
}, {}, false, "filters" | "zip-limits" | "schema">;
|
|
77
|
+
lines: import("@konstit/cli").HandledCommand<"lines", {
|
|
78
|
+
path: string;
|
|
79
|
+
"zip-entry": string | undefined;
|
|
80
|
+
delimiter: string | undefined;
|
|
81
|
+
encoding: "utf8" | "utf-16le" | "latin1" | "ibm866" | "iso-8859-2" | "iso-8859-3" | "iso-8859-4" | "iso-8859-5" | "iso-8859-6" | "iso-8859-7" | "iso-8859-8" | "iso-8859-8-i" | "iso-8859-10" | "iso-8859-13" | "iso-8859-14" | "iso-8859-15" | "iso-8859-16" | "koi8-r" | "koi8-u" | "macintosh" | "windows-874" | "windows-1250" | "windows-1251" | "windows-1252" | "windows-1253" | "windows-1254" | "windows-1255" | "windows-1256" | "windows-1257" | "windows-1258" | "x-mac-cyrillic" | "gbk" | "gb18030" | "big5" | "euc-jp" | "iso-2022-jp" | "shift_jis" | "euc-kr" | "utf-16be" | "x-user-defined" | "auto" | undefined;
|
|
82
|
+
compression: "auto" | "zip" | "gzip" | "deflate" | "deflate-raw" | "brotli" | "zstd" | "none" | undefined;
|
|
83
|
+
"chunk-size": number | undefined;
|
|
84
|
+
"max-compression-ratio": number | undefined;
|
|
85
|
+
"max-decompressed-bytes": number | undefined;
|
|
86
|
+
strict: boolean;
|
|
87
|
+
"fixed-columns": number | undefined;
|
|
88
|
+
columns: string | undefined;
|
|
89
|
+
"expected-header": readonly string[];
|
|
90
|
+
"require-header": boolean;
|
|
91
|
+
"min-data-rows": number | undefined;
|
|
92
|
+
where: unknown;
|
|
93
|
+
"where-eq": readonly import("@konstit/cli").KeyValuePair[];
|
|
94
|
+
"where-neq": readonly import("@konstit/cli").KeyValuePair[];
|
|
95
|
+
"where-in": readonly import("@konstit/cli").KeyValuePair[];
|
|
96
|
+
"where-noin": readonly import("@konstit/cli").KeyValuePair[];
|
|
97
|
+
"where-prefix": readonly import("@konstit/cli").KeyValuePair[];
|
|
98
|
+
"where-regex": readonly import("@konstit/cli").KeyValuePair[];
|
|
99
|
+
json: boolean;
|
|
100
|
+
"output-delimiter": string;
|
|
101
|
+
limit: number | undefined;
|
|
102
|
+
}, {}, false, "filters" | "zip-limits" | "schema">;
|
|
103
|
+
probe: import("@konstit/cli").HandledCommand<"probe", {
|
|
104
|
+
path: string;
|
|
105
|
+
"zip-entry": string | undefined;
|
|
106
|
+
}, {}, boolean, string>;
|
|
107
|
+
completion: import("@konstit/cli").HandledCommand<"completion", {
|
|
108
|
+
shell: "bash" | "zsh" | "fish" | "powershell";
|
|
109
|
+
}, {}, boolean, string>;
|
|
110
|
+
}, true, string>;
|
|
111
|
+
export {};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
command,
|
|
3
|
+
completionShells,
|
|
4
|
+
flag,
|
|
5
|
+
option,
|
|
6
|
+
parsers,
|
|
7
|
+
positional
|
|
8
|
+
} from "@konstit/cli";
|
|
9
|
+
import packageInfo from "../package.json";
|
|
10
|
+
import { resolveInputEncoding } from "./normalize.js";
|
|
11
|
+
const encodings = parsers.enum([
|
|
12
|
+
"auto",
|
|
13
|
+
{ value: "utf8", aliases: ["utf-8"] },
|
|
14
|
+
{ value: "latin1", aliases: ["iso88591", "iso-8859-1"] },
|
|
15
|
+
"utf-16le",
|
|
16
|
+
"utf-16be",
|
|
17
|
+
"windows-874",
|
|
18
|
+
"windows-1250",
|
|
19
|
+
"windows-1251",
|
|
20
|
+
{ value: "windows-1252", aliases: ["cp1252"] },
|
|
21
|
+
"windows-1253",
|
|
22
|
+
"windows-1254",
|
|
23
|
+
"windows-1255",
|
|
24
|
+
"windows-1256",
|
|
25
|
+
"windows-1257",
|
|
26
|
+
"windows-1258",
|
|
27
|
+
"iso-8859-2",
|
|
28
|
+
"iso-8859-3",
|
|
29
|
+
"iso-8859-4",
|
|
30
|
+
"iso-8859-5",
|
|
31
|
+
"iso-8859-6",
|
|
32
|
+
"iso-8859-7",
|
|
33
|
+
"iso-8859-8",
|
|
34
|
+
"iso-8859-8-i",
|
|
35
|
+
"iso-8859-10",
|
|
36
|
+
"iso-8859-13",
|
|
37
|
+
"iso-8859-14",
|
|
38
|
+
"iso-8859-15",
|
|
39
|
+
"iso-8859-16",
|
|
40
|
+
"big5",
|
|
41
|
+
"euc-jp",
|
|
42
|
+
"euc-kr",
|
|
43
|
+
"gb18030",
|
|
44
|
+
"gbk",
|
|
45
|
+
"ibm866",
|
|
46
|
+
"iso-2022-jp",
|
|
47
|
+
"koi8-r",
|
|
48
|
+
"koi8-u",
|
|
49
|
+
"macintosh",
|
|
50
|
+
{ value: "shift_jis", aliases: ["sjis"] },
|
|
51
|
+
"x-mac-cyrillic",
|
|
52
|
+
"x-user-defined"
|
|
53
|
+
]);
|
|
54
|
+
const encodingParser = {
|
|
55
|
+
...encodings,
|
|
56
|
+
parse(label) {
|
|
57
|
+
try {
|
|
58
|
+
return encodings.parse(label);
|
|
59
|
+
} catch {
|
|
60
|
+
const encoding = resolveInputEncoding(label);
|
|
61
|
+
return encodings.parse(typeof encoding === "string" ? encoding : encoding.encoding);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const compressionFormats = ["auto", "none", "gzip", "deflate", "deflate-raw", "brotli", "zstd", "zip"];
|
|
66
|
+
const positiveUint32 = parsers.range(1, 4294967295, { integer: !0 });
|
|
67
|
+
const byteSize = parsers.custom(parsers.byteSize.label, (input) => {
|
|
68
|
+
const bare = Number(input);
|
|
69
|
+
return parsers.byteSize.parse(Number.isNaN(bare) ? input : `${bare}B`);
|
|
70
|
+
});
|
|
71
|
+
const positiveByteSize = parsers.refine(byteSize, (bytes) => bytes > 0, "expected at least 1 byte");
|
|
72
|
+
const chunkSize = parsers.refine(positiveByteSize, (bytes) => bytes <= 67108864, "expected at most 64 MiB");
|
|
73
|
+
const inputDelimiter = parsers.regex(/^(?:auto|[\p{ASCII}--["\r\n]])$/v);
|
|
74
|
+
const outputDelimiter = parsers.regex(/^[\p{ASCII}--["\r\n]]$/v);
|
|
75
|
+
const path = positional("path", parsers.string, { required: !0, valueHint: "file", describe: "Input file path" });
|
|
76
|
+
const zipEntry = option("zip-entry", parsers.refine(parsers.string, (value) => value.length > 0, "expected a non-empty ZIP entry name"), {
|
|
77
|
+
valueName: "PATH",
|
|
78
|
+
describe: "Select an entry inside a ZIP archive"
|
|
79
|
+
});
|
|
80
|
+
const fileArgs = [
|
|
81
|
+
path,
|
|
82
|
+
option("delimiter", inputDelimiter, { valueName: "CHAR|auto", describe: "One safe ASCII character or auto (default: auto)" }),
|
|
83
|
+
option("encoding", encodingParser, {
|
|
84
|
+
valueName: "ENCODING",
|
|
85
|
+
describe: "Input encoding or decoder alias (default: auto)"
|
|
86
|
+
}),
|
|
87
|
+
option("compression", parsers.enum(compressionFormats), {
|
|
88
|
+
valueName: "FORMAT",
|
|
89
|
+
describe: `Input compression (default: auto). Choices: ${compressionFormats.join(", ")}`
|
|
90
|
+
}),
|
|
91
|
+
option("chunk-size", chunkSize, {
|
|
92
|
+
describe: "Read 1 B through 64 MiB per chunk (default: 1MiB). Example: 256KiB"
|
|
93
|
+
}),
|
|
94
|
+
zipEntry,
|
|
95
|
+
option("max-compression-ratio", positiveUint32, {
|
|
96
|
+
valueName: "RATIO",
|
|
97
|
+
describe: "Maximum ZIP expansion ratio, an integer from 1 through 4294967295"
|
|
98
|
+
}),
|
|
99
|
+
option("max-decompressed-bytes", positiveByteSize, { describe: "Maximum decompressed ZIP size (default: 64GiB)" }),
|
|
100
|
+
flag("strict", { describe: "Enable strict RFC 4180 validation" }),
|
|
101
|
+
option("fixed-columns", positiveUint32, { valueName: "COUNT", describe: "Require this positive field count in strict mode" }),
|
|
102
|
+
option("columns", parsers.string, {
|
|
103
|
+
valueName: "INDEXES",
|
|
104
|
+
describe: "Zero-based column indexes in output order. The count command validates the indexes only"
|
|
105
|
+
}),
|
|
106
|
+
option("expected-header", parsers.string, { repeatable: !0, describe: "Expected header value. Repeat once per column in strict mode" }),
|
|
107
|
+
flag("require-header", { describe: "Require a header row in strict mode" }),
|
|
108
|
+
option("min-data-rows", parsers.range(0, Number.MAX_SAFE_INTEGER, { integer: !0 }), {
|
|
109
|
+
valueName: "COUNT",
|
|
110
|
+
describe: "Require at least this many data rows in strict mode"
|
|
111
|
+
}),
|
|
112
|
+
option("where", parsers.json(), { valueName: "JSON", describe: "Advanced JSON can nest all, any, and not." }),
|
|
113
|
+
option("where-eq", parsers.keyValue, { repeatable: !0, valueName: "COLUMN=VALUE", describe: "Match an exact value" }),
|
|
114
|
+
option("where-neq", parsers.keyValue, { repeatable: !0, valueName: "COLUMN=VALUE", describe: "Exclude an exact value" }),
|
|
115
|
+
option("where-in", parsers.keyValue, { repeatable: !0, valueName: "COLUMN=VALUE", describe: "Match any listed value for this column" }),
|
|
116
|
+
option("where-noin", parsers.keyValue, {
|
|
117
|
+
repeatable: !0,
|
|
118
|
+
valueName: "COLUMN=VALUE",
|
|
119
|
+
describe: "Exclude all listed values for this column"
|
|
120
|
+
}),
|
|
121
|
+
option("where-prefix", parsers.keyValue, { repeatable: !0, valueName: "COLUMN=VALUE", describe: "Match a value prefix" }),
|
|
122
|
+
option("where-regex", parsers.keyValue, {
|
|
123
|
+
repeatable: !0,
|
|
124
|
+
valueName: "COLUMN=/RE/FLAGS",
|
|
125
|
+
describe: "Match an RE2-compatible regex (flags: i, m, s, u)"
|
|
126
|
+
})
|
|
127
|
+
];
|
|
128
|
+
const fileRelations = {
|
|
129
|
+
requires: [["zip-entry", "compression"]],
|
|
130
|
+
requiresIf: [["compression", "zip", "zip-entry"]],
|
|
131
|
+
groups: [
|
|
132
|
+
{
|
|
133
|
+
name: "zip-limits",
|
|
134
|
+
members: ["max-compression-ratio", "max-decompressed-bytes"],
|
|
135
|
+
multiple: !0,
|
|
136
|
+
requires: ["zip-entry"]
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "schema",
|
|
140
|
+
members: ["fixed-columns", "expected-header", "require-header", "min-data-rows"],
|
|
141
|
+
multiple: !0,
|
|
142
|
+
requires: ["strict"]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "filters",
|
|
146
|
+
members: ["where", "where-eq", "where-neq", "where-in", "where-noin", "where-prefix", "where-regex"],
|
|
147
|
+
multiple: !0,
|
|
148
|
+
conflicts: ["strict"]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
};
|
|
152
|
+
const fileHelp = `ZIP input automatically selects the only data file, ignoring OS metadata.
|
|
153
|
+
Explicit ZIP options require --compression zip and --zip-entry.
|
|
154
|
+
Filters use original input column indexes. Friendly filter clauses use AND.
|
|
155
|
+
Strict mode cannot use filter options.
|
|
156
|
+
|
|
157
|
+
Encodings: ${encodings.choices?.map(({ value, aliases }) => aliases ? `${value} (${aliases.join(", ")})` : value).join(", ")}
|
|
158
|
+
Other Bun TextDecoder labels are also accepted.`;
|
|
159
|
+
const count = command("count", {
|
|
160
|
+
...fileRelations,
|
|
161
|
+
about: "Count CSV records, including the header row",
|
|
162
|
+
args: fileArgs,
|
|
163
|
+
argsOverrideSelf: !0,
|
|
164
|
+
afterHelp: `${fileHelp}
|
|
165
|
+
|
|
166
|
+
Examples:
|
|
167
|
+
csv count data.csv --chunk-size 256KiB
|
|
168
|
+
csv count data.csv --where-eq 2=SP
|
|
169
|
+
csv count data.csv --where-regex '1=/^ana/i'`
|
|
170
|
+
});
|
|
171
|
+
const lines = command("lines", {
|
|
172
|
+
...fileRelations,
|
|
173
|
+
conflicts: [["json", "output-delimiter"], ["limit", "min-data-rows"]],
|
|
174
|
+
about: "Stream matching records as normalized UTF-8 CSV or NDJSON",
|
|
175
|
+
args: [
|
|
176
|
+
...fileArgs,
|
|
177
|
+
flag("json", { describe: "Emit one JSON string array per record (NDJSON)" }),
|
|
178
|
+
option("output-delimiter", outputDelimiter, {
|
|
179
|
+
valueName: "CHAR",
|
|
180
|
+
default: ",",
|
|
181
|
+
describe: "One safe ASCII output delimiter (default: comma). Incompatible with --json"
|
|
182
|
+
}),
|
|
183
|
+
option("limit", parsers.range(1, Number.MAX_SAFE_INTEGER, { integer: !0 }), {
|
|
184
|
+
valueName: "N",
|
|
185
|
+
describe: "Stop after matching output record N, numbered from 1. Incompatible with --min-data-rows"
|
|
186
|
+
})
|
|
187
|
+
],
|
|
188
|
+
argsOverrideSelf: !0,
|
|
189
|
+
afterHelp: `${fileHelp}
|
|
190
|
+
|
|
191
|
+
With --strict and --limit, validation stops at the selected record. Set a fixed
|
|
192
|
+
delimiter and encoding (defaults: comma and UTF-8). Input must be uncompressed
|
|
193
|
+
and the chunk size must be 1 byte. Earlier records can be written before a later error.
|
|
194
|
+
|
|
195
|
+
Examples:
|
|
196
|
+
csv lines data.csv --json --limit 10
|
|
197
|
+
csv lines data.csv --columns 0,2 --where-eq 3=active`
|
|
198
|
+
});
|
|
199
|
+
export const csvCommand = command("csv", {
|
|
200
|
+
about: "Inspect, count, and stream CSV records",
|
|
201
|
+
version: packageInfo.version,
|
|
202
|
+
defaultToHelp: !0,
|
|
203
|
+
subcommandRequired: !0,
|
|
204
|
+
subcommands: [
|
|
205
|
+
count,
|
|
206
|
+
lines,
|
|
207
|
+
command("probe", {
|
|
208
|
+
about: "Inspect file size, compression, encoding, delimiter, line endings, and first record width",
|
|
209
|
+
args: [path, zipEntry],
|
|
210
|
+
argsOverrideSelf: !0,
|
|
211
|
+
afterHelp: "Samples up to 64 KiB of CSV. For a ZIP archive with multiple data files, select one with --zip-entry."
|
|
212
|
+
}),
|
|
213
|
+
command("completion", {
|
|
214
|
+
about: "Print a shell completion script for csv",
|
|
215
|
+
args: [positional("shell", parsers.enum(completionShells), { required: !0, describe: completionShells.join(", ") })]
|
|
216
|
+
})
|
|
217
|
+
],
|
|
218
|
+
afterHelp: "Run without installing: bunx @konstit/csv <command> <path>"
|
|
219
|
+
});
|