Comparing version 0.0.1 to 0.0.2
46
index.ts
export default function flatGroup<T extends Record<any, any>>( | ||
arr: Array<T>, | ||
keys: Array<string> | ||
): Record<string, Record<string, { | ||
// @ts-ignore | ||
keys: string[], | ||
[key: string]: Array<T> | ||
}>> { | ||
const groups: Record<string, any> = {}; | ||
arr: Array<T>, | ||
keys: Array<string> | ||
): Record< | ||
string, | ||
Record< | ||
string, | ||
{ | ||
// @ts-ignore | ||
keys: string[]; | ||
[key: string]: Array<T>; | ||
} | ||
> | ||
> { | ||
const groups: Record<string, any> = {}; | ||
for (const k of keys) { | ||
groups[k] = {}; | ||
const group = groups[k]; | ||
const keyOfGroups: Array<any> = (groups[k]["keys"] = []); | ||
for (const k of keys) { | ||
groups[k] = {}; | ||
const group = groups[k]; | ||
const keyOfGroups: Array<any> = (groups[k]["keys"] = []); | ||
for (const item of arr) { | ||
const value = item[k]; | ||
if (keyOfGroups.indexOf(value) === -1) keyOfGroups.push(value); | ||
for (const item of arr) { | ||
const value = item[k]; | ||
if (keyOfGroups.indexOf(value) === -1) keyOfGroups.push(value); | ||
const groupKey: string = String(value); | ||
if (groupKey in group) group[groupKey].push(item); | ||
else group[groupKey] = [item]; | ||
const groupKey: string = String(value); | ||
if (groupKey in group) group[groupKey].push(item); | ||
else group[groupKey] = [item]; | ||
} | ||
} | ||
} | ||
return groups; | ||
return groups; | ||
} |
{ | ||
"name": "flat-group", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A function for creating flat groups from items in array", | ||
"main": "/dist/index.js", | ||
"types": "/dist/index.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Jamesbarford/flat-group.git" | ||
}, | ||
"scripts": { | ||
@@ -8,0 +12,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
5182
4
43
1
166
0