convert-buddy-js 0.10.18 → 0.11.1

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 (37) hide show
  1. package/README.md +49 -4
  2. package/dist/browser-stream-controller.d.ts +107 -0
  3. package/dist/browser-stream-controller.js +226 -0
  4. package/dist/browser-stream-controller.js.map +1 -0
  5. package/dist/browser.d.ts +16 -195
  6. package/dist/browser.js +78 -339
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index-BpUN6Tdz.d.ts +440 -0
  9. package/dist/index.d.ts +1 -271
  10. package/dist/index.js +34 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/node-stream-controller.d.ts +133 -0
  13. package/dist/node-stream-controller.js +274 -0
  14. package/dist/node-stream-controller.js.map +1 -0
  15. package/dist/node.d.ts +3 -2
  16. package/dist/node.js +2 -0
  17. package/dist/node.js.map +1 -1
  18. package/dist/stream-controller.d.ts +1 -0
  19. package/dist/stream-controller.js +277 -0
  20. package/dist/stream-controller.js.map +1 -0
  21. package/dist/streaming-worker.js +1 -1
  22. package/dist/streaming-worker.js.map +1 -1
  23. package/dist/tests/stream-controller.test.js +237 -0
  24. package/dist/tests/stream-controller.test.js.map +1 -0
  25. package/dist/wasm/nodejs/convert_buddy.d.ts +6 -0
  26. package/dist/wasm/nodejs/convert_buddy.js +58 -28
  27. package/dist/wasm/nodejs/convert_buddy_bg.wasm +0 -0
  28. package/dist/wasm/nodejs/convert_buddy_bg.wasm.d.ts +4 -3
  29. package/dist/wasm/web/convert_buddy.d.ts +10 -3
  30. package/dist/wasm/web/convert_buddy.js +55 -27
  31. package/dist/wasm/web/convert_buddy_bg.wasm +0 -0
  32. package/dist/wasm/web/convert_buddy_bg.wasm.d.ts +4 -3
  33. package/package.json +3 -5
  34. package/dist/browser-core.d.ts +0 -196
  35. package/dist/browser-core.js +0 -787
  36. package/dist/browser-core.js.map +0 -1
  37. package/dist/wasm/nodejs/convert_buddy.cjs +0 -712
