JSPM

transform-object

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q37257F

Transforms objects.

Package Exports

  • transform-object

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (transform-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.