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
Merge and flatten any arrays found in all values within plain objects
Table of Contents
Install
npm i object-flatten-all-arrays
// consume as a CommonJS require:
const flattenAllArrays = require('object-flatten-all-arrays')
// or as an ES Module:
import flattenAllArrays from 'object-flatten-all-arrays'
Here's what you'll get:
Type | Key in package.json |
Path | Size |
---|---|---|---|
Main export - CommonJS version, transpiled to ES5, contains require and module.exports |
main |
dist/object-flatten-all-arrays.cjs.js |
2 KB |
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import /export . |
module |
dist/object-flatten-all-arrays.esm.js |
2 KB |
UMD build for browsers, transpiled, minified, containing iife 's and has all dependencies baked-in |
browser |
dist/object-flatten-all-arrays.umd.js |
34 KB |
Purpose
Recursively traverse the cloned input and merge all plain objects within each array.
For example
const flattenAllArrays = require('object-flatten-all-arrays')
const object = {
a: 'a',
b: 'b',
c: [
{
b: 'b',
a: 'a'
},
{
d: 'd',
c: 'c'
},
]
}
const flattened = flattenAllArrays(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[, options])
Returns the same type thing as given input, only with arrays (recursively) flattened.
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. |
options |
Plain object | no | Set the options in this object. See below for keys. |
options object's key |
Type | Obligatory? | Default | Description |
---|---|---|---|---|
{ | ||||
flattenArraysContainingStringsToBeEmpty |
Boolean | no | false |
If any arrays contain strings, flatten them to be empty thing. This is turned off by default, but it's what you actually need most of the time. |
} |
Contributing
Hi! 99% of people in the society are passive - consumers. They wait for others to take action, they prefer to blend in. The remaining 1% are proactive citizens who will do something rather than wait. If you are one of that 1%, you're in luck because I am the same and together we can make something happen.
If you want a new feature in this package or you would like to change some of its functionality, raise an issue on this repo. Also, you can email me. Just let it out.
If you tried to use this library but it misbehaves, or you need an advice setting it up, and its readme doesn't make sense, just document it and raise an issue on this repo. Alternatively, you can email me.
If you don't like the code in here and would like to give advice about how something could be done better, please do. Same drill - GitHub issues or email, your choice.
If you would like to add or change some features, just fork it, hack away, and file a pull request. I'll do my best to merge it quickly. Code style is
airbnb-base
, only without semicolons. If you use a good code editor, it will pick up the established ESLint setup.
Licence
MIT License (MIT)
Copyright © 2018 Codsen Ltd, Roy Revelt