@dankreiger/groop
Advanced tools
Comparing version 0.1.20 to 0.1.22
import { Dict, EntityDict, ObjectKey } from './types'; | ||
export declare function createGroup<K extends ObjectKey>(key: K): <T extends Record<K, T[K]>>(items: T[]) => EntityDict<T, keyof T>; | ||
export declare function createGroup<K extends ObjectKey>(key: K): <T extends Record<K, T[K]>>(items: T[]) => EntityDict<T, T[K]>; | ||
export { EntityDict, Dict }; |
{ | ||
"name": "@dankreiger/groop", | ||
"version": "0.1.20", | ||
"version": "0.1.22", | ||
"description": "Normalize an array of objects by a property.", | ||
@@ -55,6 +55,6 @@ "homepage": "https://github.com/dankreiger/groop#readme", | ||
"@babel/runtime": "^7.18.3", | ||
"@commitlint/config-conventional": "^17.0.2", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@commitlint/config-conventional": "^17.0.2", | ||
"@semantic-release/changelog": "6.0.1", | ||
@@ -61,0 +61,0 @@ "@semantic-release/git": "10.0.1", |
@@ -8,19 +8,44 @@ # groop | ||
```ts | ||
import { groupBy } from '@dankreiger/groop'; | ||
import { createGroup } from '@dankreiger/groop'; | ||
groupBy('id', [ | ||
{ id: 3, name: 'Dan' }, | ||
{ id: 2, name: 'Puppy' }, | ||
{ id: 3, name: 'woofer' }, | ||
]); | ||
const listGroup = [ | ||
{ name: 'Dan', age: 5 }, | ||
{ name: 'Puppy', age: 5 }, | ||
{ name: 'Woofer', age: 22 }, | ||
{ name: 'Dan', age: 20 }, | ||
]; | ||
/** yields: | ||
const byAge = createGroup('age'); | ||
byAge(listGroup); | ||
/** yields **/ | ||
{ | ||
entities: { | ||
'2': [{ id: 2, name: 'Puppy' }], | ||
'3': [{ id: 3, name: 'woofer' }], | ||
'20': [ | ||
{ | ||
age: 20, | ||
name: 'Dan', | ||
}, | ||
], | ||
'22': [ | ||
{ | ||
age: 22, | ||
name: 'Woofer', | ||
}, | ||
], | ||
'5': [ | ||
{ | ||
age: 5, | ||
name: 'Dan', | ||
}, | ||
{ | ||
age: 5, | ||
name: 'Puppy', | ||
}, | ||
], | ||
}, | ||
ids: [3, 2, 3], | ||
ids: [5, 22, 20], | ||
} | ||
*/ | ||
``` |
@@ -22,3 +22,3 @@ import { Dict, EntityDict, ObjectKey } from './types'; | ||
items: T[] | ||
): EntityDict<T> { | ||
): EntityDict<T, T[K]> { | ||
return groupBy(key, items); | ||
@@ -25,0 +25,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8006
51