js-partial-default-of
Version:
A partial to handle default values.
55 lines (47 loc) • 1.6 kB
JavaScript
/*
|----------------------------------------------------------------------------------------------------------------------
| A partial to handle default values.
|----------------------------------------------------------------------------------------------------------------------
*/
/**
* More information on [JavaScript Open Standards]{@link https://github.com/jsopenstd/jsopenstd}.
*
* @namespace js.partial
* @version 0.0.2
*
* @author Richard King <richrdkng@gmail.com> [GitHub]{@link https://github.com/richrdkng}
* @license [MIT]{@link https://github.com/jsopenstd/js-partial-foreach/blob/master/license.md}
*/
/**
* UMD - [returnExports.js pattern]{@link https://github.com/umdjs/umd/blob/master/templates/returnExports.js}
* For more information and license, check the link below:
* [UMD GitHub Repository]{@link https://github.com/umdjs/umd}
*/
(function(root, factory) {
// AMD
/* istanbul ignore next: ignore coverage test for UMD */
if (typeof define === 'function' && define.amd) {
define([], factory);
// CommonJS
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
// Browser
} else {
root.js_partial_defaultOf = factory();
}
}(this, function() {
'use strict';
/**
*
* @param {*} value A
* @param {*} defaultValue B
*
* @returns {*} C
*/
return function defaultOf(value, defaultValue) {
if (typeof value === 'undefined' || value === null) {
return defaultValue;
}
return value;
};
}));