Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

pluma/transform-object

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTE: This package is no longer being maintained. If you are interested in taking over as maintainer or are interested in the npm package name, get in touch by creating an issue.

Synopsis

transform-object transforms objects.

stability 3 - stable license - Unlicense Flattr this

Build Status Coverage Status Dependencies

NPM status

Install

With NPM

npm install transform-object

From source

git clone https://github.com/pluma/transform-object.git
cd transform-object
npm install
make 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:

function upper(s) {return s.toUpperCase();}
function lower(s) {return s.toLowerCase();}
var result = transform({a: 'Foo', b: 'Bar', c: 'Qux'}, {a: upper, b: lower});
console.log(result); // {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:

function upper(s) {return s.toUpperCase();}
function lower(s) {return s.toLowerCase();}
var result1 = transform(['Foo', 'Bar', 'Qux'], {0: upper, 2: lower});
console.log(result1); // ['FOO', 'Bar', 'qux']
var result2 = transform(['Foo', 'Bar', 'Qux'], [upper, undefined, lower]);
console.log(result2); // ['FOO', 'Bar', 'qux']

If transformation is a Function, returns the result of calling it with the given obj as argument:

function upper(s) {return s.toUpperCase();}
var result = transform('foo', upper);
console.log(result); // 'FOO'

If transformation is undefined, returns the obj:

var result = transform('foo', undefined);
console.log(result); // 'foo'

Otherwise returns the transformation:

var result = transform('foo', 'bar');
console.log(result); // 'bar'

Unlicense

This is free and unencumbered public domain software. For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.

About

UNMAINTAINED. Transform objects using deep transformations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published