convert-buddy-js 0.2.0 → 0.4.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 CHANGED
@@ -44,11 +44,13 @@ console.log(buddy.stats());
44
44
 
45
45
  ### Node.js Transform stream
46
46
 
47
+ Use the Node-specific entrypoint so bundlers keep `node:stream` out of the browser bundle.
48
+
47
49
  ```ts
48
- import { createNodeTransform } from "convert-buddy-js";
50
+ import { createNodeTransform } from "convert-buddy-js/node";
49
51
  import { createReadStream, createWriteStream } from "node:fs";
50
52
 
51
- const transform = createNodeTransform({
53
+ const transform = await createNodeTransform({
52
54
  inputFormat: "csv",
53
55
  outputFormat: "ndjson",
54
56
  csvConfig: { hasHeaders: true },
@@ -74,6 +76,28 @@ const response = await fetch("/data.csv");
74
76
  const outputStream = response.body?.pipeThrough(transform);
75
77
  ```
76
78
 
79
+ ### Detect format and CSV fields/delimiter
80
+
81
+ Use streaming inputs to keep detection fast on large files.
82
+
83
+ ```ts
84
+ import {
85
+ detectFormat,
86
+ detectCsvFieldsAndDelimiter,
87
+ } from "convert-buddy-js";
88
+
89
+ const fileStream = (await fetch("/data")).body!;
90
+
91
+ const format = await detectFormat(fileStream, { maxBytes: 256 * 1024 });
92
+ console.log(format); // "csv" | "json" | "ndjson" | "xml" | "unknown"
93
+
94
+ const csvInfo = await detectCsvFieldsAndDelimiter(fileStream);
95
+ if (csvInfo) {
96
+ console.log(csvInfo.delimiter);
97
+ console.log(csvInfo.fields);
98
+ }
99
+ ```
100
+
77
101
  ## Configuration
78
102
 
79
103
  ### Formats
@@ -1,5 +1,4 @@
1
1
  // src/index.ts
2
- import { Transform } from "stream";
3
2
  async function loadWasmModule() {
4
3
  const isNode = typeof process !== "undefined" && !!process.versions?.node;
5
4
  if (isNode) {
@@ -56,9 +55,18 @@ var ConvertBuddy = class _ConvertBuddy {
56
55
  return this.converter.getStats();
57
56
  }
58
57
  };
59
- function createNodeTransform(opts = {}) {
58
+ async function loadNodeTransform() {
59
+ const isNode = typeof process !== "undefined" && !!process.versions?.node;
60
+ if (!isNode) {
61
+ throw new Error("createNodeTransform is only available in Node.js runtimes.");
62
+ }
63
+ const streamModule = await import("stream");
64
+ return streamModule.Transform;
65
+ }
66
+ async function createNodeTransform(opts = {}) {
60
67
  let buddy = null;
61
68
  let initPromise = null;
69
+ const Transform = await loadNodeTransform();
62
70
  const transform = new Transform({
63
71
  async transform(chunk, encoding, callback) {
64
72
  try {
@@ -158,4 +166,4 @@ export {
158
166
  convert,
159
167
  convertToString
160
168
  };
161
- //# sourceMappingURL=chunk-B44HYXEP.js.map
169
+ //# sourceMappingURL=chunk-27H3T556.js.map
@@ -44,7 +44,7 @@ declare class ConvertBuddy {
44
44
  finish(): Uint8Array;
45
45
  stats(): Stats;
46
46
  }
47
- declare function createNodeTransform(opts?: ConvertBuddyOptions): Transform;
47
+ declare function createNodeTransform(opts?: ConvertBuddyOptions): Promise<Transform>;
48
48
  declare class ConvertBuddyTransformStream extends TransformStream<Uint8Array, Uint8Array> {
49
49
  constructor(opts?: ConvertBuddyOptions);
50
50
  }
package/dist/src/index.js CHANGED
@@ -4,8 +4,7 @@ import {
4
4
  convert,
5
5
  convertToString,
6
6
  createNodeTransform
7
- } from "../chunk-B44HYXEP.js";
8
- import "../chunk-VUNV25KB.js";
7
+ } from "../chunk-27H3T556.js";
9
8
  export {
10
9
  ConvertBuddy,
11
10
  ConvertBuddyTransformStream,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "convert-buddy-js",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "TypeScript wrapper for convert-buddy (Rust/WASM core)",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -10,11 +10,17 @@
10
10
  ".": {
11
11
  "types": "./dist/src/index.d.ts",
12
12
  "default": "./dist/src/index.js"
13
+ },
14
+ "./node": {
15
+ "types": "./dist/src/node.d.ts",
16
+ "default": "./dist/src/node.js"
13
17
  }
14
18
  },
15
19
  "files": [
16
20
  "dist/src/index.js",
17
21
  "dist/src/index.d.ts",
22
+ "dist/src/node.js",
23
+ "dist/src/node.d.ts",
18
24
  "dist/chunk-*.js",
19
25
  "dist/chunk-*.d.ts",
20
26
  "dist/*.js",
@@ -1,16 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
- }) : x)(function(x) {
5
- if (typeof require !== "undefined") return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
- var __commonJS = (cb, mod) => function __require2() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
-
12
- export {
13
- __require,
14
- __commonJS
15
- };
16
- //# sourceMappingURL=chunk-VUNV25KB.js.map