node package manager

transform-per-suffixes

transform-per-suffixes

Helpers to transform every properties of an object having a specific suffix.

NPM version Build status Dependency Status devDependency Status Coverage Status

## transform-per-suffixes ### transform-per-suffixes~transformPerSuffixes(suffixes) ⇒ Object | Array | Object | Array Transform every properties of an object according to given suffixes.

Kind: inner method of transform-per-suffixes
Returns: Object | Array - val The source Object/ArrayObject | Array - The modified object

Param Type Description
suffixes Array An array of suffix definitions ({value: String, transform: Function})

Example

var object = {
  _id: 'abbacacaabbacacaabbacaca',
  creation_date: '2015-11-28T16:22:47.552Z',
  value: 'Hey!'
};
console.log(transformPerSuffixes([{
  value: '_id',
  transform: castToObjectId,
}, {
  value: '_date',
  transform: function(d) { return new Date(d) },
}]));
// Prints: 
// { 
//   _id: ObjectId('abbacacaabbacacaabbacaca'), 
//   creation_date: Date('2015-11-28T16:22:47.552Z'), 
//   value: 'Hey!' 
// }