@dankreiger/groop
Advanced tools
Comparing version 0.1.26 to 0.1.27
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createGroup=function(e){return function(t){return((e,t)=>t.reduce(((t,i)=>({...t,entities:{...t.entities,[i[e]]:[t.entities[i[e]]||[],i].flat()},ids:[...new Set((t.ids||[]).concat([i[e]]))]})),{entities:{},ids:[]}))(e,t)}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createGroup=function(e){return function(t){return((e,t)=>{const i={entities:{},ids:[]};for(let n=0;n<t.length;n++)i.entities[t[n][e]]?i.entities[t[n][e]].push(t[n]):(i.entities[t[n][e]]=[t[n]],i.ids.push(t[n][e]));return i})(e,t)}}; |
@@ -1,1 +0,1 @@ | ||
function t(t){return function(e){return((t,e)=>e.reduce(((e,i)=>({...e,entities:{...e.entities,[i[t]]:[e.entities[i[t]]||[],i].flat()},ids:[...new Set((e.ids||[]).concat([i[t]]))]})),{entities:{},ids:[]}))(t,e)}}export{t as createGroup}; | ||
function t(t){return function(e){return((t,e)=>{const n={entities:{},ids:[]};for(let i=0;i<e.length;i++)n.entities[e[i][t]]?n.entities[e[i][t]].push(e[i]):(n.entities[e[i][t]]=[e[i]],n.ids.push(e[i][t]));return n})(t,e)}}export{t as createGroup}; |
export type ObjectKey = string | number | symbol; | ||
export type EntityDict<Entity, Key extends ObjectKey> = { | ||
entities: Record<Key, Entity | undefined>; | ||
entities: Record<Key, Entity[] | undefined>; | ||
ids: Key[]; | ||
}; |
{ | ||
"name": "@dankreiger/groop", | ||
"version": "0.1.26", | ||
"version": "0.1.27", | ||
"description": "Normalize an array of objects by a property.", | ||
@@ -36,3 +36,5 @@ "homepage": "https://github.com/dankreiger/groop#readme", | ||
"size:analyze": "scripty", | ||
"test": "scripty" | ||
"test": "scripty", | ||
"test:ci": "scripty", | ||
"test:watch": "scripty" | ||
}, | ||
@@ -75,7 +77,7 @@ "config": { | ||
"lefthook": "1.2.2", | ||
"prettier": "2.7.1", | ||
"prettier": "2.8.0", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.79.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
"rollup-plugin-typescript2": "0.32.1", | ||
"rollup-plugin-typescript2": "0.34.1", | ||
"scripty": "2.1.1", | ||
@@ -82,0 +84,0 @@ "semantic-release": "19.0.5", |
@@ -20,32 +20,49 @@ # groop | ||
byAge(listGroup); | ||
/** | ||
* { | ||
* entities: { | ||
* '20': [ | ||
* { | ||
* age: 20, | ||
* name: 'Dan', | ||
* }, | ||
* ], | ||
* '22': [ | ||
* { | ||
* age: 22, | ||
* name: 'Woofer', | ||
* }, | ||
* ], | ||
* '5': [ | ||
* { | ||
* age: 5, | ||
* name: 'Dan', | ||
* }, | ||
* { | ||
* age: 5, | ||
* name: 'Puppy', | ||
* }, | ||
* ], | ||
* }, | ||
* ids: [5, 22, 20], | ||
* } | ||
*/ | ||
/** yields **/ | ||
const byName = createGroup('name'); | ||
{ | ||
entities: { | ||
'20': [ | ||
{ | ||
age: 20, | ||
name: 'Dan', | ||
}, | ||
], | ||
'22': [ | ||
{ | ||
age: 22, | ||
name: 'Woofer', | ||
}, | ||
], | ||
'5': [ | ||
{ | ||
age: 5, | ||
name: 'Dan', | ||
}, | ||
{ | ||
age: 5, | ||
name: 'Puppy', | ||
}, | ||
], | ||
}, | ||
ids: [5, 22, 20], | ||
} | ||
byName(listGroup); | ||
/** | ||
* { | ||
* entities: { | ||
* Dan: [ | ||
* { name: 'Dan', age: 5 }, | ||
* { name: 'Dan', age: 20 } | ||
* ], | ||
* Puppy: [ { name: 'Puppy', age: 5 } ], | ||
* Woofer: [ { name: 'Woofer', age: 22 } ] | ||
* }, | ||
* ids: [ 'Dan', 'Puppy', 'Woofer' ] | ||
* } | ||
*/ | ||
``` |
export type ObjectKey = string | number | symbol; | ||
export type EntityDict<Entity, Key extends ObjectKey> = { | ||
entities: Record<Key, Entity | undefined>; | ||
entities: Record<Key, Entity[] | undefined>; | ||
ids: Key[]; | ||
}; |
@@ -9,6 +9,7 @@ import { createGroup } from './createGroup'; | ||
]; | ||
describe('createGroup', () => { | ||
it('one', () => { | ||
const byId = createGroup('age'); | ||
expect(byId(listGroup)).toEqual({ | ||
const byAge = createGroup('age'); | ||
expect(byAge(listGroup)).toEqual({ | ||
entities: { | ||
@@ -15,0 +16,0 @@ '20': [ |
import type { EntityDict, ObjectKey } from '../../typings'; | ||
import { groupBy } from '../_internal'; | ||
import { groupBy } from '../__internal__'; | ||
@@ -4,0 +4,0 @@ export function createGroup<K extends ObjectKey>(key: K) { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
13223
41
271
68
1