swc/bundler/tests/.cache/deno/b9826eb439990f095330b27e4d1e482e027286a6.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

47 lines
1.1 KiB
TypeScript

// Loaded from https://deno.land/x/ramda@v0.27.2/source/invert.js
import _curry1 from './internal/_curry1.js';
import _has from './internal/_has.js';
import keys from './keys.js';
/**
* Same as [`R.invertObj`](#invertObj), however this accounts for objects with
* duplicate values by putting the values into an array.
*
* @func
* @memberOf R
* @since v0.9.0
* @category Object
* @sig {s: x} -> {x: [ s, ... ]}
* @param {Object} obj The object or array to invert
* @return {Object} out A new object with keys in an array.
* @see R.invertObj
* @example
*
* const raceResultsByFirstName = {
* first: 'alice',
* second: 'jake',
* third: 'alice',
* };
* R.invert(raceResultsByFirstName);
* //=> { 'alice': ['first', 'third'], 'jake':['second'] }
*/
var invert = _curry1(function invert(obj) {
var props = keys(obj);
var len = props.length;
var idx = 0;
var out = {};
while (idx < len) {
var key = props[idx];
var val = obj[key];
var list = _has(val, out) ? out[val] : (out[val] = []);
list[list.length] = key;
idx += 1;
}
return out;
});
export default invert;