Gathering detailed insights and metrics for objectools
Gathering detailed insights and metrics for objectools
npm install objectools
Typescript
Module System
Min. Node Version
Node Version
NPM Version
72.5
Supply Chain
98.9
Quality
78.3
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
4,950
Last Day
7
Last Week
44
Last Month
271
Last Year
3,755
1 Stars
9 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
objectools@4.0.0
Unpacked Size
31.47 kB
Size
6.47 kB
File Count
5
NPM Version
10.8.1
Node Version
22.4.1
Publised On
26 Aug 2024
Cumulative downloads
Total Downloads
Last day
600%
7
Compared to previous day
Last week
25.7%
44
Compared to previous week
Last month
-12.3%
271
Compared to previous month
Last year
214.2%
3,755
Compared to previous year
4
Useful easy-to-use utilities for JavaScript objects
.filter()
.map()
, .mapKeyValue
.keys
, .values
, .entries
, .length
.find()
, .findIndex()
, .findKey()
, .findValue()
.findLast()
, .findLastIndex()
, .findLastKey()
, .findLastValue()
.indexOf()
, .lastIndexOf()
, .indexOfKey()
.sort()
, .sortByValues()
.some()
, .every()
.omit()
.flip()
.reverse()
.transpose()
o(obj).filter(...)
).length
.keys
, .values
, .entries
Set
instead
of Array
for .keys
(
see: Why does Object.keys()
return an Array
instead of
a Set
?)1npm i objectools
or:
1yarn add objectools
1import o from 'objectools' 2 3o({a: 1, b: 2, c: 3}).filter(/*...*/) 4o({a: 1, b: 2, c: 3}).map(/*...*/) 5o({a: 1, c: 3, b: 2}).sort() 6o({...}) //... 7 8// Or chain methods: 9o({...}).oFilter(/*...*/).oMap(/*...*/).sort() // Don't prefix the last one with `o`. 10// I.e. don't write `.oSort()` if you don't want to countinue the chain.
.filter()
1o({a: 1, b: 2, c: 3}).filter((value) => value > 1) // {b: 2, c: 3} 2o({a: 1, b: 2, c: 3}).filter((_, key, index) => key < 'c' && index > 0) // {b: 2}
.map()
1o({a: 1, b: 2, c: 3}).map((value) => value * 2) // {a: 2, b: 4, c: 6} 2o({a: 1, b: 2, c: 3}).mapKeyValue((value, key) => [key.toUpperCase(), value - 1]) // {A: 0, B: 1, C: 2}
.keys
, .values
, .entries
, .length
1o({a: 1, b: 2, c: 3}).keys // Set {'a', 'b', 'c'} // Type: `Set<'a' | 'b' | 'c'>` 2o({a: 1, b: 2, c: 3}).values // [1, 2, 3] // Type: `number[]` 3o({a: 1, b: 2, c: 3}).entries // [['a', 1], ['b', 2], ['c', 3]] // Type: ['a' | 'b' | 'c', number][] 4o({a: 1, b: 2, c: 3}).length // 3
.find()
, .findIndex()
, .findKey()
, .findValue()
1o({a: 1, b: 2, c: 3}).find((value) => value > 1) // ['b', 2] 2o({a: 1, b: 2, c: 3}).findIndex((value) => value > 1) // 1 3o({a: 1, b: 2, c: 3}).findKey((value) => value > 1) // 'b' 4o({a: 1, b: 2, c: 3}).findValue((value) => value > 1) // 2
.findLast()
, .findLastIndex()
, .findLastKey()
, .findLastValue()
1o({a: 1, b: 2, c: 3}).findLast((value) => value > 1) // ['c', 3] 2o({a: 1, b: 2, c: 3}).findLastIndex((value) => value > 1) // 2 3o({a: 1, b: 2, c: 3}).findLastKey((value) => value > 1) // 'c' 4o({a: 1, b: 2, c: 3}).findLastValue((value) => value > 1) // 3
.indexOf()
, .lastIndexOf()
, .indexOfKey()
1o({a: 3, b: 3}).indexOf(3) // 0 2o({a: 3, b: 3}).lastIndexOf(3) // 1 3o({a: 3, b: 3}).indexOfKey('b') // 1
.sort()
, .sortByValues()
1o({b: 1, a: 3, c: 2}).sort() // {a: 3, b: 1, c: 2} 2o({b: 1, a: 3, c: 2}).sortByValues() // {b: 1, c: 2, a: 3}
.some()
, .every()
1o({a: 1, b: 2, c: 3}).some((value) => value > 1) // true 2o({a: 1, b: 2, c: 3}).every((value) => value > 1) // false
.omit()
1o({a: 1, b: 2, c: 3}).omit('b') // {a: 1, c: 3} 2o({a: 1, b: 2, c: 3}).omit('c', 'a') // {b: 2}
.flip()
1o({a: 'x', b: 'y'}).flip() // {x: 'a', y: 'b'}
.reverse()
1o({a: 'x', b: 'y'}).reverse() // {b: 'y', a: 'x'}
1o({b: 1, a: 2, c: 3}) 2 .oFilter((value) => value < 3) 3 .oMap((value) => value * 2) 4 .sort() 5// --> {a: 4, b: 2}
.transpose()
1o({ 2 x: {a: 1, b: 2}, 3 y: {a: 3, b: 4}, 4 z: {a: 5, b: 6}, 5}).transpose() 6// --> 7// { 8// a: {x: 1, y: 3, z: 5}, 9// b: {x: 2, y: 4, z: 6}, 10// }
You may need to add this to your "jest.config.js" file:
1export default { 2 transformIgnorePatterns: [ 3 // These packages are created based on modern javascript and use ESM module system (import/export). But Jest use 4 // old common-js module-system. So we need to transform these files using babel, too (like source files). Note that 5 // "node_modules" folder is ignored by default, and we've EXCLUDED these packages from this general rule (see `?!` 6 // in the below regex). 7 '/node_modules/(?!(objectools)/)', 8}
No vulnerabilities found.
No security vulnerabilities found.