Skip to content

danne931/falcon-punch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

falcon-punch

Flatten your objects and arrays by a delimiter

Build Status Coverage Status npm version JavaScript Style Guide

Install

$ npm install --save falcon-punch

Not using Node or a module bundler? Use a UMD build via the <script> tag.

Usage

import falconPunch from 'falcon-punch'

const o = {
  a: 1,
  b: {
    c: 'falcon',
    d: {
      e: 'punch'
    }
  }
}
// { a: 1, 'b_c': 'falcon', 'b_d_e': 'punch' }
falconPunch(o)

// Specify opts: delimiter & maxDepth
// { a: 1, 'b???c': 'falcon', 'b???d': { e: 'punch' } }
falconPunch(o, { delimiter: '???', maxDepth: 1 })

// go crazy
const arr = [
  {
    a: [
      [
        {
          b: 0,
          c: 1
        },
        10
      ],
      {
        d: {
          e: null,
          f: [],
          g: {},
          h: undefined
        }
      }
    ]
  },
  [[1, [{}]]]
]
/*
{
  '0.a.0.0.b': 0,
  '0.a.0.0.c': 1,
  '0.a.0.1': 10,
  '0.a.1.d.e': null,
  '0.a.1.d.f': [],
  '0.a.1.d.g': {},
  '0.a.1.d.h': undefined,
  '1.0.0': 1,
  '1.0.1.0': {}
}
*/
falconPunch(arr, { delimiter: '.' })

About

Flatten your objects and arrays by a delimiter

Resources

Stars

Watchers

Forks

Packages

No packages published