ramda-extension
Version:
Helpful functions built on top of the mighty Ramda
37 lines (32 loc) • 1.03 kB
JavaScript
;
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"));
/**
* If the given, non-null object has a value at the given dot path,
* returns the value at that path. Otherwise returns the provided default value.
*
* @func
* @category Object
*
* @param {any} default Default value if `path` does not exist.
* @param {String} path The dot path to use.
* @param {Object} obj
*
* @return {*} The data at `path` of the supplied object or the default value.
*
* @example
*
* R_.dotPathOr('N/A', 'a.b', { a: { b: 1 } }); // 1
* R_.dotPathOr('N/A', 'a.b', { a: { c: 1 } }); // "N/A"
*
* @sig a → String → {a} → a
*
*/
var dotPathOr = (0, _ramda.useWith)(_ramda.pathOr, [_ramda.identity, _splitByDot.default, _ramda.identity]);
var _default = dotPathOr;
exports.default = _default;