adaltas / node-stream-transform

Object transformations implementing the Node.js `stream.Transform` API
https://csv.js.org/transform/
49 stars 13 forks source link

passing additional param to transform callback #15

Closed hbakhtiyor closed 7 years ago

hbakhtiyor commented 9 years ago

for example

datasets.forEach(dataset => {
  var parser = parse({delimiter: dataset.delimiter, ...);
   // we can pass everything, fn, arrays, some extra data, ...
  var transformer = transform(transformer_callback, dataset.defautls);
  request(dataset.url).pipe(parser).pipe(transformer).pipe(process.stdout);
});

function transformer_callback(record, calllback, defaults) {
  // we can use the third argument for each of the specific datasets.
  record.country = defaults.country; 
  // e.g. for some dataset the default country is US, for another is EUR, ....

}