package/dist/index.d.ts CHANGED
@@ -1,271 +1 @@
1
- type Format = "csv" | "ndjson" | "json" | "xml";
2
- type DetectInput = Uint8Array | ArrayBuffer | string | ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>;
3
- type CsvDetection = {
4
- delimiter: string;
5
- fields: string[];
6
- };
7
- type XmlDetection = {
8
- elements: string[];
9
- recordElement?: string;
10
- };
11
- type JsonDetection = {
12
- fields: string[];
13
- };
14
- type NdjsonDetection = {
15
- fields: string[];
16
- };
17
- type StructureDetection = {
18
- format: Format;
19
- fields: string[];
20
- delimiter?: string;
21
- recordElement?: string;
22
- };
23
- type DetectOptions = {
24
- maxBytes?: number;
25
- debug?: boolean;
26
- };
27
- type ProgressCallback = (stats: Stats) => void;
28
- type ConvertBuddyOptions = {
29
- debug?: boolean;
30
- profile?: boolean;
31
- inputFormat?: Format | "auto";
32
- outputFormat?: Format;
33
- chunkTargetBytes?: number;
34
- parallelism?: number;
35
- maxMemoryMB?: number;
36
- csvConfig?: CsvConfig;
37
- xmlConfig?: XmlConfig;
38
- transform?: TransformConfig;
39
- onProgress?: ProgressCallback;
40
- progressIntervalBytes?: number;
41
- };
42
- type ConvertOptions = {
43
- inputFormat?: Format | "auto";
44
- outputFormat: Format;
45
- csvConfig?: CsvConfig;
46
- xmlConfig?: XmlConfig;
47
- transform?: TransformConfig;
48
- onProgress?: ProgressCallback;
49
- };
50
- type CsvConfig = {
51
- delimiter?: string;
52
- quote?: string;
53
- hasHeaders?: boolean;
54
- trimWhitespace?: boolean;
55
- };
56
- type XmlConfig = {
57
- recordElement?: string;
58
- trimText?: boolean;
59
- includeAttributes?: boolean;
60
- expandEntities?: boolean;
61
- };
62
- type TransformMode = "replace" | "augment";
63
- type Coerce = {
64
- type: "string";
65
- } | {
66
- type: "i64";
67
- } | {
68
- type: "f64";
69
- } | {
70
- type: "bool";
71
- } | {
72
- type: "timestamp_ms";
73
- format?: "iso8601" | "unix_ms" | "unix_s";
74
- };
75
- type FieldMap = {
76
- targetFieldName: string;
77
- originFieldName?: string;
78
- required?: boolean;
79
- defaultValue?: string | number | boolean | null;
80
- coerce?: Coerce;
81
- compute?: string;
82
- };
83
- type TransformConfig = {
84
- mode?: TransformMode;
85
- fields: FieldMap[];
86
- onMissingField?: "error" | "null" | "drop";
87
- onMissingRequired?: "error" | "abort";
88
- onCoerceError?: "error" | "null" | "dropRecord";
89
- };
90
- type Stats = {
91
- bytesIn: number;
92
- bytesOut: number;
93
- chunksIn: number;
94
- recordsProcessed: number;
95
- parseTimeMs: number;
96
- transformTimeMs: number;
97
- writeTimeMs: number;
98
- maxBufferSize: number;
99
- currentPartialSize: number;
100
- throughputMbPerSec: number;
101
- };
102
- declare class ConvertBuddy {
103
- private converter;
104
- private debug;
105
- private profile;
106
- private aborted;
107
- private paused;
108
- private onProgress?;
109
- private progressIntervalBytes;
110
- private lastProgressBytes;
111
- private globalConfig;
112
- private initialized;
113
- simd: boolean;
114
- /**
115
- * Create a new ConvertBuddy instance with global configuration.
116
- * This is useful when you want to set memory limits, debug mode, or other global settings.
117
- *
118
- * @example
119
- * const buddy = new ConvertBuddy({ maxMemoryMB: 512, debug: true });
120
- * const result = await buddy.convert(input, { outputFormat: "json" });
121
- */
122
- constructor(opts?: ConvertBuddyOptions);
123
- /**
124
- * Convert input (string, Buffer, File, URL, etc.) to the desired output format.
125
- * This is the main method for the new simplified API.
126
- *
127
- * @example
128
- * // Auto-detect everything
129
- * const buddy = new ConvertBuddy();
130
- * const result = await buddy.convert("https://example.com/data.csv", { outputFormat: "json" });
131
- *
132
- * @example
133
- * // With configuration
134
- * const buddy = new ConvertBuddy({ maxMemoryMB: 512 });
135
- * const result = await buddy.convert(file, { inputFormat: "csv", outputFormat: "json" });
136
- */
137
- convert(input: string | Uint8Array | File | Blob | ReadableStream<Uint8Array>, opts: ConvertOptions): Promise<Uint8Array>;
138
- private convertFromUrl;
139
- private convertFromString;
140
- private convertFromBuffer;
141
- private convertFromBufferParallel;
142
- private convertUsingNodejsThreadPool;
143
- private convertUsingWasmThreadPool;
144
- private convertUsingJsParallelism;
145
- private splitIntoChunks;
146
- private convertFromFile;
147
- private convertFromBlob;
148
- private convertFromStream;
149
- /**
150
- * Legacy create method for backward compatibility.
151
- * Prefer using the constructor: new ConvertBuddy(opts)
152
- */
153
- static create(opts?: ConvertBuddyOptions): Promise<ConvertBuddy>;
154
- push(chunk: Uint8Array): Uint8Array;
155
- finish(): Uint8Array;
156
- stats(): Stats;
157
- abort(): void;
158
- pause(): void;
159
- resume(): void;
160
- isAborted(): boolean;
161
- isPaused(): boolean;
162
- }
163
- declare function detectFormat(input: DetectInput, opts?: DetectOptions): Promise<Format | "unknown">;
164
- declare function detectStructure(input: DetectInput, formatHint?: Format, opts?: DetectOptions): Promise<StructureDetection | null>;
165
- declare function detectCsvFieldsAndDelimiter(input: DetectInput, opts?: DetectOptions): Promise<CsvDetection | null>;
166
- declare function detectXmlElements(input: DetectInput, opts?: DetectOptions): Promise<XmlDetection | null>;
167
- declare function autoDetectConfig(input: DetectInput, opts?: DetectOptions): Promise<{
168
- format: Format | "unknown";
169
- csvConfig?: CsvConfig;
170
- xmlConfig?: XmlConfig;
171
- }>;
172
- declare class ConvertBuddyTransformStream extends TransformStream<Uint8Array, Uint8Array> {
173
- constructor(opts?: ConvertBuddyOptions);
174
- }
175
- declare function convert(input: Uint8Array | string, opts?: ConvertBuddyOptions): Promise<Uint8Array>;
176
- declare function convertToString(input: Uint8Array | string, opts?: ConvertBuddyOptions): Promise<string>;
177
- /**
178
- * Ultra-simple standalone convert function with auto-detection.
179
- * Accepts any input type (URL, File, Buffer, string, stream) and automatically detects format.
180
- *
181
- * @example
182
- * // From URL
183
- * import { convertAny } from "convert-buddy-js";
184
- * const result = await convertAny("https://example.com/data.csv", { outputFormat: "json" });
185
- *
186
- * @example
187
- * // From File (browser)
188
- * const file = fileInput.files[0];
189
- * const result = await convertAny(file, { outputFormat: "ndjson" });
190
- *
191
- * @example
192
- * // From string data
193
- * const result = await convertAny('{"name":"Ada"}', { outputFormat: "csv" });
194
- */
195
- declare function convertAny(input: string | Uint8Array | File | Blob | ReadableStream<Uint8Array>, opts: ConvertOptions): Promise<Uint8Array>;
196
- /**
197
- * Ultra-simple standalone convert function that returns a string.
198
- * Same as convertAny but decodes the output to a string.
199
- *
200
- * @example
201
- * import { convertAnyToString } from "convert-buddy-js";
202
- * const json = await convertAnyToString("https://example.com/data.csv", { outputFormat: "json" });
203
- * console.log(JSON.parse(json));
204
- */
205
- declare function convertAnyToString(input: string | Uint8Array | File | Blob | ReadableStream<Uint8Array>, opts: ConvertOptions): Promise<string>;
206
- /**
207
- * Get MIME type for a given format
208
- *
209
- * @example
210
- * const mimeType = getMimeType("json"); // "application/json"
211
- */
212
- declare function getMimeType(format: Format): string;
213
- /**
214
- * Get file extension for a given format (without the dot)
215
- *
216
- * @example
217
- * const ext = getExtension("json"); // "json"
218
- */
219
- declare function getExtension(format: Format): string;
220
- /**
221
- * Get suggested filename for a converted file
222
- *
223
- * @param originalName - Original filename
224
- * @param outputFormat - Target format
225
- * @param includeTimestamp - Whether to include a timestamp (default: false)
226
- *
227
- * @example
228
- * const name = getSuggestedFilename("data.csv", "json"); // "data.json"
229
- * const name = getSuggestedFilename("data.csv", "json", true); // "data_converted_1234567890.json"
230
- */
231
- declare function getSuggestedFilename(originalName: string, outputFormat: Format, includeTimestamp?: boolean): string;
232
- /**
233
- * Get File System Access API file type configuration for showSaveFilePicker
234
- *
235
- * @example
236
- * const types = getFileTypeConfig("json");
237
- * const handle = await showSaveFilePicker({ types });
238
- */
239
- declare function getFileTypeConfig(format: Format): Array<{
240
- description: string;
241
- accept: Record<string, string[]>;
242
- }>;
243
- /**
244
- * Check if WASM threading is supported in the current environment
245
- * @returns true if SharedArrayBuffer and Atomics are available (required for WASM threads)
246
- */
247
- declare function isWasmThreadingSupported(): boolean;
248
- /**
249
- * Get the optimal number of worker threads based on CPU cores and WASM capabilities
250
- * @returns Recommended thread count for optimal performance
251
- */
252
- declare function getOptimalThreadCount(): number;
253
- /**
254
- * Get current threading capabilities and configuration
255
- * @returns Object with threading information
256
- */
257
- declare function getThreadingInfo(): {
258
- wasmThreadingSupported: boolean;
259
- customThreadPoolAvailable: boolean;
260
- nodejsWasmThreading: boolean;
261
- recommendedThreads: number;
262
- currentThreads: number;
263
- approach: string;
264
- };
265
- /**
266
- * Backward compatibility alias for ConvertBuddy
267
- * @deprecated Use ConvertBuddy instead
268
- */
269
- declare const Converter: typeof ConvertBuddy;
270
-
271
- export { type Coerce, ConvertBuddy, type ConvertBuddyOptions, ConvertBuddyTransformStream, type ConvertOptions, Converter, type CsvConfig, type CsvDetection, type DetectInput, type DetectOptions, type FieldMap, type Format, type JsonDetection, type NdjsonDetection, type ProgressCallback, type Stats, type StructureDetection, type TransformConfig, type TransformMode, type XmlConfig, type XmlDetection, autoDetectConfig, convert, convertAny, convertAnyToString, convertToString, detectCsvFieldsAndDelimiter, detectFormat, detectStructure, detectXmlElements, getExtension, getFileTypeConfig, getMimeType, getOptimalThreadCount, getSuggestedFilename, getThreadingInfo, isWasmThreadingSupported };
1
+ export { f as Coerce, j as ConvertBuddy, a as ConvertBuddyOptions, p as ConvertBuddyTransformStream, C as ConvertOptions, z as Converter, d as CsvConfig, b as CsvDetection, D as DetectInput, c as DetectOptions, g as FieldMap, F as Format, J as JsonDetection, N as NdjsonDetection, B as ParsedRecord, P as ProgressCallback, i as Stats, A as StreamControllerOptions, S as StructureDetection, h as TransformConfig, T as TransformMode, e as XmlConfig, X as XmlDetection, o as autoDetectConfig, L as convert, q as convertAny, r as convertAnyToString, M as convertToString, m as detectCsvFieldsAndDelimiter, k as detectFormat, l as detectStructure, n as detectXmlElements, t as getExtension, v as getFileTypeConfig, s as getMimeType, x as getOptimalThreadCount, u as getSuggestedFilename, y as getThreadingInfo, w as isWasmThreadingSupported } from './index-BpUN6Tdz.js';
package/dist/index.js CHANGED
@@ -604,6 +604,40 @@ class ConvertBuddy {
604
604
  }
