MCPcopy
hub / github.com/adaltas/node-csv / transform

Function transform

packages/stream-transform/lib/sync.js:10–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8import { Transformer } from "./index.js";
9
10const transform = function () {
11 // Import arguments normalization
12 let handler, records;
13 let options = {};
14 for (const i in arguments) {
15 const argument = arguments[i];
16 let type = typeof argument;
17 if (argument === null) {
18 type = "null";
19 } else if (type === "object" && Array.isArray(argument)) {
20 type = "array";
21 }
22 if (type === "array") {
23 records = argument;
24 } else if (type === "object") {
25 options = { ...argument };
26 } else if (type === "function") {
27 handler = argument;
28 } else if (type !== "null") {
29 throw new Error(
30 `Invalid Arguments: got ${JSON.stringify(argument)} at position ${i}`,
31 );
32 }
33 }
34 // Validate arguments
35 let expected_handler_length = 1;
36 if (options.params) {
37 expected_handler_length++;
38 }
39 if (handler.length > expected_handler_length) {
40 throw Error("Invalid Handler: only synchronous handlers are supported");
41 }
42 // Start transformation
43 const chunks = [];
44 const transformer = new Transformer(options, handler);
45 transformer.push = function (chunk) {
46 chunks.push(chunk);
47 };
48 for (const record of records) {
49 transformer._transform(record, null, function () {});
50 }
51 return chunks;
52};
53
54export { transform };

Callers 15

recipe.pipe.jsFile · 0.90
state.handler.jsFile · 0.90
mode.sync.jsFile · 0.90
mode.callback.jsFile · 0.90
api.callback.jsFile · 0.90
api.sync.jsFile · 0.90
state.instance.jsFile · 0.90
api.stream.jsFile · 0.90
mode.promise.jsFile · 0.90

Calls 1

_transformMethod · 0.45

Tested by

no test coverage detected