0.1.3 • Published 9 years ago

chryformer v0.1.3

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

NPM version Build Status Dependency Status

Basic transformer for use with chrysalis.

Install

$ npm install chryformer --save

Usage

The chryformer is the basic transformer for use with chrysalis - 'githublink@here' chryformer supports a simple map strategy designed to effortlessly transform a collection of source objects to a collection of new objects of a unique scheme.

###Initialization It is required to initialize the chryformer with a Mapper. A mapper can be an object mapping the keys on the source object to the desired keys on the destination object or an iteratee function that will be run on each item in the source collection.

var Chryformer = require('chryformer');
var Chrysalis = require('chrysalis');

var map = {
  sourceKey1: 'destinationKey1',
  sourceKey2: 'destinationKey2'
};
var chryformer = Chryformer(map);

var chrysalis = Chrysalis();
chrysalis.setTransformer(chryformer);

#API

  • chryformer.setFilter (filter) - Sets the filter strategy to be used by the chryformer.
  • chryformer.setReducer (reducer) - Sets the reducer strategy to be used by the chryformer
  • chryformer.transform (inputData) - Transforms the input data based on the filter, mapper, and reducer.
    • inputData (Array|Object) - An single object or array of source objects that will be transformed. If you are using Chrysalis, this will be fed the output from your extractor.

#Example

var input = [{
  name: 'Fred',
  age: 35
}, {
  name: 'Barney',
  age: 32
}, {
  name: 'Pebbles',
  age: 6
}];

var mapObj = {
  name: 'firstName',
  age: 'age'
};

var transformer = chryformer(mapObj);
transformer.setFilter(function(data) {
  return data.age > 30;
});

chryformer.transform(input);
// -> [{firstName: 'Fred', age: 35}, {firsName: 'Barney', age: 32}]

License

MIT © APPrise-Mobile

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago