lodash-es#groupBy TypeScript Examples
The following examples show how to use
lodash-es#groupBy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: mock-filesystem-plugin.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
async readdir(options: ReaddirOptions): Promise<ReaddirResult> {
const directorys = groupBy([...this.files.keys()], path =>
path.substring(0, path.lastIndexOf('/'))
);
const targetDirectory = `${options.directory ?? ''}${options.path}`;
const directory = directorys[targetDirectory];
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!directory) {
return { files: [] };
}
return {
files: directory.map(filePath =>
filePath.replace(RegExp(`^${targetDirectory}`), '')
),
};
}
Example #2
Source File: old-proof-adapter.ts From capture-lite with GNU General Public License v3.0 | 6 votes |
/**
* Group by the key. The returned collection does not have the original key property.
*/
function groupObjectsBy<T extends Record<string, any>>(
objects: T[],
key: string
) {
return mapValues(groupBy(objects, key), values =>
values.map(v => {
delete v[key];
return v;
})
);
}
Example #3
Source File: capture-tab.component.ts From capture-lite with GNU General Public License v3.0 | 5 votes |
readonly capturesByDate$ = this.proofs$.pipe(
map(proofs => proofs.sort((a, b) => b.timestamp - a.timestamp)),
map(proofs =>
groupBy(proofs, proof =>
formatDate(proof.timestamp, 'yyyy/MM/dd', 'en-US')
)
)
);