Socket
Socket
Sign inDemoInstall

lodash.template

Package Overview
Dependencies
Maintainers
3
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lodash.template - npm Package Compare versions

Comparing version 3.6.2 to 4.0.0

439

index.js
/**
* lodash 3.6.2 (Custom Build) <https://lodash.com/>
* Build: `lodash modern modularize exports="npm" -o ./`
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
* lodash 4.0.0 (Custom Build) <https://lodash.com/>
* Build: `lodash modularize exports="npm" -o ./`
* Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <https://lodash.com/license>
*/
var baseCopy = require('lodash._basecopy'),
baseToString = require('lodash._basetostring'),
baseValues = require('lodash._basevalues'),
isIterateeCall = require('lodash._isiterateecall'),
var arrayMap = require('lodash._arraymap'),
assignInWith = require('lodash.assigninwith'),
keys = require('lodash.keys'),
reInterpolate = require('lodash._reinterpolate'),
keys = require('lodash.keys'),
restParam = require('lodash.restparam'),
rest = require('lodash.rest'),
templateSettings = require('lodash.templatesettings');
/** Used as references for various `Number` constants. */
var INFINITY = 1 / 0,
MAX_SAFE_INTEGER = 9007199254740991;
/** `Object#toString` result references. */
var errorTag = '[object Error]';
var errorTag = '[object Error]',
funcTag = '[object Function]',
genTag = '[object GeneratorFunction]',
symbolTag = '[object Symbol]';

@@ -29,2 +34,5 @@ /** Used to match empty string literals in compiled template source. */

/** Used to detect unsigned integer values. */
var reIsUint = /^(?:0|[1-9]\d*)$/;
/** Used to ensure capturing order of template delimiters. */

@@ -47,2 +55,39 @@ var reNoMatch = /($^)/;

/**
* A faster alternative to `Function#apply`, this function invokes `func`
* with the `this` binding of `thisArg` and the arguments of `args`.
*
* @private
* @param {Function} func The function to invoke.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [args] The arguments to invoke `func` with.
* @returns {*} Returns the result of `func`.
*/
function apply(func, thisArg, args) {
var length = args ? args.length : 0;
switch (length) {
case 0: return func.call(thisArg);
case 1: return func.call(thisArg, args[0]);
case 2: return func.call(thisArg, args[0], args[1]);
case 3: return func.call(thisArg, args[0], args[1], args[2]);
}
return func.apply(thisArg, args);
}
/**
* The base implementation of `_.values` and `_.valuesIn` which creates an
* array of `object` property values corresponding to the property names
* of `props`.
*
* @private
* @param {Object} object The object to query.
* @param {Array} props The property names to get values for.
* @returns {Object} Returns the array of property values.
*/
function baseValues(object, props) {
return arrayMap(props, function(key) {
return object[key];
});
}
/**
* Used by `_.template` to escape characters for inclusion in compiled string literals.

@@ -59,14 +104,17 @@ *

/**
* Checks if `value` is object-like.
* Checks if `value` is a valid array-like index.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
function isIndex(value, length) {
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}
/** Used for native method references. */
var objectProto = Object.prototype;
/** Used for built-in method references. */
var objectProto = global.Object.prototype;

@@ -80,68 +128,141 @@ /** Used to check objects for own properties. */

*/
var objToString = objectProto.toString;
var objectToString = objectProto.toString;
/** Built-in value references. */
var _Symbol = global.Symbol;
/** Used to convert symbols to primitives and strings. */
var symbolProto = _Symbol ? _Symbol.prototype : undefined,
symbolToString = _Symbol ? symbolProto.toString : undefined;
/**
* Used by `_.template` to customize its `_.assign` use.
* Used by `_.defaults` to customize its `_.assignIn` use.
*
* **Note:** This function is like `assignDefaults` except that it ignores
* inherited property values when checking if a property is `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 assignInDefaults(objValue, srcValue, key, object) {
if (objValue === undefined ||
(eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
return srcValue;
}
return objValue;
}
/**
* The base implementation of `_.property` without support for deep paths.
*
* @private
* @param {*} objectValue The destination object property value.
* @param {*} sourceValue The source object property value.
* @param {string} key The key associated with the object and source values.
* @param {Object} object The destination object.
* @returns {*} Returns the value to assign to the destination object.
* @param {string} key The key of the property to get.
* @returns {Function} Returns the new function.
*/
function assignOwnDefaults(objectValue, sourceValue, key, object) {
return (objectValue === undefined || !hasOwnProperty.call(object, key))
? sourceValue
: objectValue;
function baseProperty(key) {
return function(object) {
return object == null ? undefined : object[key];
};
}
/**
* A specialized version of `_.assign` for customizing assigned values without
* support for argument juggling, multiple sources, and `this` binding `customizer`
* functions.
* Gets the "length" property value of `object`.
*
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
* that affects Safari on at least iOS 8.1-8.3 ARM64.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} customizer The function to customize assigned values.
* @returns {Object} Returns `object`.
* @param {Object} object The object to query.
* @returns {*} Returns the "length" value.
*/
function assignWith(object, source, customizer) {
var index = -1,
props = keys(source),
length = props.length;
var getLength = baseProperty('length');
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? (result !== value) : (value === value)) ||
(value === undefined && !(key in object))) {
object[key] = result;
}
/**
* Checks if the provided arguments are from an iteratee call.
*
* @private
* @param {*} value The potential iteratee value argument.
* @param {*} index The potential iteratee index or key argument.
* @param {*} object The potential iteratee object argument.
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
*/
function isIterateeCall(value, index, object) {
if (!isObject(object)) {
return false;
}
return object;
var type = typeof index;
if (type == 'number'
? (isArrayLike(object) && isIndex(index, object.length))
: (type == 'string' && index in object)) {
return eq(object[index], value);
}
return false;
}
/**
* The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `customizer` functions.
* Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* comparison between two values to determine if they are equivalent.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @returns {Object} Returns `object`.
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to compare.
* @param {*} other The other value to compare.
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
* @example
*
* var object = { 'user': 'fred' };
* var other = { 'user': 'fred' };
*
* _.eq(object, object);
* // => true
*
* _.eq(object, other);
* // => false
*
* _.eq('a', 'a');
* // => true
*
* _.eq('a', Object('a'));
* // => false
*
* _.eq(NaN, NaN);
* // => true
*/
function baseAssign(object, source) {
return source == null
? object
: baseCopy(source, keys(source), object);
function eq(value, other) {
return value === other || (value !== value && other !== other);
}
/**
* Checks if `value` is array-like. A value is considered array-like if it's
* not a function and has a `value.length` that's an integer greater than or
* equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
*
* @static
* @memberOf _
* @type Function
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
* @example
*
* _.isArrayLike([1, 2, 3]);
* // => true
*
* _.isArrayLike(document.body.children);
* // => true
*
* _.isArrayLike('abc');
* // => true
*
* _.isArrayLike(_.noop);
* // => false
*/
function isArrayLike(value) {
return value != null &&
!(typeof value == 'function' && isFunction(value)) && isLength(getLength(value));
}
/**
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,

@@ -164,6 +285,172 @@ * `SyntaxError`, `TypeError`, or `URIError` object.

function isError(value) {
return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
return isObjectLike(value) &&
typeof value.message == 'string' && objectToString.call(value) == errorTag;
}
/**
* Checks if `value` is classified as a `Function` object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isFunction(_);
* // => true
*
* _.isFunction(/abc/);
* // => false
*/
function isFunction(value) {
// The use of `Object#toString` avoids issues with the `typeof` operator
// in Safari 8 which returns 'object' for typed array constructors, and
// PhantomJS 1.9 which returns 'function' for `NodeList` instances.
var tag = isObject(value) ? objectToString.call(value) : '';
return tag == funcTag || tag == genTag;
}
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is loosely based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
* @example
*
* _.isLength(3);
* // => true
*
* _.isLength(Number.MIN_VALUE);
* // => false
*
* _.isLength(Infinity);
* // => false
*
* _.isLength('3');
* // => false
*/
function isLength(value) {
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
}
/**
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
* @example
*
* _.isObject({});
* // => true
*
* _.isObject([1, 2, 3]);
* // => true
*
* _.isObject(_.noop);
* // => true
*
* _.isObject(null);
* // => false
*/
function isObject(value) {
// Avoid a V8 JIT bug in Chrome 19-20.
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
var type = typeof value;
return !!value && (type == 'object' || type == 'function');
}
/**
* Checks if `value` is object-like. A value is object-like if it's not `null`
* and has a `typeof` result of "object".
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
* @example
*
* _.isObjectLike({});
* // => true
*
* _.isObjectLike([1, 2, 3]);
* // => true
*
* _.isObjectLike(_.noop);
* // => false
*
* _.isObjectLike(null);
* // => false
*/
function isObjectLike(value) {
return !!value && typeof value == 'object';
}
/**
* Checks if `value` is classified as a `Symbol` primitive or object.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
* @example
*
* _.isSymbol(Symbol.iterator);
* // => true
*
* _.isSymbol('abc');
* // => false
*/
function isSymbol(value) {
return typeof value == 'symbol' ||
(isObjectLike(value) && objectToString.call(value) == symbolTag);
}
/**
* Converts `value` to a string if it's not one. An empty string is returned
* for `null` and `undefined` values. The sign of `-0` is preserved.
*
* @static
* @memberOf _
* @category Lang
* @param {*} value The value to process.
* @returns {string} Returns the string.
* @example
*
* _.toString(null);
* // => ''
*
* _.toString(-0);
* // => '-0'
*
* _.toString([1, 2, 3]);
* // => '1,2,3'
*/
function toString(value) {
// Exit early for strings to avoid a performance hit in some environments.
if (typeof value == 'string') {
return value;
}
if (value == null) {
return '';
}
if (isSymbol(value)) {
return _Symbol ? symbolToString.call(value) : '';
}
var result = (value + '');
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
}
/**
* Creates a compiled template function that can interpolate data properties

@@ -196,3 +483,3 @@ * in "interpolate" delimiters, HTML-escape interpolated data properties in

* @param {string} [options.variable] The data object variable name.
* @param- {Object} [otherOptions] Enables the legacy `options` param signature.
* @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
* @returns {Function} Returns the compiled template function.

@@ -265,3 +552,3 @@ * @example

*/
function template(string, options, otherOptions) {
function template(string, options, guard) {
// Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)

@@ -271,9 +558,9 @@ // and Laura Doktorova's doT.js (https://github.com/olado/doT).

if (otherOptions && isIterateeCall(string, options, otherOptions)) {
options = otherOptions = undefined;
if (guard && isIterateeCall(string, options, guard)) {
options = undefined;
}
string = baseToString(string);
options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
string = toString(string);
options = assignInWith({}, options, settings, assignInDefaults);
var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
importsKeys = keys(imports),

@@ -319,4 +606,4 @@ importsValues = baseValues(imports, importsKeys);

// The JS engine embedded in Adobe products requires returning the `match`
// string in order to produce the correct `offset` value.
// The JS engine embedded in Adobe products needs `match` returned in
// order to produce the correct `offset` value.
return match;

@@ -372,7 +659,7 @@ });

* Attempts to invoke `func`, returning either the result or the caught error
* object. Any additional arguments are provided to `func` when it is invoked.
* object. Any additional arguments are provided to `func` when it's invoked.
*
* @static
* @memberOf _
* @category Utility
* @category Util
* @param {Function} func The function to attempt.

@@ -391,6 +678,6 @@ * @returns {*} Returns the `func` result or error object.

*/
var attempt = restParam(function(func, args) {
var attempt = rest(function(func, args) {
try {
return func.apply(undefined, args);
} catch(e) {
return apply(func, undefined, args);
} catch (e) {
return isError(e) ? e : new Error(e);

@@ -397,0 +684,0 @@ }

21

package.json
{
"name": "lodash.template",
"version": "3.6.2",
"description": "The modern build of lodash’s `_.template` as a module.",
"version": "4.0.0",
"description": "The lodash method `_.template` exported as a module.",
"homepage": "https://lodash.com/",
"icon": "https://lodash.com/icon.svg",
"license": "MIT",
"keywords": "lodash, lodash-modularized, stdlib, util",
"keywords": "lodash, lodash-modularized, stdlib, util, template",
"author": "John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
"contributors": [
"John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)",
"Benjamin Tan <demoneaux@gmail.com> (https://d10.github.io/)",
"Blaine Bublitz <blaine@iceddev.com> (http://www.iceddev.com/)",
"Kit Cambridge <github@kitcambridge.be> (http://kitcambridge.be/)",
"Blaine Bublitz <blaine@iceddev.com> (https://github.com/phated)",
"Mathias Bynens <mathias@qiwi.be> (https://mathiasbynens.be/)"

@@ -20,12 +18,9 @@ ],

"dependencies": {
"lodash._basecopy": "^3.0.0",
"lodash._basetostring": "^3.0.0",
"lodash._basevalues": "^3.0.0",
"lodash._isiterateecall": "^3.0.0",
"lodash._arraymap": "^3.0.0",
"lodash._reinterpolate": "^3.0.0",
"lodash.escape": "^3.0.0",
"lodash.keys": "^3.0.0",
"lodash.restparam": "^3.0.0",
"lodash.assigninwith": "^4.0.0",
"lodash.keys": "^4.0.0",
"lodash.rest": "^4.0.0",
"lodash.templatesettings": "^3.0.0"
}
}

@@ -1,4 +0,4 @@

# lodash.template v3.6.2
# lodash.template v4.0.0
The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash’s](https://lodash.com/) `_.template` exported as a [Node.js](http://nodejs.org/)/[io.js](https://iojs.org/) module.
The [lodash](https://lodash.com/) method `_.template` exported as a [Node.js](https://nodejs.org/) module.

@@ -8,3 +8,2 @@ ## Installation

Using npm:
```bash

@@ -15,4 +14,3 @@ $ {sudo -H} npm i -g npm

In Node.js/io.js:
In Node.js:
```js

@@ -22,2 +20,2 @@ var template = require('lodash.template');

See the [documentation](https://lodash.com/docs#template) or [package source](https://github.com/lodash/lodash/blob/3.6.2-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.0.0-npm-packages/lodash.template) for more details.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc