Synopsis
transform-object transforms objects.
Install
With NPM
npm install transform-object
From source
git clone https://github.com/pluma/transform-object.gitcd transform-objectnpm installmake test
API
transform(obj, transformation)
Transforms the given object by mapping it against the given transformation recursively.
If obj
is an object and transformation
is an object, returns a new object with each property set to the result of applying the property of the transformation
to the respective property of the obj
:
{return s;} {return s;}var result = ;console; // {a: 'FOO', b: 'bar', c: 'Qux'}
If obj
is an array and transformation
is an array or object, returns a new array with each item set to the result of applying the matching property or item of the transformation
to the respective item in the obj
array:
{return s;} {return s;}var result1 = ;console; // ['FOO', 'Bar', 'qux']var result2 = ;console; // ['FOO', 'Bar', 'qux']
If transformation
is a Function
, returns the result of calling it with the given obj
as argument:
{return s;}var result = ;console; // 'FOO'
If transformation
is undefined
, returns the obj
:
var result = ;console; // 'foo'
Otherwise returns the transformation
:
var result = ;console; // 'bar'
Unlicense
This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.