@schornio/map-object
Map javascript objects by dot notation and other cool stuff
Last updated 5 years ago by schornio .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @schornio/map-object 
SYNC missed versions from official npm registry.

map-object

Build Status

Usage

_constructor(map, options)

  • map: map schema
  • options: (optional) configuration
    • strictMode: error on unsuccessful mapping (default: ignore)
    • context: provide a context object

prototype.map(obj, callback)

  • obj: object to map
  • callback(error, obj): on mapping finished

Map Schema

{
  <string: destination name>: <string: source path>,
  <string: destination name>: <string: '$' + context source path>,
  <string: destination name>: <object: nested schema>
}

Example

var MapObjLib = require('@schornio/map-object');

var obj = {
  simpleProperty: 42,
  complexProperty: {
    child: 126
  }
};

var map = {
  flattern: 'complexProperty.child',
  explode: {
    child: 'simpleProperty'
  }
};

var objMap = new MapObjLib(map);
objMap.map(obj, function(error, result) {
  /* result == {
    flattern: 126,
    explode: {
      child: 42
    }
  }*/
});

Current Tags

  • 1.2.2                                ...           latest (5 years ago)

3 Versions

  • 1.2.2                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.2.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |