lodash.template
Advanced tools
Comparing version 4.4.0 to 4.5.0
709
index.js
/** | ||
* lodash (Custom Build) <https://lodash.com/> | ||
* Lodash (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/> | ||
* Released under MIT license <https://lodash.com/license> | ||
@@ -12,2 +12,6 @@ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
/** Used to detect hot functions by number of calls within a span of milliseconds. */ | ||
var HOT_COUNT = 800, | ||
HOT_SPAN = 16; | ||
/** Used as references for various `Number` constants. */ | ||
@@ -19,7 +23,34 @@ var INFINITY = 1 / 0, | ||
var argsTag = '[object Arguments]', | ||
arrayTag = '[object Array]', | ||
asyncTag = '[object AsyncFunction]', | ||
boolTag = '[object Boolean]', | ||
dateTag = '[object Date]', | ||
domExcTag = '[object DOMException]', | ||
errorTag = '[object Error]', | ||
funcTag = '[object Function]', | ||
genTag = '[object GeneratorFunction]', | ||
symbolTag = '[object Symbol]'; | ||
mapTag = '[object Map]', | ||
numberTag = '[object Number]', | ||
nullTag = '[object Null]', | ||
objectTag = '[object Object]', | ||
proxyTag = '[object Proxy]', | ||
regexpTag = '[object RegExp]', | ||
setTag = '[object Set]', | ||
stringTag = '[object String]', | ||
symbolTag = '[object Symbol]', | ||
undefinedTag = '[object Undefined]', | ||
weakMapTag = '[object WeakMap]'; | ||
var arrayBufferTag = '[object ArrayBuffer]', | ||
dataViewTag = '[object DataView]', | ||
float32Tag = '[object Float32Array]', | ||
float64Tag = '[object Float64Array]', | ||
int8Tag = '[object Int8Array]', | ||
int16Tag = '[object Int16Array]', | ||
int32Tag = '[object Int32Array]', | ||
uint8Tag = '[object Uint8Array]', | ||
uint8ClampedTag = '[object Uint8ClampedArray]', | ||
uint16Tag = '[object Uint16Array]', | ||
uint32Tag = '[object Uint32Array]'; | ||
/** Used to match empty string literals in compiled template source. */ | ||
@@ -31,2 +62,8 @@ var reEmptyStringLeading = /\b__p \+= '';/g, | ||
/** | ||
* Used to match `RegExp` | ||
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). | ||
*/ | ||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g; | ||
/** | ||
* Used to match | ||
@@ -37,2 +74,5 @@ * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). | ||
/** Used to detect host constructors (Safari). */ | ||
var reIsHostCtor = /^\[object .+?Constructor\]$/; | ||
/** Used to detect unsigned integer values. */ | ||
@@ -47,2 +87,18 @@ var reIsUint = /^(?:0|[1-9]\d*)$/; | ||
/** Used to identify `toStringTag` values of typed arrays. */ | ||
var typedArrayTags = {}; | ||
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = | ||
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = | ||
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = | ||
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = | ||
typedArrayTags[uint32Tag] = true; | ||
typedArrayTags[argsTag] = typedArrayTags[arrayTag] = | ||
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = | ||
typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = | ||
typedArrayTags[errorTag] = typedArrayTags[funcTag] = | ||
typedArrayTags[mapTag] = typedArrayTags[numberTag] = | ||
typedArrayTags[objectTag] = typedArrayTags[regexpTag] = | ||
typedArrayTags[setTag] = typedArrayTags[stringTag] = | ||
typedArrayTags[weakMapTag] = false; | ||
/** Used to escape characters for inclusion in compiled string literals. */ | ||
@@ -67,2 +123,32 @@ var stringEscapes = { | ||
/** Detect free variable `exports`. */ | ||
var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; | ||
/** Detect free variable `module`. */ | ||
var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; | ||
/** Detect the popular CommonJS extension `module.exports`. */ | ||
var moduleExports = freeModule && freeModule.exports === freeExports; | ||
/** Detect free variable `process` from Node.js. */ | ||
var freeProcess = moduleExports && freeGlobal.process; | ||
/** Used to access faster Node.js helpers. */ | ||
var nodeUtil = (function() { | ||
try { | ||
// Use `util.types` for Node.js 10+. | ||
var types = freeModule && freeModule.require && freeModule.require('util').types; | ||
if (types) { | ||
return types; | ||
} | ||
// Legacy `process.binding('util')` for Node.js < 10. | ||
return freeProcess && freeProcess.binding && freeProcess.binding('util'); | ||
} catch (e) {} | ||
}()); | ||
/* Node.js helper references. */ | ||
var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; | ||
/** | ||
@@ -99,3 +185,3 @@ * A faster alternative to `Function#apply`, this function invokes `func` | ||
var index = -1, | ||
length = array ? array.length : 0, | ||
length = array == null ? 0 : array.length, | ||
result = Array(length); | ||
@@ -129,2 +215,15 @@ | ||
/** | ||
* The base implementation of `_.unary` without support for storing metadata. | ||
* | ||
* @private | ||
* @param {Function} func The function to cap arguments for. | ||
* @returns {Function} Returns the new capped function. | ||
*/ | ||
function baseUnary(func) { | ||
return function(value) { | ||
return func(value); | ||
}; | ||
} | ||
/** | ||
* The base implementation of `_.values` and `_.valuesIn` which creates an | ||
@@ -157,2 +256,14 @@ * array of `object` property values corresponding to the property names | ||
/** | ||
* Gets the value at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} [object] The object to query. | ||
* @param {string} key The key of the property to get. | ||
* @returns {*} Returns the property value. | ||
*/ | ||
function getValue(object, key) { | ||
return object == null ? undefined : object[key]; | ||
} | ||
/** | ||
* Creates a unary function that invokes `func` with its argument transformed. | ||
@@ -172,7 +283,20 @@ * | ||
/** Used for built-in method references. */ | ||
var objectProto = Object.prototype; | ||
var funcProto = Function.prototype, | ||
objectProto = Object.prototype; | ||
/** Used to detect overreaching core-js shims. */ | ||
var coreJsData = root['__core-js_shared__']; | ||
/** Used to resolve the decompiled source of functions. */ | ||
var funcToString = funcProto.toString; | ||
/** Used to check objects for own properties. */ | ||
var hasOwnProperty = objectProto.hasOwnProperty; | ||
/** Used to detect methods masquerading as native. */ | ||
var maskSrcKey = (function() { | ||
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); | ||
return uid ? ('Symbol(src)_1.' + uid) : ''; | ||
}()); | ||
/** | ||
@@ -183,11 +307,33 @@ * Used to resolve the | ||
*/ | ||
var objectToString = objectProto.toString; | ||
var nativeObjectToString = objectProto.toString; | ||
/** Used to infer the `Object` constructor. */ | ||
var objectCtorString = funcToString.call(Object); | ||
/** Used to detect if a method is native. */ | ||
var reIsNative = RegExp('^' + | ||
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') | ||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' | ||
); | ||
/** Built-in value references. */ | ||
var Symbol = root.Symbol, | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable; | ||
var Buffer = moduleExports ? root.Buffer : undefined, | ||
Symbol = root.Symbol, | ||
getPrototype = overArg(Object.getPrototypeOf, Object), | ||
propertyIsEnumerable = objectProto.propertyIsEnumerable, | ||
symToStringTag = Symbol ? Symbol.toStringTag : undefined; | ||
var defineProperty = (function() { | ||
try { | ||
var func = getNative(Object, 'defineProperty'); | ||
func({}, '', {}); | ||
return func; | ||
} catch (e) {} | ||
}()); | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeKeys = overArg(Object.keys, Object), | ||
nativeMax = Math.max; | ||
var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined, | ||
nativeKeys = overArg(Object.keys, Object), | ||
nativeMax = Math.max, | ||
nativeNow = Date.now; | ||
@@ -207,14 +353,22 @@ /** Used to convert symbols to primitives and strings. */ | ||
function arrayLikeKeys(value, inherited) { | ||
// Safari 8.1 makes `arguments.callee` enumerable in strict mode. | ||
// Safari 9 makes `arguments.length` enumerable in strict mode. | ||
var result = (isArray(value) || isArguments(value)) | ||
? baseTimes(value.length, String) | ||
: []; | ||
var isArr = isArray(value), | ||
isArg = !isArr && isArguments(value), | ||
isBuff = !isArr && !isArg && isBuffer(value), | ||
isType = !isArr && !isArg && !isBuff && isTypedArray(value), | ||
skipIndexes = isArr || isArg || isBuff || isType, | ||
result = skipIndexes ? baseTimes(value.length, String) : [], | ||
length = result.length; | ||
var length = result.length, | ||
skipIndexes = !!length; | ||
for (var key in value) { | ||
if ((inherited || hasOwnProperty.call(value, key)) && | ||
!(skipIndexes && (key == 'length' || isIndex(key, length)))) { | ||
!(skipIndexes && ( | ||
// Safari 9 has enumerable `arguments.length` in strict mode. | ||
key == 'length' || | ||
// Node.js 0.10 has enumerable non-index properties on buffers. | ||
(isBuff && (key == 'offset' || key == 'parent')) || | ||
// PhantomJS 2 has enumerable non-index properties on typed arrays. | ||
(isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || | ||
// Skip index properties. | ||
isIndex(key, length) | ||
))) { | ||
result.push(key); | ||
@@ -227,23 +381,22 @@ } | ||
/** | ||
* Used by `_.defaults` to customize its `_.assignIn` use. | ||
* Assigns `value` to `key` of `object` if the existing value is not equivalent | ||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* for equality comparisons. | ||
* | ||
* @private | ||
* @param {*} objValue The destination value. | ||
* @param {*} srcValue The source value. | ||
* @param {Object} object The object to modify. | ||
* @param {string} key The key of the property to assign. | ||
* @param {Object} object The parent object of `objValue`. | ||
* @returns {*} Returns the value to assign. | ||
* @param {*} value The value to assign. | ||
*/ | ||
function assignInDefaults(objValue, srcValue, key, object) { | ||
if (objValue === undefined || | ||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { | ||
return srcValue; | ||
function assignValue(object, key, value) { | ||
var objValue = object[key]; | ||
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || | ||
(value === undefined && !(key in object))) { | ||
baseAssignValue(object, key, value); | ||
} | ||
return objValue; | ||
} | ||
/** | ||
* Assigns `value` to `key` of `object` if the existing value is not equivalent | ||
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
* for equality comparisons. | ||
* The base implementation of `assignValue` and `assignMergeValue` without | ||
* value checks. | ||
* | ||
@@ -255,6 +408,11 @@ * @private | ||
*/ | ||
function assignValue(object, key, value) { | ||
var objValue = object[key]; | ||
if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || | ||
(value === undefined && !(key in object))) { | ||
function baseAssignValue(object, key, value) { | ||
if (key == '__proto__' && defineProperty) { | ||
defineProperty(object, key, { | ||
'configurable': true, | ||
'enumerable': true, | ||
'value': value, | ||
'writable': true | ||
}); | ||
} else { | ||
object[key] = value; | ||
@@ -265,2 +423,57 @@ } | ||
/** | ||
* The base implementation of `getTag` without fallbacks for buggy environments. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
*/ | ||
function baseGetTag(value) { | ||
if (value == null) { | ||
return value === undefined ? undefinedTag : nullTag; | ||
} | ||
return (symToStringTag && symToStringTag in Object(value)) | ||
? getRawTag(value) | ||
: objectToString(value); | ||
} | ||
/** | ||
* The base implementation of `_.isArguments`. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an `arguments` object, | ||
*/ | ||
function baseIsArguments(value) { | ||
return isObjectLike(value) && baseGetTag(value) == argsTag; | ||
} | ||
/** | ||
* The base implementation of `_.isNative` without bad shim checks. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a native function, | ||
* else `false`. | ||
*/ | ||
function baseIsNative(value) { | ||
if (!isObject(value) || isMasked(value)) { | ||
return false; | ||
} | ||
var pattern = isFunction(value) ? reIsNative : reIsHostCtor; | ||
return pattern.test(toSource(value)); | ||
} | ||
/** | ||
* The base implementation of `_.isTypedArray` without Node.js optimizations. | ||
* | ||
* @private | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`. | ||
*/ | ||
function baseIsTypedArray(value) { | ||
return isObjectLike(value) && | ||
isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; | ||
} | ||
/** | ||
* The base implementation of `_.keys` which doesn't treat sparse arrays as dense. | ||
@@ -316,23 +529,23 @@ * | ||
function baseRest(func, start) { | ||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0); | ||
return function() { | ||
var args = arguments, | ||
index = -1, | ||
length = nativeMax(args.length - start, 0), | ||
array = Array(length); | ||
while (++index < length) { | ||
array[index] = args[start + index]; | ||
} | ||
index = -1; | ||
var otherArgs = Array(start + 1); | ||
while (++index < start) { | ||
otherArgs[index] = args[index]; | ||
} | ||
otherArgs[start] = array; | ||
return apply(func, this, otherArgs); | ||
}; | ||
return setToString(overRest(func, start, identity), func + ''); | ||
} | ||
/** | ||
* The base implementation of `setToString` without support for hot loop shorting. | ||
* | ||
* @private | ||
* @param {Function} func The function to modify. | ||
* @param {Function} string The `toString` result. | ||
* @returns {Function} Returns `func`. | ||
*/ | ||
var baseSetToString = !defineProperty ? identity : function(func, string) { | ||
return defineProperty(func, 'toString', { | ||
'configurable': true, | ||
'enumerable': false, | ||
'value': constant(string), | ||
'writable': true | ||
}); | ||
}; | ||
/** | ||
* The base implementation of `_.toString` which doesn't convert nullish | ||
@@ -350,2 +563,6 @@ * values to empty strings. | ||
} | ||
if (isArray(value)) { | ||
// Recursively convert values (susceptible to call stack limits). | ||
return arrayMap(value, baseToString) + ''; | ||
} | ||
if (isSymbol(value)) { | ||
@@ -369,2 +586,3 @@ return symbolToString ? symbolToString.call(value) : ''; | ||
function copyObject(source, props, object, customizer) { | ||
var isNew = !object; | ||
object || (object = {}); | ||
@@ -382,3 +600,10 @@ | ||
assignValue(object, key, newValue === undefined ? source[key] : newValue); | ||
if (newValue === undefined) { | ||
newValue = source[key]; | ||
} | ||
if (isNew) { | ||
baseAssignValue(object, key, newValue); | ||
} else { | ||
assignValue(object, key, newValue); | ||
} | ||
} | ||
@@ -422,2 +647,62 @@ return object; | ||
/** | ||
* Used by `_.defaults` to customize its `_.assignIn` use to assign properties | ||
* of source objects to the destination object for all destination properties | ||
* that resolve to `undefined`. | ||
* | ||
* @private | ||
* @param {*} objValue The destination value. | ||
* @param {*} srcValue The source value. | ||
* @param {string} key The key of the property to assign. | ||
* @param {Object} object The parent object of `objValue`. | ||
* @returns {*} Returns the value to assign. | ||
*/ | ||
function customDefaultsAssignIn(objValue, srcValue, key, object) { | ||
if (objValue === undefined || | ||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { | ||
return srcValue; | ||
} | ||
return objValue; | ||
} | ||
/** | ||
* Gets the native function at `key` of `object`. | ||
* | ||
* @private | ||
* @param {Object} object The object to query. | ||
* @param {string} key The key of the method to get. | ||
* @returns {*} Returns the function if it's native, else `undefined`. | ||
*/ | ||
function getNative(object, key) { | ||
var value = getValue(object, key); | ||
return baseIsNative(value) ? value : undefined; | ||
} | ||
/** | ||
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. | ||
* | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the raw `toStringTag`. | ||
*/ | ||
function getRawTag(value) { | ||
var isOwn = hasOwnProperty.call(value, symToStringTag), | ||
tag = value[symToStringTag]; | ||
try { | ||
value[symToStringTag] = undefined; | ||
var unmasked = true; | ||
} catch (e) {} | ||
var result = nativeObjectToString.call(value); | ||
if (unmasked) { | ||
if (isOwn) { | ||
value[symToStringTag] = tag; | ||
} else { | ||
delete value[symToStringTag]; | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Checks if `value` is a valid array-like index. | ||
@@ -431,6 +716,9 @@ * | ||
function isIndex(value, length) { | ||
var type = typeof value; | ||
length = length == null ? MAX_SAFE_INTEGER : length; | ||
return !!length && | ||
(typeof value == 'number' || reIsUint.test(value)) && | ||
(value > -1 && value % 1 == 0 && value < length); | ||
(type == 'number' || | ||
(type != 'symbol' && reIsUint.test(value))) && | ||
(value > -1 && value % 1 == 0 && value < length); | ||
} | ||
@@ -463,2 +751,13 @@ | ||
/** | ||
* Checks if `func` has its source masked. | ||
* | ||
* @private | ||
* @param {Function} func The function to check. | ||
* @returns {boolean} Returns `true` if `func` is masked, else `false`. | ||
*/ | ||
function isMasked(func) { | ||
return !!maskSrcKey && (maskSrcKey in func); | ||
} | ||
/** | ||
* Checks if `value` is likely a prototype object. | ||
@@ -497,2 +796,101 @@ * | ||
/** | ||
* Converts `value` to a string using `Object.prototype.toString`. | ||
* | ||
* @private | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
*/ | ||
function objectToString(value) { | ||
return nativeObjectToString.call(value); | ||
} | ||
/** | ||
* A specialized version of `baseRest` which transforms the rest array. | ||
* | ||
* @private | ||
* @param {Function} func The function to apply a rest parameter to. | ||
* @param {number} [start=func.length-1] The start position of the rest parameter. | ||
* @param {Function} transform The rest array transform. | ||
* @returns {Function} Returns the new function. | ||
*/ | ||
function overRest(func, start, transform) { | ||
start = nativeMax(start === undefined ? (func.length - 1) : start, 0); | ||
return function() { | ||
var args = arguments, | ||
index = -1, | ||
length = nativeMax(args.length - start, 0), | ||
array = Array(length); | ||
while (++index < length) { | ||
array[index] = args[start + index]; | ||
} | ||
index = -1; | ||
var otherArgs = Array(start + 1); | ||
while (++index < start) { | ||
otherArgs[index] = args[index]; | ||
} | ||
otherArgs[start] = transform(array); | ||
return apply(func, this, otherArgs); | ||
}; | ||
} | ||
/** | ||
* Sets the `toString` method of `func` to return `string`. | ||
* | ||
* @private | ||
* @param {Function} func The function to modify. | ||
* @param {Function} string The `toString` result. | ||
* @returns {Function} Returns `func`. | ||
*/ | ||
var setToString = shortOut(baseSetToString); | ||
/** | ||
* Creates a function that'll short out and invoke `identity` instead | ||
* of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` | ||
* milliseconds. | ||
* | ||
* @private | ||
* @param {Function} func The function to restrict. | ||
* @returns {Function} Returns the new shortable function. | ||
*/ | ||
function shortOut(func) { | ||
var count = 0, | ||
lastCalled = 0; | ||
return function() { | ||
var stamp = nativeNow(), | ||
remaining = HOT_SPAN - (stamp - lastCalled); | ||
lastCalled = stamp; | ||
if (remaining > 0) { | ||
if (++count >= HOT_COUNT) { | ||
return arguments[0]; | ||
} | ||
} else { | ||
count = 0; | ||
} | ||
return func.apply(undefined, arguments); | ||
}; | ||
} | ||
/** | ||
* Converts `func` to its source code. | ||
* | ||
* @private | ||
* @param {Function} func The function to convert. | ||
* @returns {string} Returns the source code. | ||
*/ | ||
function toSource(func) { | ||
if (func != null) { | ||
try { | ||
return funcToString.call(func); | ||
} catch (e) {} | ||
try { | ||
return (func + ''); | ||
} catch (e) {} | ||
} | ||
return ''; | ||
} | ||
/** | ||
* Performs a | ||
@@ -551,7 +949,6 @@ * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) | ||
*/ | ||
function isArguments(value) { | ||
// Safari 8.1 makes `arguments.callee` enumerable in strict mode. | ||
return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') && | ||
(!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag); | ||
} | ||
var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { | ||
return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && | ||
!propertyIsEnumerable.call(value, 'callee'); | ||
}; | ||
@@ -613,29 +1010,19 @@ /** | ||
/** | ||
* This method is like `_.isArrayLike` except that it also checks if `value` | ||
* is an object. | ||
* Checks if `value` is a buffer. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @since 4.3.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an array-like object, | ||
* else `false`. | ||
* @returns {boolean} Returns `true` if `value` is a buffer, else `false`. | ||
* @example | ||
* | ||
* _.isArrayLikeObject([1, 2, 3]); | ||
* _.isBuffer(new Buffer(2)); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject(document.body.children); | ||
* // => true | ||
* | ||
* _.isArrayLikeObject('abc'); | ||
* _.isBuffer(new Uint8Array(2)); | ||
* // => false | ||
* | ||
* _.isArrayLikeObject(_.noop); | ||
* // => false | ||
*/ | ||
function isArrayLikeObject(value) { | ||
return isObjectLike(value) && isArrayLike(value); | ||
} | ||
var isBuffer = nativeIsBuffer || stubFalse; | ||
@@ -664,4 +1051,5 @@ /** | ||
} | ||
return (objectToString.call(value) == errorTag) || | ||
(typeof value.message == 'string' && typeof value.name == 'string'); | ||
var tag = baseGetTag(value); | ||
return tag == errorTag || tag == domExcTag || | ||
(typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); | ||
} | ||
@@ -687,6 +1075,9 @@ | ||
function isFunction(value) { | ||
if (!isObject(value)) { | ||
return false; | ||
} | ||
// The use of `Object#toString` avoids issues with the `typeof` operator | ||
// in Safari 8-9 which returns 'object' for typed array and other constructors. | ||
var tag = isObject(value) ? objectToString.call(value) : ''; | ||
return tag == funcTag || tag == genTag; | ||
// in Safari 9 which returns 'object' for typed arrays and other constructors. | ||
var tag = baseGetTag(value); | ||
return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; | ||
} | ||
@@ -752,3 +1143,3 @@ | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
return value != null && (type == 'object' || type == 'function'); | ||
} | ||
@@ -781,6 +1172,47 @@ | ||
function isObjectLike(value) { | ||
return !!value && typeof value == 'object'; | ||
return value != null && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is a plain object, that is, an object created by the | ||
* `Object` constructor or one with a `[[Prototype]]` of `null`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.8.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`. | ||
* @example | ||
* | ||
* function Foo() { | ||
* this.a = 1; | ||
* } | ||
* | ||
* _.isPlainObject(new Foo); | ||
* // => false | ||
* | ||
* _.isPlainObject([1, 2, 3]); | ||
* // => false | ||
* | ||
* _.isPlainObject({ 'x': 0, 'y': 0 }); | ||
* // => true | ||
* | ||
* _.isPlainObject(Object.create(null)); | ||
* // => true | ||
*/ | ||
function isPlainObject(value) { | ||
if (!isObjectLike(value) || baseGetTag(value) != objectTag) { | ||
return false; | ||
} | ||
var proto = getPrototype(value); | ||
if (proto === null) { | ||
return true; | ||
} | ||
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; | ||
return typeof Ctor == 'function' && Ctor instanceof Ctor && | ||
funcToString.call(Ctor) == objectCtorString; | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
@@ -804,6 +1236,25 @@ * | ||
return typeof value == 'symbol' || | ||
(isObjectLike(value) && objectToString.call(value) == symbolTag); | ||
(isObjectLike(value) && baseGetTag(value) == symbolTag); | ||
} | ||
/** | ||
* Checks if `value` is classified as a typed array. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 3.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a typed array, else `false`. | ||
* @example | ||
* | ||
* _.isTypedArray(new Uint8Array); | ||
* // => true | ||
* | ||
* _.isTypedArray([]); | ||
* // => false | ||
*/ | ||
var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; | ||
/** | ||
* Converts `value` to a string. An empty string is returned for `null` | ||
@@ -816,4 +1267,4 @@ * and `undefined` values. The sign of `-0` is preserved. | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {string} Returns the string. | ||
* @param {*} value The value to convert. | ||
* @returns {string} Returns the converted string. | ||
* @example | ||
@@ -985,3 +1436,4 @@ * | ||
* | ||
* // Use the ES delimiter as an alternative to the default "interpolate" delimiter. | ||
* // Use the ES template literal delimiter as an "interpolate" delimiter. | ||
* // Disable support by replacing the "interpolate" delimiter. | ||
* var compiled = _.template('hello ${ user }!'); | ||
@@ -1040,5 +1492,5 @@ * compiled({ 'user': 'pebbles' }); | ||
string = toString(string); | ||
options = assignInWith({}, options, settings, assignInDefaults); | ||
options = assignInWith({}, options, settings, customDefaultsAssignIn); | ||
var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults), | ||
var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), | ||
importsKeys = keys(imports), | ||
@@ -1062,3 +1514,10 @@ importsValues = baseValues(imports, importsKeys); | ||
// Use a sourceURL for easier debugging. | ||
var sourceURL = 'sourceURL' in options ? '//# sourceURL=' + options.sourceURL + '\n' : ''; | ||
// The sourceURL gets injected into the source that's eval-ed, so be careful | ||
// with lookup (in case of e.g. prototype pollution), and strip newlines if any. | ||
// A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection. | ||
var sourceURL = hasOwnProperty.call(options, 'sourceURL') | ||
? ('//# sourceURL=' + | ||
(options.sourceURL + '').replace(/[\r\n]/g, ' ') + | ||
'\n') | ||
: ''; | ||
@@ -1094,3 +1553,5 @@ string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { | ||
// code to add the data object to the top of the scope chain. | ||
var variable = options.variable; | ||
// Like with sourceURL, we take care to not check the option's prototype, | ||
// as this configuration is a code injection vector. | ||
var variable = hasOwnProperty.call(options, 'variable') && options.variable; | ||
if (!variable) { | ||
@@ -1167,2 +1628,64 @@ source = 'with (obj) {\n' + source + '\n}\n'; | ||
/** | ||
* Creates a function that returns `value`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 2.4.0 | ||
* @category Util | ||
* @param {*} value The value to return from the new function. | ||
* @returns {Function} Returns the new constant function. | ||
* @example | ||
* | ||
* var objects = _.times(2, _.constant({ 'a': 1 })); | ||
* | ||
* console.log(objects); | ||
* // => [{ 'a': 1 }, { 'a': 1 }] | ||
* | ||
* console.log(objects[0] === objects[1]); | ||
* // => true | ||
*/ | ||
function constant(value) { | ||
return function() { | ||
return value; | ||
}; | ||
} | ||
/** | ||
* This method returns the first argument it receives. | ||
* | ||
* @static | ||
* @since 0.1.0 | ||
* @memberOf _ | ||
* @category Util | ||
* @param {*} value Any value. | ||
* @returns {*} Returns `value`. | ||
* @example | ||
* | ||
* var object = { 'a': 1 }; | ||
* | ||
* console.log(_.identity(object) === object); | ||
* // => true | ||
*/ | ||
function identity(value) { | ||
return value; | ||
} | ||
/** | ||
* This method returns `false`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.13.0 | ||
* @category Util | ||
* @returns {boolean} Returns `false`. | ||
* @example | ||
* | ||
* _.times(2, _.stubFalse); | ||
* // => [false, false] | ||
*/ | ||
function stubFalse() { | ||
return false; | ||
} | ||
module.exports = template; |
{ | ||
"name": "lodash.template", | ||
"version": "4.4.0", | ||
"description": "The lodash method `_.template` exported as a module.", | ||
"version": "4.5.0", | ||
"description": "The Lodash method `_.template` exported as a module.", | ||
"homepage": "https://lodash.com/", | ||
@@ -9,7 +9,6 @@ "icon": "https://lodash.com/icon.svg", | ||
"keywords": "lodash-modularized, template", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"author": "John-David Dalton <john.david.dalton@gmail.com>", | ||
"contributors": [ | ||
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)", | ||
"Blaine Bublitz <blaine.bublitz@gmail.com> (https://github.com/phated)", | ||
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)" | ||
"John-David Dalton <john.david.dalton@gmail.com>", | ||
"Mathias Bynens <mathias@qiwi.be>" | ||
], | ||
@@ -19,5 +18,5 @@ "repository": "lodash/lodash", | ||
"dependencies": { | ||
"lodash._reinterpolate": "~3.0.0", | ||
"lodash._reinterpolate": "^3.0.0", | ||
"lodash.templatesettings": "^4.0.0" | ||
} | ||
} |
@@ -1,4 +0,4 @@ | ||
# lodash.template v4.4.0 | ||
# lodash.template v4.5.0 | ||
The [lodash](https://lodash.com/) method `_.template` exported as a [Node.js](https://nodejs.org/) module. | ||
The [Lodash](https://lodash.com/) method `_.template` exported as a [Node.js](https://nodejs.org/) module. | ||
@@ -18,2 +18,2 @@ ## Installation | ||
See the [documentation](https://lodash.com/docs#template) or [package source](https://github.com/lodash/lodash/blob/4.4.0-npm-packages/lodash.template) for more details. | ||
See the [documentation](https://lodash.com/docs#template) or [package source](https://github.com/lodash/lodash/blob/4.5.0-npm-packages/lodash.template) for more details. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50230
1530
Updatedlodash._reinterpolate@^3.0.0