mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add basePropertyOf helper.
This commit is contained in:
51
lodash.js
51
lodash.js
@@ -781,6 +781,32 @@
|
|||||||
return length ? (baseSum(array, iteratee) / length) : NAN;
|
return length ? (baseSum(array, iteratee) / length) : NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.property` without support for deep paths.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} key The key of the property to get.
|
||||||
|
* @returns {Function} Returns the new accessor function.
|
||||||
|
*/
|
||||||
|
function baseProperty(key) {
|
||||||
|
return function(object) {
|
||||||
|
return object == null ? undefined : object[key];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The base implementation of `_.propertyOf` without support for deep paths.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to query.
|
||||||
|
* @returns {Function} Returns the new accessor function.
|
||||||
|
*/
|
||||||
|
function basePropertyOf(object) {
|
||||||
|
return function(key) {
|
||||||
|
return object == null ? undefined : object[key];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.reduce` and `_.reduceRight`, without support
|
* The base implementation of `_.reduce` and `_.reduceRight`, without support
|
||||||
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
|
||||||
@@ -992,9 +1018,7 @@
|
|||||||
* @param {string} letter The matched letter to deburr.
|
* @param {string} letter The matched letter to deburr.
|
||||||
* @returns {string} Returns the deburred letter.
|
* @returns {string} Returns the deburred letter.
|
||||||
*/
|
*/
|
||||||
function deburrLetter(letter) {
|
var deburrLetter = basePropertyOf(deburredLetters);
|
||||||
return deburredLetters[letter];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.escape` to convert characters to HTML entities.
|
* Used by `_.escape` to convert characters to HTML entities.
|
||||||
@@ -1003,9 +1027,7 @@
|
|||||||
* @param {string} chr The matched character to escape.
|
* @param {string} chr The matched character to escape.
|
||||||
* @returns {string} Returns the escaped character.
|
* @returns {string} Returns the escaped character.
|
||||||
*/
|
*/
|
||||||
function escapeHtmlChar(chr) {
|
var escapeHtmlChar = basePropertyOf(htmlEscapes);
|
||||||
return htmlEscapes[chr];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by `_.template` to escape characters for inclusion in compiled string literals.
|
* Used by `_.template` to escape characters for inclusion in compiled string literals.
|
||||||
@@ -1192,9 +1214,7 @@
|
|||||||
* @param {string} chr The matched character to unescape.
|
* @param {string} chr The matched character to unescape.
|
||||||
* @returns {string} Returns the unescaped character.
|
* @returns {string} Returns the unescaped character.
|
||||||
*/
|
*/
|
||||||
function unescapeHtmlChar(chr) {
|
var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
|
||||||
return htmlUnescapes[chr];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -3370,19 +3390,6 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `_.property` without support for deep paths.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {string} key The key of the property to get.
|
|
||||||
* @returns {Function} Returns the new accessor function.
|
|
||||||
*/
|
|
||||||
function baseProperty(key) {
|
|
||||||
return function(object) {
|
|
||||||
return object == null ? undefined : object[key];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A specialized version of `baseProperty` which supports deep paths.
|
* A specialized version of `baseProperty` which supports deep paths.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user