-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
193 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** @license ISC License (c) copyright 2019 original and current authors */ | ||
/** @author Ian Hofmann-Hicks */ | ||
|
||
const curry = require('../core/curry') | ||
const isDefined = require('../core/isDefined') | ||
const isEmpty = require('../core/isEmpty') | ||
const isNil = require('../core/isNil') | ||
const isInteger = require('../core/isInteger') | ||
const isString = require('../core/isString') | ||
|
||
function fn(name) { | ||
function getPropOr(def, key, target) { | ||
if(!(isString(key) && !isEmpty(key) || isInteger(key))) { | ||
throw new TypeError(`${name}: Non-empty String or Integer required for second argument`) | ||
} | ||
|
||
if(isNil(target)) { | ||
return def | ||
} | ||
|
||
const value = target[key] | ||
|
||
return isDefined(value) | ||
? value | ||
: def | ||
} | ||
|
||
return curry(getPropOr) | ||
} | ||
|
||
// getPropOr : a -> (String | Integer) -> b -> c | ||
const getPropOr = | ||
fn('getPropOr') | ||
|
||
getPropOr.origFn = | ||
fn | ||
|
||
module.exports = getPropOr |
Oops, something went wrong.