Gathering detailed insights and metrics for flatted-object
Gathering detailed insights and metrics for flatted-object
npm install flatted-object
Typescript
Module System
Node Version
NPM Version
68
Supply Chain
97.6
Quality
74.1
Maintenance
100
Vulnerability
98.2
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
855
Last Day
1
Last Week
1
Last Month
26
Last Year
185
3 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Aug 15, 2021
Minified
Minified + Gzipped
Latest Version
0.1.2
Package Id
flatted-object@0.1.2
Unpacked Size
9.75 kB
Size
2.77 kB
File Count
4
NPM Version
7.20.3
Node Version
14.17.3
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-87.5%
1
Compared to previous week
Last Month
85.7%
26
Compared to previous month
Last Year
-33.5%
185
Compared to previous year
1
Flattening objects is somewhat difficult as they could have infinitely many nested levels and some of those levels could be array and even other objects.
This module flattens an object to it's "flattest" size possible while still avoiding collapsing none related keys so that data integrity is maintained.
I love the flatted module and I wanted something that's equally fast and at the same time safe to use. Besides, "flatten-object" was already taken by another module which I didn't like much.
Install yarn add flatted-object
then:
1 2 const flatted = require('flatted-object'); 3 4 let obj = { 5 city: { 6 7 library: { 8 9 books: [{ 10 name: "How to flatten objects like a pro", 11 author: { 12 13 first: "Anthony", 14 second: "Mugendi" 15 } 16 }, 17 { 18 name: "How to flatten objects like a pro", 19 author: { 20 21 first: "Anthony", 22 second: "Mugendi" 23 } 24 } 25 ] 26 } 27 } 28 29 } 30 31 // adding cyclic data 32 obj.obj = obj; 33 34 // use without depthMaps 35 let flattenedObj = flatted(obj); 36 37 console.log(JSON.stringify(flattenedObj, 0, 4)); 38
This will log a flattened object as shown below:
1 2 { 3 "city": [ 4 { 5 "name": "How to flatten objects like a pro", 6 "author": { 7 "first": "Anthony", 8 "second": "Mugendi" 9 } 10 }, 11 { 12 "name": "How to flatten objects like a pro", 13 "author": { 14 "first": "Anthony", 15 "second": "Mugendi" 16 } 17 } 18 ], 19 "obj": "CIRCULAR <obj>" 20 } 21 22
NOTE: There is no way to deal with circular references so they are indicated as "CIRCULAR".
You can also pass an alternative rootKey that will be used as the root for the flattened object. Below is an example using the same object above.
1 2 ... 3 4 flattenedObj = flatted(obj, 'city_books'); 5 6 console.log(JSON.stringify(flattenedObj, 0, 4)); 7 8
This will output the following JSON:
1 2 { 3 "city_books": [ 4 { 5 "name": "How to flatten objects like a pro", 6 "author": { 7 "first": "Anthony", 8 "second": "Mugendi" 9 } 10 }, 11 { 12 "name": "How to flatten objects like a pro", 13 "author": { 14 "first": "Anthony", 15 "second": "Mugendi" 16 } 17 } 18 ], 19 "obj": "CIRCULAR <obj>" 20 } 21 22
Also the rootKey allows you to use dot notation to determine how the final structure of the object looks like.
Consider the following:
1 flattenedObj = flatted(obj, 'city.books'); 2 3 console.log(JSON.stringify(flattenedObj, 0, 4)); 4
Which outputs:
1 2 { 3 "city": { 4 "books": [ 5 { 6 "name": "How to flatten objects like a pro", 7 "author": { 8 "first": "Anthony", 9 "second": "Mugendi" 10 } 11 }, 12 { 13 "name": "How to flatten objects like a pro", 14 "author": { 15 "first": "Anthony", 16 "second": "Mugendi" 17 } 18 } 19 ] 20 }, 21 "obj": "CIRCULAR <obj>" 22 } 23 24
Enjoy!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
1 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More