source: node_modules/es-toolkit/dist/compat/object/invertBy.mjs

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 783 bytes
Line 
1import { identity } from '../../function/identity.mjs';
2import { isNil } from '../../predicate/isNil.mjs';
3import { iteratee } from '../util/iteratee.mjs';
4
5function invertBy(object, iteratee$1) {
6 const result = {};
7 if (isNil(object)) {
8 return result;
9 }
10 if (iteratee$1 == null) {
11 iteratee$1 = identity;
12 }
13 const keys = Object.keys(object);
14 const getString = iteratee(iteratee$1);
15 for (let i = 0; i < keys.length; i++) {
16 const key = keys[i];
17 const value = object[key];
18 const valueStr = getString(value);
19 if (Array.isArray(result[valueStr])) {
20 result[valueStr].push(key);
21 }
22 else {
23 result[valueStr] = [key];
24 }
25 }
26 return result;
27}
28
29export { invertBy };
Note: See TracBrowser for help on using the repository browser.