2016-06-01 11:21:26 -07:00
|
|
|
/**
|
2018-09-07 15:11:23 -07:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-06-01 11:21:26 -07:00
|
|
|
*
|
2017-09-24 13:48:13 -07:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-01 11:21:26 -07:00
|
|
|
*
|
|
|
|
|
* @flow
|
|
|
|
|
*/
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/*:: import type { ErrorMap } from './Types' */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* turns
|
|
|
|
|
* { 'MUCH ERROR': '0', 'SUCH WRONG': '1' }
|
|
|
|
|
* into
|
|
|
|
|
* { 0: 'MUCH ERROR', 1: 'SUCH WRONG' }
|
|
|
|
|
*/
|
2017-04-05 16:47:29 +01:00
|
|
|
function invertObject(targetObj /* : ErrorMap */) /* : ErrorMap */ {
|
2017-11-28 23:13:12 -02:00
|
|
|
const result = {};
|
|
|
|
|
const mapKeys = Object.keys(targetObj);
|
2016-06-01 11:21:26 -07:00
|
|
|
|
2018-02-09 16:11:22 +00:00
|
|
|
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
|
2017-11-28 23:13:12 -02:00
|
|
|
for (const originalKey of mapKeys) {
|
|
|
|
|
const originalVal = targetObj[originalKey];
|
2016-06-01 11:21:26 -07:00
|
|
|
|
|
|
|
|
result[originalVal] = originalKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = invertObject;
|