Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chain-able-deps / dist / fp / propOr.js
Size: Mime:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var is_1 = require("../is");
var curry_1 = require("./curry");
/**
 * If the given, non-null object has an own property with the specified name,
 * returns the value of that property. Otherwise returns the provided default
 * value.
 * @since 5.0.0-beta.9
 *
 * @memberOf fp
 * @fork v0.6.0
 * @category Object
 * @sig a -> String -> Object -> a
 * @param {*} val The default value.
 * @param {String} p The name of the property to return.
 * @param {Object} obj The object to query.
 * @return {*} The value of given property of the supplied object or the default value.
 * @example
 *
 *      var alice = {
 *        name: 'ALICE',
 *        age: 101
 *      };
 *      var favorite = prop('favoriteLibrary');
 *      var favoriteWithDefault = propOr('Ramda', 'favoriteLibrary');
 *
 *      favorite(alice);  //=> undefined
 *      favoriteWithDefault(alice);  //=> 'Ramda'
 */
/**
 * this is ramda sig version
 */
// function propOr<Value, Prop extends keyof Value, Fallback = any>(
//   val: AnyArrayOrObj,
//   prop: Prop,
//   obj: Fallback
// ) {
//   // @note - with ts, figured out this `has` was backwards eh?
//   // return has(prop, obj) ? obj[prop] : val
//   return has(obj, prop) ? obj[prop] : val
// }
function propOr(obj, prop, fallback) {
    return is_1.has(obj, prop) ? obj[prop] : fallback;
}
exports.default = curry_1.default(3, propOr);
//# sourceMappingURL=propOr.js.map