import assignInWith from './assignInWith.js'; import attempt from './attempt.js'; import baseValues from './.internal/baseValues.js'; import customDefaultsAssignIn from './.internal/customDefaultsAssignIn.js'; import escapeStringChar from './.internal/escapeStringChar.js'; import isError from './isError.js'; import isIterateeCall from './.internal/isIterateeCall.js'; import keys from './keys.js'; import reInterpolate from './.internal/reInterpolate.js'; import templateSettings from './templateSettings.js'; import toString from './toString.js'; /** Used to match empty string literals in compiled template source. */ const reEmptyStringLeading = /\b__p \+= '';/g; const reEmptyStringMiddle = /\b(__p \+=) '' \+/g; const reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; /** * Used to match * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). */ const reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to ensure capturing order of template delimiters. */ const reNoMatch = /($^)/; /** Used to match unescaped characters in compiled string literals. */ const reUnescapedString = /['\n\r\u2028\u2029\\]/g; /** * Creates a compiled template function that can interpolate data properties * in "interpolate" delimiters, HTML-escape interpolated data properties in * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data * properties may be accessed as free variables in the template. If a setting * object is given, it takes precedence over `templateSettings` values. * * **Note:** In the development build `template` utilizes * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) * for easier debugging. * * For more information on precompiling templates see * [lodash's custom builds documentation](https://lodash.com/custom-builds). * * For more information on Chrome extension sandboxes see * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). * * @since 0.1.0 * @category String * @param {string} [string=''] The template string. * @param {Object} [options={}] The options object. * @param {RegExp} [options.escape=templateSettings.escape] * The HTML "escape" delimiter. * @param {RegExp} [options.evaluate=templateSettings.evaluate] * The "evaluate" delimiter. * @param {Object} [options.imports=templateSettings.imports] * An object to import into the template as free variables. * @param {RegExp} [options.interpolate=templateSettings.interpolate] * The "interpolate" delimiter. * @param {string} [options.sourceURL='templateSources[n]'] * The sourceURL of the compiled template. * @param {string} [options.variable='obj'] * The data object variable name. * @param- {Object} [guard] Enables use as an iteratee for methods like `map`. * @returns {Function} Returns the compiled template function. * @example * * // Use the "interpolate" delimiter to create a compiled template. * let compiled = template('hello <%= user %>!'); * compiled({ 'user': 'fred' }); * // => 'hello fred!' * * // Use the HTML "escape" delimiter to escape data property values. * let compiled = template('<%- value %>'); * compiled({ 'value': '