JSPM

  • Created
  • Published
  • Downloads 1585
  • Score
    100M100P100Q108165F
  • License MIT

Merge and flatten any arrays found in all values within plain objects

Package Exports

  • object-flatten-all-arrays

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-flatten-all-arrays) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

object-flatten-all-arrays

Standard JavaScript

Merge and flatten any arrays found in all values within plain objects

Build Status Coverage Status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies Downloads/Month

Table of Contents

Install

$ npm install --save object-flatten-all-arrays

Purpose

Recursively traverse the cloned input and merge all plain objects within each array.

Use

var flatten = require('object-flatten-all-arrays')
var object = {
  a: 'a',
  b: 'b',
  c: [
    {
      b: 'b',
      a: 'a'
    },
    {
      d: 'd',
      c: 'c'
    }
  ]
}
var flattened = flatten(object)
console.log('flattened = ' + JSON.stringify(flattened, null, 4))
// => {
// a: 'a',
// b: 'b',
// c: [
//   {
//     a: 'a',
//     b: 'b',
//     c: 'c',
//     d: 'd'
//   }
// ]}

API

flatten(input)

API - Input

None of the input arguments are mutated. Their clones are being used instead.

Input argument Type Obligatory? Description
input Whatever yes AST tree, or object or array or whatever. Can be deeply-nested. Hopefully contains some plain objects.

Testing

$ npm test

For unit tests we use AVA, Istanbul CLI and JS Standard notation.

Contributing

All contributions are welcome. Please stick to Standard JavaScript notation and supplement the test.js with new unit tests covering your feature(s).

If you see anything incorrect whatsoever, do raise an issue. If you file a pull request, I'll do my best to help you to get it merged in a timely manner. If you have any comments on the code, including ideas how to improve things, don't hesitate to contact me by email.

Licence

MIT License (MIT)

Copyright (c) 2017 Codsen Ltd, Roy Reveltas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.