UNPKG

ramda-extension

Version:

Helpful functions built on top of the mighty Ramda

40 lines (33 loc) 1.35 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _ramda = require("ramda"); var _splitByDot = _interopRequireDefault(require("./splitByDot")); var _argumentsToList = _interopRequireDefault(require("./argumentsToList")); var _overHead = _interopRequireDefault(require("./overHead")); /** * Makes a shallow clone of an object, setting or overriding the nodes required * to create the given path, and placing the specific value at the tail end of * that path. * * @func * @category Object * @param {String} path the dot path to set * @param {*} val The new value * @param {Object} obj The object to clone * @return {Object} A new object equivalent to the original except along the specified path. * @example * * R_.assocDotPath('a.b.c', 42, {a: {b: {c: 0}}}); //=> {a: {b: {c: 42}}} * * // Any missing or non-object keys in path will be overridden * R_.assocDotPath('a.b.c', 42, {a: 5}); //=> {a: {b: {c: 42}}} * * @sig String -> a -> b */ var assocDotPath = (0, _ramda.curryN)(2, (0, _ramda.compose)((0, _ramda.apply)(_ramda.assocPath), (0, _overHead.default)(_splitByDot.default), _argumentsToList.default)); var _default = assocDotPath; exports.default = _default;