shapey
Version:
A simple syntax for remapping objects, inspired by several of Ramda's spec based functions
29 lines (22 loc) • 1.3 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _curry = _interopRequireDefault(require("vanillas/curry"));
var _combine = _interopRequireDefault(require("./combine"));
var _mapSpec = _interopRequireDefault(require("./mapSpec"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Similar to [Ramda's applySpec()](http://ramdajs.com/docs/#applySpec), however the spec will be applied and then merged into the original input.
* Ramda's applySpec() will omit the original input, returning an object containing _only_ the props named in your spec, but this function here will apply the spec and then merge back it into the original input.
*
* @function
* @name mergeSpec
* @sig {k: v} -> {k: v} -> {k: v}
* @param {Object} spec An object whose values are functions which expect the entire object to be fed in as input. This is identical to the input you'd pass into applySpec()
* @param {Object} input An object to be mapped over (transformed)
* @returns {Object} The input object with all the transform functions applied at the named keys
*/
var _default = (0, _curry.default)(function (spec, value) {
return (0, _combine.default)(value, (0, _mapSpec.default)(spec, value));
});
exports.default = _default;