extruder

Functional tools for processing node-task input objects.

npm install extruder
1 downloads in the last day
5 downloads in the last week
16 downloads in the last month

extruder

Functional, promise-based tools for processing node-task input objects.

API

extruder.map

Iterate over node-task inputs and map their sources for transformation by a provided callback. Return a promise which resolves to the modified input.

extruder.map(input, fn, context)
  • input A node-task input object.
  • fn A method to be invoked for each source item. Its return value (can be a promise) will replace each source item. fn(source, dest)
  • context The context the fn will be called with.
var extruder = require('./lib/extruder');
var sources = ['path/to/source1', 'path/to/source2'];
extruder.map(sources, function(source, dest) {
  return source+'mapped';
}).then(function(result) {
  console.log(result); // ['path/to/source1mapped', 'path/to/source2mapped'];
});

var sourceDestPairs = [
  { src: 'path/to/source1', dest: 'path/to/dest' },
  { src: ['path/to/source2', 'path/to/source3'], dest: 'path/to/dest' }
];
extruder.map(sourceDestPairs, function(source, dest) {
  return source+'mapped';
}).then(function(result) {
  console.log(result); // [ { src: 'path/to/source1', dest: 'path/to/dest' },
                       // { src: 'path/to/source2-path/to/source3, dest: 'path/to/dest' } ]
});

extruder.reduce

Iterate over node-task inputs and reduce their sources with a provided callback. Return a promise which resolves to the modified input.

extruder.reduce(input, fn, context)
  • input A node-task input object.
  • fn A method to be invoked for each source array. Its return value (can be a promise) will replace each source array. fn(source, dest)
  • context The context the fn will be called with.
var extruder = require('extruder');
var sources = ['path/to/source1', 'path/to/source2'];
extruder.reduce(sources, function(sources, dest) {
  return sources.join('-');
}).then(function(result) {
  console.log(result); // 'path/to/source1-path/to/source2';
});

var sourceDestPairs = [
  { src: 'path/to/source1', dest: 'path/to/dest' },
  { src: ['path/to/source2', 'path/to/source3'], dest: 'path/to/dest' }
];
extruder.reduce(sourceDestPairs, function(sources, dest) {
  return sources.join('-');
}).then(function(result) {
  console.log(result); // [ { src: 'path/to/source1', dest: 'path/to/dest' },
                       //   { src: 'path/to/source2-path/to/source3', dest: 'path/to/dest' } ]
});
npm loves you