605
605
  return output;
606
606
  }
607
+ /**
608
+ * Push a chunk and optionally get pre-parsed records.
609
+ * This is more efficient than parsing the output yourself.
610
+ *
611
+ * @param chunk - Input chunk to process
612
+ * @param includeRecords - If true, returns { output, records }, otherwise just output bytes
613
+ * @returns Either Uint8Array or { output: Uint8Array, records: any[] }
614
+ */
615
+ pushWithRecords(chunk, includeRecords = true) {
616
+ if (this.aborted) {
617
+ throw new Error("Conversion has been aborted");
618
+ }
619
+ if (this.paused) {
620
+ throw new Error("Conversion is paused. Call resume() before pushing more data.");
621
+ }
622
+ if (this.debug) console.log("[convert-buddy-js] pushWithRecords", chunk.byteLength, "includeRecords:", includeRecords);
623
+ if (typeof this.converter.pushWithRecords === "function") {
624
+ const result = this.converter.pushWithRecords(chunk, includeRecords);
625
+ if (this.onProgress) {
626
+ const stats = this.stats();
627
+ if (stats.bytesIn - this.lastProgressBytes >= this.progressIntervalBytes) {
628
+ this.onProgress(stats);
629
+ this.lastProgressBytes = stats.bytesIn;
630
+ }
631
+ }
632
+ return result;
633
+ } else {
634
+ const output = this.push(chunk);
635
+ if (includeRecords) {
636
+ return { output, records: [] };
637
+ }
638
+ return output;
639
+ }
640
+ }
607
641
  finish() {
608
642
  if (this.aborted) {
609
643
  throw new Error("Conversion has been aborted");