mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-11 14:14:36 +08:00
DISABLE_THIRD_PARTY_CHECK=new npm module causes package-lock change We can get rid of a custom script and use ESLint for these rules. Additionally this means editors will highlight the issue in the editor. Change-Id: I552b52e7f07b4e7430b3f685dbc3b5fad36ffff2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2052167 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
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 = /*#__PURE__*/_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; |