Skip to content

Lodash - Properties

Lodash exposes a few utility properties directly on the _ object. These provide information about the library itself or configure certain behaviors, like templating.

PropertyDescription
_.VERSION(String): The semantic version number of the Lodash library currently being used. Useful for debugging or conditional logic based on Lodash version. Example: '4.17.21'.
_.templateSettings(Object): An object containing settings that configure the behavior of Lodash’s template functions (_.template). This includes defining the delimiters used for interpolation, evaluation, and escaping within template strings.
_.templateSettings.escape(RegExp): The regex used to detect template code for HTML-escaped interpolation. Defaults to / G.
_.templateSettings.evaluate(RegExp): The regex used to detect template code to be evaluated (executed). Defaults to / G.
_.templateSettings.imports(Object): An object whose properties are added to the imports variable within compiled templates. Useful for providing utility functions or data globally to templates. Defaults to {'\_': \_}.
_.templateSettings.interpolate(RegExp): The regex used to detect template code for plain interpolation. Defaults to /=([\s\S]+?)\%>/g.
_.templateSettings.variable(String): The name of the variable used to reference the data object passed to the compiled template. Defaults to 'obj'.

While _.VERSION is straightforward, _.templateSettings is relevant only if you use Lodash’s built-in templating (_.template). In modern web development, component-based frameworks (like React, Vue, Angular) or dedicated templating engines (like Handlebars) are more commonly used than _.template. However, if you do use it, these settings allow customization of the template syntax.

You can modify these settings globally, for example: _.templateSettings.interpolate = /{{([sS]+?)}}/g; to use Mustache-style delimiters.