1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ejs = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
3 * EJS Embedded JavaScript templates
4 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 * @file Embedded JavaScript templating engine. {@link http://ejs.co}
24 * @author Matthew Eernisse <mde@fleegix.org>
25 * @author Tiancheng "Timothy" Gu <timothygu99@gmail.com>
27 * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
31 * EJS internal functions.
33 * Technically this "module" lies in the same file as {@link module:ejs}, for
34 * the sake of organization all the private functions re grouped into this
37 * @module ejs-internal
42 * Embedded JavaScript templating engine.
48 var fs = require('fs');
49 var path = require('path');
50 var utils = require('./utils');
52 var scopeOptionWarned = false;
54 var _VERSION_STRING = require('../package.json').version;
55 var _DEFAULT_OPEN_DELIMITER = '<';
56 var _DEFAULT_CLOSE_DELIMITER = '>';
57 var _DEFAULT_DELIMITER = '%';
58 var _DEFAULT_LOCALS_NAME = 'locals';
60 var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
61 var _OPTS_PASSABLE_WITH_DATA = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
62 'client', '_with', 'rmWhitespace', 'strict', 'filename', 'async'];
63 // We don't allow 'cache' option to be passed in the data obj for
64 // the normal `render` call, but this is where Express 2 & 3 put it
65 // so we make an exception for `renderFile`
66 var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat('cache');
70 * EJS template function cache. This can be a LRU object from lru-cache NPM
71 * module. By default, it is {@link module:utils.cache}, a simple in-process
72 * cache that grows continuously.
77 exports.cache = utils.cache;
80 * Custom file loader. Useful for template preprocessing or restricting access
81 * to a certain part of the filesystem.
86 exports.fileLoader = fs.readFileSync;
89 * Name of the object containing the locals.
91 * This variable is overridden by {@link Options}`.localsName` if it is not
98 exports.localsName = _DEFAULT_LOCALS_NAME;
101 * Promise implementation -- defaults to the native implementation if available
102 * This is mostly just for testability
104 * @type {PromiseConstructorLike}
108 exports.promiseImpl = (new Function('return this;'))().Promise;
111 * Get the path to the included file from the parent file path and the
114 * @param {String} name specified path
115 * @param {String} filename parent file path
116 * @param {Boolean} [isDir=false] whether the parent file path is a directory
119 exports.resolveInclude = function(name, filename, isDir) {
120 var dirname = path.dirname;
121 var extname = path.extname;
122 var resolve = path.resolve;
123 var includePath = resolve(isDir ? filename : dirname(filename), name);
124 var ext = extname(name);
126 includePath += '.ejs';
132 * Try to resolve file path on multiple directories
134 * @param {String} name specified path
135 * @param {Array<String>} paths list of possible parent directory paths
138 function resolvePaths(name, paths) {
140 if (paths.some(function (v) {
141 filePath = exports.resolveInclude(name, v, true);
142 return fs.existsSync(filePath);
149 * Get the path to the included file by Options
151 * @param {String} path specified path
152 * @param {Options} options compilation options
155 function getIncludePath(path, options) {
158 var views = options.views;
159 var match = /^[A-Za-z]+:\\|^\//.exec(path);
162 if (match && match.length) {
163 path = path.replace(/^\/*/, '');
164 if (Array.isArray(options.root)) {
165 includePath = resolvePaths(path, options.root);
167 includePath = exports.resolveInclude(path, options.root || '/', true);
172 // Look relative to a passed filename first
173 if (options.filename) {
174 filePath = exports.resolveInclude(path, options.filename);
175 if (fs.existsSync(filePath)) {
176 includePath = filePath;
179 // Then look in any views directories
180 if (!includePath && Array.isArray(views)) {
181 includePath = resolvePaths(path, views);
183 if (!includePath && typeof options.includer !== 'function') {
184 throw new Error('Could not find the include file "' +
185 options.escapeFunction(path) + '"');
192 * Get the template from a string or a file, either compiled on-the-fly or
193 * read from cache (if enabled), and cache the template if needed.
195 * If `template` is not set, the file specified in `options.filename` will be
198 * If `options.cache` is true, this function reads the file from
199 * `options.filename` so it must be set prior to calling this function.
201 * @memberof module:ejs-internal
202 * @param {Options} options compilation options
203 * @param {String} [template] template source
204 * @return {(TemplateFunction|ClientFunction)}
205 * Depending on the value of `options.client`, either type might be returned.
209 function handleCache(options, template) {
211 var filename = options.filename;
212 var hasTemplate = arguments.length > 1;
216 throw new Error('cache option requires a filename');
218 func = exports.cache.get(filename);
223 template = fileLoader(filename).toString().replace(_BOM, '');
226 else if (!hasTemplate) {
227 // istanbul ignore if: should not happen at all
229 throw new Error('Internal EJS error: no file name or template '
232 template = fileLoader(filename).toString().replace(_BOM, '');
234 func = exports.compile(template, options);
236 exports.cache.set(filename, func);
242 * Try calling handleCache with the given options and data and call the
243 * callback with the result. If an error occurs, call the callback with
244 * the error. Used by renderFile().
246 * @memberof module:ejs-internal
247 * @param {Options} options compilation options
248 * @param {Object} data template data
249 * @param {RenderFileCallback} cb callback
253 function tryHandleCache(options, data, cb) {
256 if (typeof exports.promiseImpl == 'function') {
257 return new exports.promiseImpl(function (resolve, reject) {
259 result = handleCache(options)(data);
268 throw new Error('Please provide a callback function');
273 result = handleCache(options)(data);
284 * fileLoader is independent
286 * @param {String} filePath ejs file path.
287 * @return {String} The contents of the specified file.
291 function fileLoader(filePath){
292 return exports.fileLoader(filePath);
296 * Get the template function.
298 * If `options.cache` is `true`, then the template is cached.
300 * @memberof module:ejs-internal
301 * @param {String} path path for the specified file
302 * @param {Options} options compilation options
303 * @return {(TemplateFunction|ClientFunction)}
304 * Depending on the value of `options.client`, either type might be returned
308 function includeFile(path, options) {
309 var opts = utils.shallowCopy({}, options);
310 opts.filename = getIncludePath(path, opts);
311 if (typeof options.includer === 'function') {
312 var includerResult = options.includer(path, opts.filename);
313 if (includerResult) {
314 if (includerResult.filename) {
315 opts.filename = includerResult.filename;
317 if (includerResult.template) {
318 return handleCache(opts, includerResult.template);
322 return handleCache(opts);
326 * Re-throw the given `err` in context to the `str` of ejs, `filename`, and
329 * @implements {RethrowCallback}
330 * @memberof module:ejs-internal
331 * @param {Error} err Error object
332 * @param {String} str EJS source
333 * @param {String} flnm file name of the EJS file
334 * @param {Number} lineno line number of the error
335 * @param {EscapeCallback} esc
339 function rethrow(err, str, flnm, lineno, esc) {
340 var lines = str.split('\n');
341 var start = Math.max(lineno - 3, 0);
342 var end = Math.min(lines.length, lineno + 3);
343 var filename = esc(flnm);
345 var context = lines.slice(start, end).map(function (line, i){
346 var curr = i + start + 1;
347 return (curr == lineno ? ' >> ' : ' ')
353 // Alter exception message
355 err.message = (filename || 'ejs') + ':'
363 function stripSemi(str){
364 return str.replace(/;(\s*$)/, '$1');
368 * Compile the given `str` of ejs into a template function.
370 * @param {String} template EJS template
372 * @param {Options} [opts] compilation options
374 * @return {(TemplateFunction|ClientFunction)}
375 * Depending on the value of `opts.client`, either type might be returned.
376 * Note that the return type of the function also depends on the value of `opts.async`.
380 exports.compile = function compile(template, opts) {
384 // 'scope' is 'context'
385 // FIXME: Remove this in a future version
386 if (opts && opts.scope) {
387 if (!scopeOptionWarned){
388 console.warn('`scope` option is deprecated and will be removed in EJS 3');
389 scopeOptionWarned = true;
392 opts.context = opts.scope;
396 templ = new Template(template, opts);
397 return templ.compile();
401 * Render the given `template` of ejs.
403 * If you would like to include options but not data, you need to explicitly
404 * call this function with `data` being an empty object or `null`.
406 * @param {String} template EJS template
407 * @param {Object} [data={}] template data
408 * @param {Options} [opts={}] compilation and rendering options
409 * @return {(String|Promise<String>)}
410 * Return value type depends on `opts.async`.
414 exports.render = function (template, d, o) {
418 // No options object -- if there are optiony names
419 // in the data, copy them to options
420 if (arguments.length == 2) {
421 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
424 return handleCache(opts, template)(data);
428 * Render an EJS file at the given `path` and callback `cb(err, str)`.
430 * If you would like to include options but not data, you need to explicitly
431 * call this function with `data` being an empty object or `null`.
433 * @param {String} path path to the EJS file
434 * @param {Object} [data={}] template data
435 * @param {Options} [opts={}] compilation and rendering options
436 * @param {RenderFileCallback} cb callback
440 exports.renderFile = function () {
441 var args = Array.prototype.slice.call(arguments);
442 var filename = args.shift();
444 var opts = {filename: filename};
448 // Do we have a callback?
449 if (typeof arguments[arguments.length - 1] == 'function') {
452 // Do we have data/opts?
454 // Should always have data obj
456 // Normal passed opts (data obj + opts obj)
458 // Use shallowCopy so we don't pollute passed in opts obj with new vals
459 utils.shallowCopy(opts, args.pop());
461 // Special casing for Express (settings + opts-in-data)
465 // Pull a few things from known locations
466 if (data.settings.views) {
467 opts.views = data.settings.views;
469 if (data.settings['view cache']) {
472 // Undocumented after Express 2, but still usable, esp. for
473 // items that are unsafe to be passed along with data, like `root`
474 viewOpts = data.settings['view options'];
476 utils.shallowCopy(opts, viewOpts);
479 // Express 2 and lower, values set in app.locals, or people who just
480 // want to pass options in their data. NOTE: These values will override
481 // anything previously set in settings or settings['view options']
482 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
484 opts.filename = filename;
490 return tryHandleCache(opts, data, cb);
494 * Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
502 exports.Template = Template;
504 exports.clearCache = function () {
505 exports.cache.reset();
508 function Template(text, opts) {
511 this.templateText = text;
512 /** @type {string | null} */
514 this.truncate = false;
515 this.currentLine = 1;
517 options.client = opts.client || false;
518 options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
519 options.compileDebug = opts.compileDebug !== false;
520 options.debug = !!opts.debug;
521 options.filename = opts.filename;
522 options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
523 options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
524 options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
525 options.strict = opts.strict || false;
526 options.context = opts.context;
527 options.cache = opts.cache || false;
528 options.rmWhitespace = opts.rmWhitespace;
529 options.root = opts.root;
530 options.includer = opts.includer;
531 options.outputFunctionName = opts.outputFunctionName;
532 options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
533 options.views = opts.views;
534 options.async = opts.async;
535 options.destructuredLocals = opts.destructuredLocals;
536 options.legacyInclude = typeof opts.legacyInclude != 'undefined' ? !!opts.legacyInclude : true;
538 if (options.strict) {
539 options._with = false;
542 options._with = typeof opts._with != 'undefined' ? opts._with : true;
547 this.regex = this.createRegex();
558 Template.prototype = {
559 createRegex: function () {
560 var str = _REGEX_STRING;
561 var delim = utils.escapeRegExpChars(this.opts.delimiter);
562 var open = utils.escapeRegExpChars(this.opts.openDelimiter);
563 var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
564 str = str.replace(/%/g, delim)
566 .replace(/>/g, close);
567 return new RegExp(str);
570 compile: function () {
571 /** @type {string} */
573 /** @type {ClientFunction} */
575 var opts = this.opts;
578 /** @type {EscapeCallback} */
579 var escapeFn = opts.escapeFunction;
580 /** @type {FunctionConstructor} */
582 /** @type {string} */
583 var sanitizedFilename = opts.filename ? JSON.stringify(opts.filename) : 'undefined';
586 this.generateSource();
588 ' var __output = "";\n' +
589 ' function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
590 if (opts.outputFunctionName) {
591 prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
593 if (opts.destructuredLocals && opts.destructuredLocals.length) {
594 var destructuring = ' var __locals = (' + opts.localsName + ' || {}),\n';
595 for (var i = 0; i < opts.destructuredLocals.length; i++) {
596 var name = opts.destructuredLocals[i];
598 destructuring += ',\n ';
600 destructuring += name + ' = __locals.' + name;
602 prepended += destructuring + ';\n';
604 if (opts._with !== false) {
605 prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
606 appended += ' }' + '\n';
608 appended += ' return __output;' + '\n';
609 this.source = prepended + this.source + appended;
612 if (opts.compileDebug) {
613 src = 'var __line = 1' + '\n'
614 + ' , __lines = ' + JSON.stringify(this.templateText) + '\n'
615 + ' , __filename = ' + sanitizedFilename + ';' + '\n'
618 + '} catch (e) {' + '\n'
619 + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
627 src = 'escapeFn = escapeFn || ' + escapeFn.toString() + ';' + '\n' + src;
628 if (opts.compileDebug) {
629 src = 'rethrow = rethrow || ' + rethrow.toString() + ';' + '\n' + src;
634 src = '"use strict";\n' + src;
639 if (opts.compileDebug && opts.filename) {
641 + '//# sourceURL=' + sanitizedFilename + '\n';
646 // Have to use generated function for this, since in envs without support,
647 // it breaks in parsing
649 ctor = (new Function('return (async function(){}).constructor;'))();
652 if (e instanceof SyntaxError) {
653 throw new Error('This environment does not support async/await');
663 fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
666 // istanbul ignore else
667 if (e instanceof SyntaxError) {
669 e.message += ' in ' + opts.filename;
671 e.message += ' while compiling ejs\n\n';
672 e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
673 e.message += 'https://github.com/RyanZim/EJS-Lint';
676 e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.';
682 // Return a callable function which will execute the function
683 // created by the source-code, with the passed data as locals
684 // Adds a local `include` function which allows full recursive include
685 var returnedFn = opts.client ? fn : function anonymous(data) {
686 var include = function (path, includeData) {
687 var d = utils.shallowCopy({}, data);
689 d = utils.shallowCopy(d, includeData);
691 return includeFile(path, opts)(d);
693 return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
695 if (opts.filename && typeof Object.defineProperty === 'function') {
696 var filename = opts.filename;
697 var basename = path.basename(filename, path.extname(filename));
699 Object.defineProperty(returnedFn, 'name', {
705 } catch (e) {/* ignore */}
710 generateSource: function () {
711 var opts = this.opts;
713 if (opts.rmWhitespace) {
714 // Have to use two separate replace here as `^` and `$` operators don't
715 // work well with `\r` and empty lines don't work well with the `m` flag.
717 this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
720 // Slurp spaces and tabs before <%_ and after _%>
722 this.templateText.replace(/[ \t]*<%_/gm, '<%_').replace(/_%>[ \t]*/gm, '_%>');
725 var matches = this.parseTemplateText();
726 var d = this.opts.delimiter;
727 var o = this.opts.openDelimiter;
728 var c = this.opts.closeDelimiter;
730 if (matches && matches.length) {
731 matches.forEach(function (line, index) {
733 // If this is an opening tag, check for closing tags
734 // FIXME: May end up with some false positives here
735 // Better to store modes as k/v with openDelimiter + delimiter as key
736 // Then this can simply check against the map
737 if ( line.indexOf(o + d) === 0 // If it is a tag
738 && line.indexOf(o + d + d) !== 0) { // and is not escaped
739 closing = matches[index + 2];
740 if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
741 throw new Error('Could not find matching close tag for "' + line + '".');
750 parseTemplateText: function () {
751 var str = this.templateText;
752 var pat = this.regex;
753 var result = pat.exec(str);
758 firstPos = result.index;
760 if (firstPos !== 0) {
761 arr.push(str.substring(0, firstPos));
762 str = str.slice(firstPos);
766 str = str.slice(result[0].length);
767 result = pat.exec(str);
777 _addOutput: function (line) {
779 // Only replace single leading linebreak in the line after
780 // -%> tag -- this is the single, trailing linebreak
781 // after the tag that the truncation mode replaces
782 // Handle Win / Unix / old Mac linebreaks -- do the \r\n
783 // combo first in the regex-or
784 line = line.replace(/^(?:\r\n|\r|\n)/, '');
785 this.truncate = false;
791 // Preserve literal slashes
792 line = line.replace(/\\/g, '\\\\');
794 // Convert linebreaks
795 line = line.replace(/\n/g, '\\n');
796 line = line.replace(/\r/g, '\\r');
798 // Escape double-quotes
799 // - this will be the delimiter during execution
800 line = line.replace(/"/g, '\\"');
801 this.source += ' ; __append("' + line + '")' + '\n';
804 scanLine: function (line) {
806 var d = this.opts.delimiter;
807 var o = this.opts.openDelimiter;
808 var c = this.opts.closeDelimiter;
809 var newLineCount = 0;
811 newLineCount = (line.split('\n').length - 1);
816 this.mode = Template.modes.EVAL;
819 this.mode = Template.modes.ESCAPED;
822 this.mode = Template.modes.RAW;
825 this.mode = Template.modes.COMMENT;
828 this.mode = Template.modes.LITERAL;
829 this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
832 this.mode = Template.modes.LITERAL;
833 this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
838 if (this.mode == Template.modes.LITERAL) {
839 this._addOutput(line);
843 this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
846 // In script mode, depends on type of tag
848 // If '//' is found without a line break, add a line break.
850 case Template.modes.EVAL:
851 case Template.modes.ESCAPED:
852 case Template.modes.RAW:
853 if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
858 // Just executing code
859 case Template.modes.EVAL:
860 this.source += ' ; ' + line + '\n';
862 // Exec, esc, and output
863 case Template.modes.ESCAPED:
864 this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n';
867 case Template.modes.RAW:
868 this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
870 case Template.modes.COMMENT:
873 // Literal <%% mode, append as raw output
874 case Template.modes.LITERAL:
875 this._addOutput(line);
879 // In string mode, just add the output
881 this._addOutput(line);
885 if (self.opts.compileDebug && newLineCount) {
886 this.currentLine += newLineCount;
887 this.source += ' ; __line = ' + this.currentLine + '\n';
893 * Escape characters reserved in XML.
895 * This is simply an export of {@link module:utils.escapeXML}.
897 * If `markup` is `undefined` or `null`, the empty string is returned.
899 * @param {String} markup Input string
900 * @return {String} Escaped string
904 exports.escapeXML = utils.escapeXML;
907 * Express.js support.
909 * This is an alias for {@link module:ejs.renderFile}, in order to support
910 * Express.js out-of-the-box.
915 exports.__express = exports.renderFile;
925 exports.VERSION = _VERSION_STRING;
928 * Name for detection of EJS.
935 exports.name = _NAME;
937 /* istanbul ignore if */
938 if (typeof window != 'undefined') {
939 window.ejs = exports;
942 },{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
944 * EJS Embedded JavaScript templates
945 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
947 * Licensed under the Apache License, Version 2.0 (the "License");
948 * you may not use this file except in compliance with the License.
949 * You may obtain a copy of the License at
951 * http://www.apache.org/licenses/LICENSE-2.0
953 * Unless required by applicable law or agreed to in writing, software
954 * distributed under the License is distributed on an "AS IS" BASIS,
955 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
956 * See the License for the specific language governing permissions and
957 * limitations under the License.
962 * Private utility functions
969 var regExpChars = /[|\\{}()[\]^$+*?.]/g;
972 * Escape characters reserved in regular expressions.
974 * If `string` is `undefined` or `null`, the empty string is returned.
976 * @param {String} string Input string
977 * @return {String} Escaped string
981 exports.escapeRegExpChars = function (string) {
982 // istanbul ignore if
986 return String(string).replace(regExpChars, '\\$&');
989 var _ENCODE_HTML_RULES = {
996 var _MATCH_HTML = /[&<>'"]/g;
998 function encode_char(c) {
999 return _ENCODE_HTML_RULES[c] || c;
1003 * Stringified version of constants used by {@link module:utils.escapeXML}.
1005 * It is used in the process of generating {@link ClientFunction}s.
1012 'var _ENCODE_HTML_RULES = {\n'
1014 + ' , "<": "<"\n'
1015 + ' , ">": ">"\n'
1016 + ' , \'"\': """\n'
1017 + ' , "\'": "'"\n'
1019 + ' , _MATCH_HTML = /[&<>\'"]/g;\n'
1020 + 'function encode_char(c) {\n'
1021 + ' return _ENCODE_HTML_RULES[c] || c;\n'
1025 * Escape characters reserved in XML.
1027 * If `markup` is `undefined` or `null`, the empty string is returned.
1029 * @implements {EscapeCallback}
1030 * @param {String} markup Input string
1031 * @return {String} Escaped string
1036 exports.escapeXML = function (markup) {
1037 return markup == undefined
1040 .replace(_MATCH_HTML, encode_char);
1042 exports.escapeXML.toString = function () {
1043 return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
1047 * Naive copy of properties from one object to another.
1048 * Does not recurse into non-scalar properties
1049 * Does not check to see if the property has a value before copying
1051 * @param {Object} to Destination object
1052 * @param {Object} from Source object
1053 * @return {Object} Destination object
1057 exports.shallowCopy = function (to, from) {
1059 for (var p in from) {
1066 * Naive copy of a list of key names, from one object to another.
1067 * Only copies property if it is actually defined
1068 * Does not recurse into non-scalar properties
1070 * @param {Object} to Destination object
1071 * @param {Object} from Source object
1072 * @param {Array} list List of properties to copy
1073 * @return {Object} Destination object
1077 exports.shallowCopyFromList = function (to, from, list) {
1078 for (var i = 0; i < list.length; i++) {
1080 if (typeof from[p] != 'undefined') {
1088 * Simple in-process cache implementation. Does not implement limits of any
1091 * @implements {Cache}
1097 set: function (key, val) {
1098 this._data[key] = val;
1100 get: function (key) {
1101 return this._data[key];
1103 remove: function (key) {
1104 delete this._data[key];
1106 reset: function () {
1112 * Transforms hyphen case variable into camel case.
1114 * @param {String} string Hyphen case string
1115 * @return {String} Camel case string
1119 exports.hyphenToCamel = function (str) {
1120 return str.replace(/-[a-z]/g, function (match) { return match[1].toUpperCase(); });
1123 },{}],3:[function(require,module,exports){
1125 },{}],4:[function(require,module,exports){
1126 (function (process){
1127 // .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
1128 // backported and transplited with Babel, with backwards-compat fixes
1130 // Copyright Joyent, Inc. and other Node contributors.
1132 // Permission is hereby granted, free of charge, to any person obtaining a
1133 // copy of this software and associated documentation files (the
1134 // "Software"), to deal in the Software without restriction, including
1135 // without limitation the rights to use, copy, modify, merge, publish,
1136 // distribute, sublicense, and/or sell copies of the Software, and to permit
1137 // persons to whom the Software is furnished to do so, subject to the
1138 // following conditions:
1140 // The above copyright notice and this permission notice shall be included
1141 // in all copies or substantial portions of the Software.
1143 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1144 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1145 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1146 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1147 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1148 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1149 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1151 // resolves . and .. elements in a path array with directory names there
1152 // must be no slashes, empty elements, or device names (c:\) in the array
1153 // (so also no leading and trailing slashes - it does not distinguish
1154 // relative and absolute paths)
1155 function normalizeArray(parts, allowAboveRoot) {
1156 // if the path tries to go above the root, `up` ends up > 0
1158 for (var i = parts.length - 1; i >= 0; i--) {
1159 var last = parts[i];
1162 } else if (last === '..') {
1171 // if the path is allowed to go above the root, restore leading ..s
1172 if (allowAboveRoot) {
1174 parts.unshift('..');
1181 // path.resolve([from ...], to)
1183 exports.resolve = function() {
1184 var resolvedPath = '',
1185 resolvedAbsolute = false;
1187 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1188 var path = (i >= 0) ? arguments[i] : process.cwd();
1190 // Skip empty and invalid entries
1191 if (typeof path !== 'string') {
1192 throw new TypeError('Arguments to path.resolve must be strings');
1197 resolvedPath = path + '/' + resolvedPath;
1198 resolvedAbsolute = path.charAt(0) === '/';
1201 // At this point the path should be resolved to a full absolute path, but
1202 // handle relative paths to be safe (might happen when process.cwd() fails)
1204 // Normalize the path
1205 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
1207 }), !resolvedAbsolute).join('/');
1209 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
1212 // path.normalize(path)
1214 exports.normalize = function(path) {
1215 var isAbsolute = exports.isAbsolute(path),
1216 trailingSlash = substr(path, -1) === '/';
1218 // Normalize the path
1219 path = normalizeArray(filter(path.split('/'), function(p) {
1221 }), !isAbsolute).join('/');
1223 if (!path && !isAbsolute) {
1226 if (path && trailingSlash) {
1230 return (isAbsolute ? '/' : '') + path;
1234 exports.isAbsolute = function(path) {
1235 return path.charAt(0) === '/';
1239 exports.join = function() {
1240 var paths = Array.prototype.slice.call(arguments, 0);
1241 return exports.normalize(filter(paths, function(p, index) {
1242 if (typeof p !== 'string') {
1243 throw new TypeError('Arguments to path.join must be strings');
1250 // path.relative(from, to)
1252 exports.relative = function(from, to) {
1253 from = exports.resolve(from).substr(1);
1254 to = exports.resolve(to).substr(1);
1256 function trim(arr) {
1258 for (; start < arr.length; start++) {
1259 if (arr[start] !== '') break;
1262 var end = arr.length - 1;
1263 for (; end >= 0; end--) {
1264 if (arr[end] !== '') break;
1267 if (start > end) return [];
1268 return arr.slice(start, end - start + 1);
1271 var fromParts = trim(from.split('/'));
1272 var toParts = trim(to.split('/'));
1274 var length = Math.min(fromParts.length, toParts.length);
1275 var samePartsLength = length;
1276 for (var i = 0; i < length; i++) {
1277 if (fromParts[i] !== toParts[i]) {
1278 samePartsLength = i;
1283 var outputParts = [];
1284 for (var i = samePartsLength; i < fromParts.length; i++) {
1285 outputParts.push('..');
1288 outputParts = outputParts.concat(toParts.slice(samePartsLength));
1290 return outputParts.join('/');
1294 exports.delimiter = ':';
1296 exports.dirname = function (path) {
1297 if (typeof path !== 'string') path = path + '';
1298 if (path.length === 0) return '.';
1299 var code = path.charCodeAt(0);
1300 var hasRoot = code === 47 /*/*/;
1302 var matchedSlash = true;
1303 for (var i = path.length - 1; i >= 1; --i) {
1304 code = path.charCodeAt(i);
1305 if (code === 47 /*/*/) {
1306 if (!matchedSlash) {
1311 // We saw the first non-path separator
1312 matchedSlash = false;
1316 if (end === -1) return hasRoot ? '/' : '.';
1317 if (hasRoot && end === 1) {
1319 // Backwards-compat fix:
1322 return path.slice(0, end);
1325 function basename(path) {
1326 if (typeof path !== 'string') path = path + '';
1330 var matchedSlash = true;
1333 for (i = path.length - 1; i >= 0; --i) {
1334 if (path.charCodeAt(i) === 47 /*/*/) {
1335 // If we reached a path separator that was not part of a set of path
1336 // separators at the end of the string, stop now
1337 if (!matchedSlash) {
1341 } else if (end === -1) {
1342 // We saw the first non-path separator, mark this as the end of our
1344 matchedSlash = false;
1349 if (end === -1) return '';
1350 return path.slice(start, end);
1353 // Uses a mixed approach for backwards-compatibility, as ext behavior changed
1354 // in new Node.js versions, so only basename() above is backported here
1355 exports.basename = function (path, ext) {
1356 var f = basename(path);
1357 if (ext && f.substr(-1 * ext.length) === ext) {
1358 f = f.substr(0, f.length - ext.length);
1363 exports.extname = function (path) {
1364 if (typeof path !== 'string') path = path + '';
1368 var matchedSlash = true;
1369 // Track the state of characters (if any) we see before our first dot and
1370 // after any path separator we find
1371 var preDotState = 0;
1372 for (var i = path.length - 1; i >= 0; --i) {
1373 var code = path.charCodeAt(i);
1374 if (code === 47 /*/*/) {
1375 // If we reached a path separator that was not part of a set of path
1376 // separators at the end of the string, stop now
1377 if (!matchedSlash) {
1384 // We saw the first non-path separator, mark this as the end of our
1386 matchedSlash = false;
1389 if (code === 46 /*.*/) {
1390 // If this is our first dot, mark it as the start of our extension
1391 if (startDot === -1)
1393 else if (preDotState !== 1)
1395 } else if (startDot !== -1) {
1396 // We saw a non-dot and non-path separator before our dot, so we should
1397 // have a good chance at having a non-empty extension
1402 if (startDot === -1 || end === -1 ||
1403 // We saw a non-dot character immediately before the dot
1404 preDotState === 0 ||
1405 // The (right-most) trimmed path component is exactly '..'
1406 preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1409 return path.slice(startDot, end);
1412 function filter (xs, f) {
1413 if (xs.filter) return xs.filter(f);
1415 for (var i = 0; i < xs.length; i++) {
1416 if (f(xs[i], i, xs)) res.push(xs[i]);
1421 // String.prototype.substr - negative index don't work in IE8
1422 var substr = 'ab'.substr(-1) === 'b'
1423 ? function (str, start, len) { return str.substr(start, len) }
1424 : function (str, start, len) {
1425 if (start < 0) start = str.length + start;
1426 return str.substr(start, len);
1430 }).call(this,require('_process'))
1431 },{"_process":5}],5:[function(require,module,exports){
1432 // shim for using process in browser
1433 var process = module.exports = {};
1435 // cached from whatever global is present so that test runners that stub it
1436 // don't break things. But we need to wrap it in a try catch in case it is
1437 // wrapped in strict mode code which doesn't define any globals. It's inside a
1438 // function because try/catches deoptimize in certain engines.
1440 var cachedSetTimeout;
1441 var cachedClearTimeout;
1443 function defaultSetTimout() {
1444 throw new Error('setTimeout has not been defined');
1446 function defaultClearTimeout () {
1447 throw new Error('clearTimeout has not been defined');
1451 if (typeof setTimeout === 'function') {
1452 cachedSetTimeout = setTimeout;
1454 cachedSetTimeout = defaultSetTimout;
1457 cachedSetTimeout = defaultSetTimout;
1460 if (typeof clearTimeout === 'function') {
1461 cachedClearTimeout = clearTimeout;
1463 cachedClearTimeout = defaultClearTimeout;
1466 cachedClearTimeout = defaultClearTimeout;
1469 function runTimeout(fun) {
1470 if (cachedSetTimeout === setTimeout) {
1471 //normal enviroments in sane situations
1472 return setTimeout(fun, 0);
1474 // if setTimeout wasn't available but was latter defined
1475 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
1476 cachedSetTimeout = setTimeout;
1477 return setTimeout(fun, 0);
1480 // when when somebody has screwed with setTimeout but no I.E. maddness
1481 return cachedSetTimeout(fun, 0);
1484 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1485 return cachedSetTimeout.call(null, fun, 0);
1487 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
1488 return cachedSetTimeout.call(this, fun, 0);
1494 function runClearTimeout(marker) {
1495 if (cachedClearTimeout === clearTimeout) {
1496 //normal enviroments in sane situations
1497 return clearTimeout(marker);
1499 // if clearTimeout wasn't available but was latter defined
1500 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
1501 cachedClearTimeout = clearTimeout;
1502 return clearTimeout(marker);
1505 // when when somebody has screwed with setTimeout but no I.E. maddness
1506 return cachedClearTimeout(marker);
1509 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1510 return cachedClearTimeout.call(null, marker);
1512 // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
1513 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
1514 return cachedClearTimeout.call(this, marker);
1522 var draining = false;
1524 var queueIndex = -1;
1526 function cleanUpNextTick() {
1527 if (!draining || !currentQueue) {
1531 if (currentQueue.length) {
1532 queue = currentQueue.concat(queue);
1541 function drainQueue() {
1545 var timeout = runTimeout(cleanUpNextTick);
1548 var len = queue.length;
1550 currentQueue = queue;
1552 while (++queueIndex < len) {
1554 currentQueue[queueIndex].run();
1560 currentQueue = null;
1562 runClearTimeout(timeout);
1565 process.nextTick = function (fun) {
1566 var args = new Array(arguments.length - 1);
1567 if (arguments.length > 1) {
1568 for (var i = 1; i < arguments.length; i++) {
1569 args[i - 1] = arguments[i];
1572 queue.push(new Item(fun, args));
1573 if (queue.length === 1 && !draining) {
1574 runTimeout(drainQueue);
1578 // v8 likes predictible objects
1579 function Item(fun, array) {
1583 Item.prototype.run = function () {
1584 this.fun.apply(null, this.array);
1586 process.title = 'browser';
1587 process.browser = true;
1590 process.version = ''; // empty string to avoid regexp issues
1591 process.versions = {};
1596 process.addListener = noop;
1597 process.once = noop;
1599 process.removeListener = noop;
1600 process.removeAllListeners = noop;
1601 process.emit = noop;
1602 process.prependListener = noop;
1603 process.prependOnceListener = noop;
1605 process.listeners = function (name) { return [] }
1607 process.binding = function (name) {
1608 throw new Error('process.binding is not supported');
1611 process.cwd = function () { return '/' };
1612 process.chdir = function (dir) {
1613 throw new Error('process.chdir is not supported');
1615 process.umask = function() { return 0; };
1617 },{}],6:[function(require,module,exports){
1620 "description": "Embedded JavaScript templates",
1627 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
1628 "license": "Apache-2.0",
1630 "ejs": "./bin/cli.js"
1632 "main": "./lib/ejs.js",
1633 "jsdelivr": "ejs.min.js",
1634 "unpkg": "ejs.min.js",
1637 "url": "git://github.com/mde/ejs.git"
1639 "bugs": "https://github.com/mde/ejs/issues",
1640 "homepage": "https://github.com/mde/ejs",
1644 "devDependencies": {
1645 "browserify": "^16.5.1",
1647 "git-directory-deploy": "^1.5.1",
1649 "lru-cache": "^4.0.1",
1651 "uglify-js": "^3.3.16"