1.0.1 • Published 6 years ago

ofl v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ofl

Build Status NPM version

Convertion between nested object and flat one with delimited keys. Yet another flatten/unflatten module with few differences:

  • no undefined values allowed
  • only primitives in arrays (no nested arrays and so on)
  • only plain objects
  • empty objects are ignored when flatten
  • only own and enumerable fields counts when flatten
  • no key conflicts allowed in flat object
  • no delimiter string in any key in nested object

It is intended to be useful for work with well-serializable config data.

Install

npm install ofl

Usage

const {
    flatten, //convert nested object to flat
    unflatten, //convert flat object to nested
    patch, //cange some fields in flat object
    validKeys, //test if array of keys are valid for flat object
    validValues,  //test if array of values are valid for flat object
} = require('ofl');

flatObj = flatten(nestedObj, delimiter);
nestedObj = unflatten(flatObj, delimiter);
//throw error if inappropriate object sent
//delimiter is optional, defaults to '.'

patchedFlatObj = patch(flatObj, diffFlatObj);
//throw error if diffFlatObj keys is not subset of flatObj keys

validKeys(Object.keys(flatObj));
validValues(Object.values(flatObj));
//throw error if inappropriate key or value

License

MIT

1.0.1

6 years ago

1.0.0

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago