lukeed / flattie Goto Github PK
View Code? Open in Web Editor NEWA tiny (203B) and fast utility to flatten an object with customizable glue
License: MIT License
A tiny (203B) and fast utility to flatten an object with customizable glue
License: MIT License
Saw your new version last week and had to check if it could replace the one I've written. Among the test cases I've used is the Reddit JSON output, i.e.: https://www.reddit.com/r/cute.json
The one thing missing in flattie is keeping empty arrays or objects. I very much depend on the output to be reversible (unflatten(flatten(input)) deep equal to input), so I can't replace my implementation (yet).
Could keepNullish also keep other empty structures or could you change it to keepEmpty = <none, null, all>?
PS: Additional info about why I'm even flattening. I'm using a DB that holds JSON records, but only the first level can be indexed (i.e. no '.' inside the attribute selector). The API on-top does now transparent flattening/unflattening on write&read to make creating indexes easier. But consumers of the API would see the magic if empty structs are dropped.
Right now I'm using a less-awesome library for merging objects as part of some JSON:API tooling, but specs for JSON:API treat null
as a meaningful value (used to specify deleting a property on a sparse update).
I see you're checking for null explicitly if (val == null)
I'm wondering if there might be a way to specify keeping null
?
$ npm install --save flat-obj
...
+ [email protected]
$ node
> flatObj = require('flat-obj');
[Function: flatten]
> flatObj({a: null, b: 'c', d: [1,2] })
{ b: 'c', d: [ {}, {} ] }
> flatObj({a: null, b: 'c', d: [1,2], e: { f: ['g', 'h']}})
{ b: 'c', d: [ {}, {} ], e_f: [ { '0': 'g' }, { '0': 'h' } ] }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.