[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports["default"] = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _renameKeys = _interopRequireDefault(require("./renameKeys"));
|
---|
| 7 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
---|
| 8 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
---|
| 9 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
---|
| 10 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
---|
| 11 | function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
---|
| 12 | function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
---|
| 13 | function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
---|
| 14 | /**
|
---|
| 15 | * Creates a new object with the own properties of the provided object, and the
|
---|
| 16 | * keys copied according to the keysMap object as `{oldKey: newKey}`.
|
---|
| 17 | * When no key from the keysMap is found, then a shallow clone of an object is returned.
|
---|
| 18 | *
|
---|
| 19 | * Keep in mind that in the case of keys conflict is behaviour undefined and
|
---|
| 20 | * the result may vary between various JS engines!
|
---|
| 21 | *
|
---|
| 22 | * @func copyKeys
|
---|
| 23 | * @memberOf RA
|
---|
| 24 | * @category Object
|
---|
| 25 | * @sig {a: b} -> {a: *} -> {b: *}
|
---|
| 26 | * @param {!Object} keysMap
|
---|
| 27 | * @param {!Object} obj
|
---|
| 28 | * @return {!Object} New object with copied keys
|
---|
| 29 | * @see {@link RA.renameKeys|renameKeys}
|
---|
| 30 | * @example
|
---|
| 31 | *
|
---|
| 32 | * copyKeys({ a: 'b' }, { a: true }); //=> { a: true, b: true }
|
---|
| 33 | * copyKeys({ a: 'b' }, { a: true, b: false }); //=> { a: true, b: true }
|
---|
| 34 | */
|
---|
| 35 | var copyKeys = (0, _ramda.curryN)(2, function (keysMap, obj) {
|
---|
| 36 | return _objectSpread(_objectSpread({}, obj), (0, _renameKeys["default"])(keysMap, obj));
|
---|
| 37 | });
|
---|
| 38 | var _default = copyKeys;
|
---|
| 39 | exports["default"] = _default; |
---|