ofl

1.0.1 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    10
    • latest

Version History

Package Sidebar

Install

npm i ofl

Weekly Downloads

10

Version

1.0.1

License

MIT

Unpacked Size

11.7 kB

Total Files

10

Last publish

Collaborators

  • astur