0.0.2 • Published 8 years ago

maplib v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
8 years ago

MapLib

Isomorphic transformations. Map, transform, filter, and morph your objects

Getting Started

$ npm i --save maplib

and then

const Mapper = require('maplib')

const mapper = new Mapper(/* [config] */)

const old = {
  here: {
    there: {
      anywhere: 'Earth'
    }
  }
}

const mappings = [ 'here.there.anywhere:location' ]

const transformation = mapper.map(mappings, old)
// -> { location: 'Earth' }

Config

You can pass in a config object to Mapper to create your own mapping system:

Options
FieldTypeDefault
typesObject{}
objDelimiterString"."
mapDelimiterString":"
preFiltersArray[]
postFiltersArray[]
Example
const mapper = new Mapper({
  objDelimiter: '|',
  mapDelimiter: '->',
  types: { bool: Boolean },
  preFilters: [ FILTER_NULL ],
  postFilters: [ REMOVE_PASSWORD ]
  // add other field to your config here
})

Examples

See test/index.spec.js for more examples of how to use MapLib.