1.1.1 • Published 4 years ago

map-convert v1.1.1

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

MapConvert

convert data structure to definition schema.

NPM version Build Status Coverage Status

inspired by map-transform, but map-transform is too complex to use to me. so I implement a simple one.

Usage

var mapConvert = require('map-convert')
var source = {
  name: 'Jhin',
  hello: {
    world: 'hello world'
  }
}

var def = '{name} say {hello.world}!'
mapConvert(source, def)
// => 'Jhin say hello world!'

var def2 = { id: 1, name: '{name}Deng', say: '{hello.world}!' }
mapConvert(source, def2)
// => { id: 1, name: 'JhinDeng', say: 'hello world!' }

var def3 = [def2, { id: 2, name: 'alex', say: 'wow!' }]
mapConvert(source, def3)
/* =>
 [
    { id: 1, name: 'JhinDeng', say: 'hello world!' },
    { id: 2, name: 'alex', say: 'wow!' }
  ]
 */

the result will always be what definition schema looks like.

Contributing

  • suggestions welcome
  • contributions welcome
1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago