UNPKG

48.5 kBJavaScriptView Raw
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){
2/*
3 * EJS Embedded JavaScript templates
4 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18*/
19
20'use strict';
21
22/**
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>
26 * @project EJS
27 * @license {@link http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0}
28 */
29
30/**
31 * EJS internal functions.
32 *
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
35 * module.
36 *
37 * @module ejs-internal
38 * @private
39 */
40
41/**
42 * Embedded JavaScript templating engine.
43 *
44 * @module ejs
45 * @public
46 */
47
48var fs = require('fs');
49var path = require('path');
50var utils = require('./utils');
51
52var scopeOptionWarned = false;
53var _VERSION_STRING = require('../package.json').version;
54var _DEFAULT_OPEN_DELIMITER = '<';
55var _DEFAULT_CLOSE_DELIMITER = '>';
56var _DEFAULT_DELIMITER = '%';
57var _DEFAULT_LOCALS_NAME = 'locals';
58var _NAME = 'ejs';
59var _REGEX_STRING = '(<%%|%%>|<%=|<%-|<%_|<%#|<%|%>|-%>|_%>)';
60var _OPTS_PASSABLE_WITH_DATA = ['delimiter', 'scope', 'context', 'debug', 'compileDebug',
61 'client', '_with', 'rmWhitespace', 'strict', 'filename', 'async'];
62// We don't allow 'cache' option to be passed in the data obj for
63// the normal `render` call, but this is where Express 2 & 3 put it
64// so we make an exception for `renderFile`
65var _OPTS_PASSABLE_WITH_DATA_EXPRESS = _OPTS_PASSABLE_WITH_DATA.concat('cache');
66var _BOM = /^\uFEFF/;
67
68/**
69 * EJS template function cache. This can be a LRU object from lru-cache NPM
70 * module. By default, it is {@link module:utils.cache}, a simple in-process
71 * cache that grows continuously.
72 *
73 * @type {Cache}
74 */
75
76exports.cache = utils.cache;
77
78/**
79 * Custom file loader. Useful for template preprocessing or restricting access
80 * to a certain part of the filesystem.
81 *
82 * @type {fileLoader}
83 */
84
85exports.fileLoader = fs.readFileSync;
86
87/**
88 * Name of the object containing the locals.
89 *
90 * This variable is overridden by {@link Options}`.localsName` if it is not
91 * `undefined`.
92 *
93 * @type {String}
94 * @public
95 */
96
97exports.localsName = _DEFAULT_LOCALS_NAME;
98
99/**
100 * Promise implementation -- defaults to the native implementation if available
101 * This is mostly just for testability
102 *
103 * @type {Function}
104 * @public
105 */
106
107exports.promiseImpl = (new Function('return this;'))().Promise;
108
109/**
110 * Get the path to the included file from the parent file path and the
111 * specified path.
112 *
113 * @param {String} name specified path
114 * @param {String} filename parent file path
115 * @param {Boolean} isDir parent file path whether is directory
116 * @return {String}
117 */
118exports.resolveInclude = function(name, filename, isDir) {
119 var dirname = path.dirname;
120 var extname = path.extname;
121 var resolve = path.resolve;
122 var includePath = resolve(isDir ? filename : dirname(filename), name);
123 var ext = extname(name);
124 if (!ext) {
125 includePath += '.ejs';
126 }
127 return includePath;
128};
129
130/**
131 * Get the path to the included file by Options
132 *
133 * @param {String} path specified path
134 * @param {Options} options compilation options
135 * @return {String}
136 */
137function getIncludePath(path, options) {
138 var includePath;
139 var filePath;
140 var views = options.views;
141 var match = /^[A-Za-z]+:\\|^\//.exec(path);
142
143 // Abs path
144 if (match && match.length) {
145 includePath = exports.resolveInclude(path.replace(/^\/*/,''), options.root || '/', true);
146 }
147 // Relative paths
148 else {
149 // Look relative to a passed filename first
150 if (options.filename) {
151 filePath = exports.resolveInclude(path, options.filename);
152 if (fs.existsSync(filePath)) {
153 includePath = filePath;
154 }
155 }
156 // Then look in any views directories
157 if (!includePath) {
158 if (Array.isArray(views) && views.some(function (v) {
159 filePath = exports.resolveInclude(path, v, true);
160 return fs.existsSync(filePath);
161 })) {
162 includePath = filePath;
163 }
164 }
165 if (!includePath) {
166 throw new Error('Could not find the include file "' +
167 options.escapeFunction(path) + '"');
168 }
169 }
170 return includePath;
171}
172
173/**
174 * Get the template from a string or a file, either compiled on-the-fly or
175 * read from cache (if enabled), and cache the template if needed.
176 *
177 * If `template` is not set, the file specified in `options.filename` will be
178 * read.
179 *
180 * If `options.cache` is true, this function reads the file from
181 * `options.filename` so it must be set prior to calling this function.
182 *
183 * @memberof module:ejs-internal
184 * @param {Options} options compilation options
185 * @param {String} [template] template source
186 * @return {(TemplateFunction|ClientFunction)}
187 * Depending on the value of `options.client`, either type might be returned.
188 * @static
189 */
190
191function handleCache(options, template) {
192 var func;
193 var filename = options.filename;
194 var hasTemplate = arguments.length > 1;
195
196 if (options.cache) {
197 if (!filename) {
198 throw new Error('cache option requires a filename');
199 }
200 func = exports.cache.get(filename);
201 if (func) {
202 return func;
203 }
204 if (!hasTemplate) {
205 template = fileLoader(filename).toString().replace(_BOM, '');
206 }
207 }
208 else if (!hasTemplate) {
209 // istanbul ignore if: should not happen at all
210 if (!filename) {
211 throw new Error('Internal EJS error: no file name or template '
212 + 'provided');
213 }
214 template = fileLoader(filename).toString().replace(_BOM, '');
215 }
216 func = exports.compile(template, options);
217 if (options.cache) {
218 exports.cache.set(filename, func);
219 }
220 return func;
221}
222
223/**
224 * Try calling handleCache with the given options and data and call the
225 * callback with the result. If an error occurs, call the callback with
226 * the error. Used by renderFile().
227 *
228 * @memberof module:ejs-internal
229 * @param {Options} options compilation options
230 * @param {Object} data template data
231 * @param {RenderFileCallback} cb callback
232 * @static
233 */
234
235function tryHandleCache(options, data, cb) {
236 var result;
237 if (!cb) {
238 if (typeof exports.promiseImpl == 'function') {
239 return new exports.promiseImpl(function (resolve, reject) {
240 try {
241 result = handleCache(options)(data);
242 resolve(result);
243 }
244 catch (err) {
245 reject(err);
246 }
247 });
248 }
249 else {
250 throw new Error('Please provide a callback function');
251 }
252 }
253 else {
254 try {
255 result = handleCache(options)(data);
256 }
257 catch (err) {
258 return cb(err);
259 }
260
261 cb(null, result);
262 }
263}
264
265/**
266 * fileLoader is independent
267 *
268 * @param {String} filePath ejs file path.
269 * @return {String} The contents of the specified file.
270 * @static
271 */
272
273function fileLoader(filePath){
274 return exports.fileLoader(filePath);
275}
276
277/**
278 * Get the template function.
279 *
280 * If `options.cache` is `true`, then the template is cached.
281 *
282 * @memberof module:ejs-internal
283 * @param {String} path path for the specified file
284 * @param {Options} options compilation options
285 * @return {(TemplateFunction|ClientFunction)}
286 * Depending on the value of `options.client`, either type might be returned
287 * @static
288 */
289
290function includeFile(path, options) {
291 var opts = utils.shallowCopy({}, options);
292 opts.filename = getIncludePath(path, opts);
293 return handleCache(opts);
294}
295
296/**
297 * Get the JavaScript source of an included file.
298 *
299 * @memberof module:ejs-internal
300 * @param {String} path path for the specified file
301 * @param {Options} options compilation options
302 * @return {Object}
303 * @static
304 */
305
306function includeSource(path, options) {
307 var opts = utils.shallowCopy({}, options);
308 var includePath;
309 var template;
310 includePath = getIncludePath(path, opts);
311 template = fileLoader(includePath).toString().replace(_BOM, '');
312 opts.filename = includePath;
313 var templ = new Template(template, opts);
314 templ.generateSource();
315 return {
316 source: templ.source,
317 filename: includePath,
318 template: template
319 };
320}
321
322/**
323 * Re-throw the given `err` in context to the `str` of ejs, `filename`, and
324 * `lineno`.
325 *
326 * @implements RethrowCallback
327 * @memberof module:ejs-internal
328 * @param {Error} err Error object
329 * @param {String} str EJS source
330 * @param {String} filename file name of the EJS file
331 * @param {String} lineno line number of the error
332 * @static
333 */
334
335function rethrow(err, str, flnm, lineno, esc){
336 var lines = str.split('\n');
337 var start = Math.max(lineno - 3, 0);
338 var end = Math.min(lines.length, lineno + 3);
339 var filename = esc(flnm); // eslint-disable-line
340 // Error context
341 var context = lines.slice(start, end).map(function (line, i){
342 var curr = i + start + 1;
343 return (curr == lineno ? ' >> ' : ' ')
344 + curr
345 + '| '
346 + line;
347 }).join('\n');
348
349 // Alter exception message
350 err.path = filename;
351 err.message = (filename || 'ejs') + ':'
352 + lineno + '\n'
353 + context + '\n\n'
354 + err.message;
355
356 throw err;
357}
358
359function stripSemi(str){
360 return str.replace(/;(\s*$)/, '$1');
361}
362
363/**
364 * Compile the given `str` of ejs into a template function.
365 *
366 * @param {String} template EJS template
367 *
368 * @param {Options} opts compilation options
369 *
370 * @return {(TemplateFunction|ClientFunction)}
371 * Depending on the value of `opts.client`, either type might be returned.
372 * Note that the return type of the function also depends on the value of `opts.async`.
373 * @public
374 */
375
376exports.compile = function compile(template, opts) {
377 var templ;
378
379 // v1 compat
380 // 'scope' is 'context'
381 // FIXME: Remove this in a future version
382 if (opts && opts.scope) {
383 if (!scopeOptionWarned){
384 console.warn('`scope` option is deprecated and will be removed in EJS 3');
385 scopeOptionWarned = true;
386 }
387 if (!opts.context) {
388 opts.context = opts.scope;
389 }
390 delete opts.scope;
391 }
392 templ = new Template(template, opts);
393 return templ.compile();
394};
395
396/**
397 * Render the given `template` of ejs.
398 *
399 * If you would like to include options but not data, you need to explicitly
400 * call this function with `data` being an empty object or `null`.
401 *
402 * @param {String} template EJS template
403 * @param {Object} [data={}] template data
404 * @param {Options} [opts={}] compilation and rendering options
405 * @return {(String|Promise<String>)}
406 * Return value type depends on `opts.async`.
407 * @public
408 */
409
410exports.render = function (template, d, o) {
411 var data = d || {};
412 var opts = o || {};
413
414 // No options object -- if there are optiony names
415 // in the data, copy them to options
416 if (arguments.length == 2) {
417 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA);
418 }
419
420 return handleCache(opts, template)(data);
421};
422
423/**
424 * Render an EJS file at the given `path` and callback `cb(err, str)`.
425 *
426 * If you would like to include options but not data, you need to explicitly
427 * call this function with `data` being an empty object or `null`.
428 *
429 * @param {String} path path to the EJS file
430 * @param {Object} [data={}] template data
431 * @param {Options} [opts={}] compilation and rendering options
432 * @param {RenderFileCallback} cb callback
433 * @public
434 */
435
436exports.renderFile = function () {
437 var args = Array.prototype.slice.call(arguments);
438 var filename = args.shift();
439 var cb;
440 var opts = {filename: filename};
441 var data;
442 var viewOpts;
443
444 // Do we have a callback?
445 if (typeof arguments[arguments.length - 1] == 'function') {
446 cb = args.pop();
447 }
448 // Do we have data/opts?
449 if (args.length) {
450 // Should always have data obj
451 data = args.shift();
452 // Normal passed opts (data obj + opts obj)
453 if (args.length) {
454 // Use shallowCopy so we don't pollute passed in opts obj with new vals
455 utils.shallowCopy(opts, args.pop());
456 }
457 // Special casing for Express (settings + opts-in-data)
458 else {
459 // Express 3 and 4
460 if (data.settings) {
461 // Pull a few things from known locations
462 if (data.settings.views) {
463 opts.views = data.settings.views;
464 }
465 if (data.settings['view cache']) {
466 opts.cache = true;
467 }
468 // Undocumented after Express 2, but still usable, esp. for
469 // items that are unsafe to be passed along with data, like `root`
470 viewOpts = data.settings['view options'];
471 if (viewOpts) {
472 utils.shallowCopy(opts, viewOpts);
473 }
474 }
475 // Express 2 and lower, values set in app.locals, or people who just
476 // want to pass options in their data. NOTE: These values will override
477 // anything previously set in settings or settings['view options']
478 utils.shallowCopyFromList(opts, data, _OPTS_PASSABLE_WITH_DATA_EXPRESS);
479 }
480 opts.filename = filename;
481 }
482 else {
483 data = {};
484 }
485
486 return tryHandleCache(opts, data, cb);
487};
488
489/**
490 * Clear intermediate JavaScript cache. Calls {@link Cache#reset}.
491 * @public
492 */
493
494/**
495 * EJS template class
496 * @public
497 */
498exports.Template = Template;
499
500exports.clearCache = function () {
501 exports.cache.reset();
502};
503
504function Template(text, opts) {
505 opts = opts || {};
506 var options = {};
507 this.templateText = text;
508 this.mode = null;
509 this.truncate = false;
510 this.currentLine = 1;
511 this.source = '';
512 this.dependencies = [];
513 options.client = opts.client || false;
514 options.escapeFunction = opts.escape || opts.escapeFunction || utils.escapeXML;
515 options.compileDebug = opts.compileDebug !== false;
516 options.debug = !!opts.debug;
517 options.filename = opts.filename;
518 options.openDelimiter = opts.openDelimiter || exports.openDelimiter || _DEFAULT_OPEN_DELIMITER;
519 options.closeDelimiter = opts.closeDelimiter || exports.closeDelimiter || _DEFAULT_CLOSE_DELIMITER;
520 options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
521 options.strict = opts.strict || false;
522 options.context = opts.context;
523 options.cache = opts.cache || false;
524 options.rmWhitespace = opts.rmWhitespace;
525 options.root = opts.root;
526 options.outputFunctionName = opts.outputFunctionName;
527 options.localsName = opts.localsName || exports.localsName || _DEFAULT_LOCALS_NAME;
528 options.views = opts.views;
529 options.async = opts.async;
530 options.destructuredLocals = opts.destructuredLocals;
531 options.legacyInclude = typeof opts.legacyInclude != 'undefined' ? !!opts.legacyInclude : true;
532
533 if (options.strict) {
534 options._with = false;
535 }
536 else {
537 options._with = typeof opts._with != 'undefined' ? opts._with : true;
538 }
539
540 this.opts = options;
541
542 this.regex = this.createRegex();
543}
544
545Template.modes = {
546 EVAL: 'eval',
547 ESCAPED: 'escaped',
548 RAW: 'raw',
549 COMMENT: 'comment',
550 LITERAL: 'literal'
551};
552
553Template.prototype = {
554 createRegex: function () {
555 var str = _REGEX_STRING;
556 var delim = utils.escapeRegExpChars(this.opts.delimiter);
557 var open = utils.escapeRegExpChars(this.opts.openDelimiter);
558 var close = utils.escapeRegExpChars(this.opts.closeDelimiter);
559 str = str.replace(/%/g, delim)
560 .replace(/</g, open)
561 .replace(/>/g, close);
562 return new RegExp(str);
563 },
564
565 compile: function () {
566 var src;
567 var fn;
568 var opts = this.opts;
569 var prepended = '';
570 var appended = '';
571 var escapeFn = opts.escapeFunction;
572 var ctor;
573
574 if (!this.source) {
575 this.generateSource();
576 prepended +=
577 ' var __output = "";\n' +
578 ' function __append(s) { if (s !== undefined && s !== null) __output += s }\n';
579 if (opts.outputFunctionName) {
580 prepended += ' var ' + opts.outputFunctionName + ' = __append;' + '\n';
581 }
582 if (opts.destructuredLocals && opts.destructuredLocals.length) {
583 var destructuring = ' var __locals = (' + opts.localsName + ' || {}),\n';
584 for (var i = 0; i < opts.destructuredLocals.length; i++) {
585 var name = opts.destructuredLocals[i];
586 if (i > 0) {
587 destructuring += ',\n ';
588 }
589 destructuring += name + ' = __locals.' + name;
590 }
591 prepended += destructuring + ';\n';
592 }
593 if (opts._with !== false) {
594 prepended += ' with (' + opts.localsName + ' || {}) {' + '\n';
595 appended += ' }' + '\n';
596 }
597 appended += ' return __output;' + '\n';
598 this.source = prepended + this.source + appended;
599 }
600
601 if (opts.compileDebug) {
602 src = 'var __line = 1' + '\n'
603 + ' , __lines = ' + JSON.stringify(this.templateText) + '\n'
604 + ' , __filename = ' + (opts.filename ?
605 JSON.stringify(opts.filename) : 'undefined') + ';' + '\n'
606 + 'try {' + '\n'
607 + this.source
608 + '} catch (e) {' + '\n'
609 + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
610 + '}' + '\n';
611 }
612 else {
613 src = this.source;
614 }
615
616 if (opts.client) {
617 src = 'escapeFn = escapeFn || ' + escapeFn.toString() + ';' + '\n' + src;
618 if (opts.compileDebug) {
619 src = 'rethrow = rethrow || ' + rethrow.toString() + ';' + '\n' + src;
620 }
621 }
622
623 if (opts.strict) {
624 src = '"use strict";\n' + src;
625 }
626 if (opts.debug) {
627 console.log(src);
628 }
629 if (opts.compileDebug && opts.filename) {
630 src = src + '\n'
631 + '//# sourceURL=' + opts.filename + '\n';
632 }
633
634 try {
635 if (opts.async) {
636 // Have to use generated function for this, since in envs without support,
637 // it breaks in parsing
638 try {
639 ctor = (new Function('return (async function(){}).constructor;'))();
640 }
641 catch(e) {
642 if (e instanceof SyntaxError) {
643 throw new Error('This environment does not support async/await');
644 }
645 else {
646 throw e;
647 }
648 }
649 }
650 else {
651 ctor = Function;
652 }
653 fn = new ctor(opts.localsName + ', escapeFn, include, rethrow', src);
654 }
655 catch(e) {
656 // istanbul ignore else
657 if (e instanceof SyntaxError) {
658 if (opts.filename) {
659 e.message += ' in ' + opts.filename;
660 }
661 e.message += ' while compiling ejs\n\n';
662 e.message += 'If the above error is not helpful, you may want to try EJS-Lint:\n';
663 e.message += 'https://github.com/RyanZim/EJS-Lint';
664 if (!opts.async) {
665 e.message += '\n';
666 e.message += 'Or, if you meant to create an async function, pass `async: true` as an option.';
667 }
668 }
669 throw e;
670 }
671
672 // Return a callable function which will execute the function
673 // created by the source-code, with the passed data as locals
674 // Adds a local `include` function which allows full recursive include
675 var returnedFn = opts.client ? fn : function anonymous(data) {
676 var include = function (path, includeData) {
677 var d = utils.shallowCopy({}, data);
678 if (includeData) {
679 d = utils.shallowCopy(d, includeData);
680 }
681 return includeFile(path, opts)(d);
682 };
683 return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
684 };
685 returnedFn.dependencies = this.dependencies;
686 if (opts.filename && typeof Object.defineProperty === 'function') {
687 var filename = opts.filename;
688 var basename = path.basename(filename, path.extname(filename));
689 try {
690 Object.defineProperty(returnedFn, 'name', {
691 value: basename,
692 writable: false,
693 enumerable: false,
694 configurable: true
695 });
696 } catch (e) {/* ignore */}
697 }
698 return returnedFn;
699 },
700
701 generateSource: function () {
702 var opts = this.opts;
703
704 if (opts.rmWhitespace) {
705 // Have to use two separate replace here as `^` and `$` operators don't
706 // work well with `\r` and empty lines don't work well with the `m` flag.
707 this.templateText =
708 this.templateText.replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
709 }
710
711 // Slurp spaces and tabs before <%_ and after _%>
712 this.templateText =
713 this.templateText.replace(/[ \t]*<%_/gm, '<%_').replace(/_%>[ \t]*/gm, '_%>');
714
715 var self = this;
716 var matches = this.parseTemplateText();
717 var d = this.opts.delimiter;
718 var o = this.opts.openDelimiter;
719 var c = this.opts.closeDelimiter;
720
721 if (matches && matches.length) {
722 matches.forEach(function (line, index) {
723 var opening;
724 var closing;
725 var include;
726 var includeOpts;
727 var includeObj;
728 var includeSrc;
729 // If this is an opening tag, check for closing tags
730 // FIXME: May end up with some false positives here
731 // Better to store modes as k/v with openDelimiter + delimiter as key
732 // Then this can simply check against the map
733 if ( line.indexOf(o + d) === 0 // If it is a tag
734 && line.indexOf(o + d + d) !== 0) { // and is not escaped
735 closing = matches[index + 2];
736 if (!(closing == d + c || closing == '-' + d + c || closing == '_' + d + c)) {
737 throw new Error('Could not find matching close tag for "' + line + '".');
738 }
739 }
740 // HACK: backward-compat `include` preprocessor directives
741 if (opts.legacyInclude && (include = line.match(/^\s*include\s+(\S+)/))) {
742 opening = matches[index - 1];
743 // Must be in EVAL or RAW mode
744 if (opening && (opening == o + d || opening == o + d + '-' || opening == o + d + '_')) {
745 includeOpts = utils.shallowCopy({}, self.opts);
746 includeObj = includeSource(include[1], includeOpts);
747 if (self.opts.compileDebug) {
748 includeSrc =
749 ' ; (function(){' + '\n'
750 + ' var __line = 1' + '\n'
751 + ' , __lines = ' + JSON.stringify(includeObj.template) + '\n'
752 + ' , __filename = ' + JSON.stringify(includeObj.filename) + ';' + '\n'
753 + ' try {' + '\n'
754 + includeObj.source
755 + ' } catch (e) {' + '\n'
756 + ' rethrow(e, __lines, __filename, __line, escapeFn);' + '\n'
757 + ' }' + '\n'
758 + ' ; }).call(this)' + '\n';
759 }else{
760 includeSrc = ' ; (function(){' + '\n' + includeObj.source +
761 ' ; }).call(this)' + '\n';
762 }
763 self.source += includeSrc;
764 self.dependencies.push(exports.resolveInclude(include[1],
765 includeOpts.filename));
766 return;
767 }
768 }
769 self.scanLine(line);
770 });
771 }
772
773 },
774
775 parseTemplateText: function () {
776 var str = this.templateText;
777 var pat = this.regex;
778 var result = pat.exec(str);
779 var arr = [];
780 var firstPos;
781
782 while (result) {
783 firstPos = result.index;
784
785 if (firstPos !== 0) {
786 arr.push(str.substring(0, firstPos));
787 str = str.slice(firstPos);
788 }
789
790 arr.push(result[0]);
791 str = str.slice(result[0].length);
792 result = pat.exec(str);
793 }
794
795 if (str) {
796 arr.push(str);
797 }
798
799 return arr;
800 },
801
802 _addOutput: function (line) {
803 if (this.truncate) {
804 // Only replace single leading linebreak in the line after
805 // -%> tag -- this is the single, trailing linebreak
806 // after the tag that the truncation mode replaces
807 // Handle Win / Unix / old Mac linebreaks -- do the \r\n
808 // combo first in the regex-or
809 line = line.replace(/^(?:\r\n|\r|\n)/, '');
810 this.truncate = false;
811 }
812 if (!line) {
813 return line;
814 }
815
816 // Preserve literal slashes
817 line = line.replace(/\\/g, '\\\\');
818
819 // Convert linebreaks
820 line = line.replace(/\n/g, '\\n');
821 line = line.replace(/\r/g, '\\r');
822
823 // Escape double-quotes
824 // - this will be the delimiter during execution
825 line = line.replace(/"/g, '\\"');
826 this.source += ' ; __append("' + line + '")' + '\n';
827 },
828
829 scanLine: function (line) {
830 var self = this;
831 var d = this.opts.delimiter;
832 var o = this.opts.openDelimiter;
833 var c = this.opts.closeDelimiter;
834 var newLineCount = 0;
835
836 newLineCount = (line.split('\n').length - 1);
837
838 switch (line) {
839 case o + d:
840 case o + d + '_':
841 this.mode = Template.modes.EVAL;
842 break;
843 case o + d + '=':
844 this.mode = Template.modes.ESCAPED;
845 break;
846 case o + d + '-':
847 this.mode = Template.modes.RAW;
848 break;
849 case o + d + '#':
850 this.mode = Template.modes.COMMENT;
851 break;
852 case o + d + d:
853 this.mode = Template.modes.LITERAL;
854 this.source += ' ; __append("' + line.replace(o + d + d, o + d) + '")' + '\n';
855 break;
856 case d + d + c:
857 this.mode = Template.modes.LITERAL;
858 this.source += ' ; __append("' + line.replace(d + d + c, d + c) + '")' + '\n';
859 break;
860 case d + c:
861 case '-' + d + c:
862 case '_' + d + c:
863 if (this.mode == Template.modes.LITERAL) {
864 this._addOutput(line);
865 }
866
867 this.mode = null;
868 this.truncate = line.indexOf('-') === 0 || line.indexOf('_') === 0;
869 break;
870 default:
871 // In script mode, depends on type of tag
872 if (this.mode) {
873 // If '//' is found without a line break, add a line break.
874 switch (this.mode) {
875 case Template.modes.EVAL:
876 case Template.modes.ESCAPED:
877 case Template.modes.RAW:
878 if (line.lastIndexOf('//') > line.lastIndexOf('\n')) {
879 line += '\n';
880 }
881 }
882 switch (this.mode) {
883 // Just executing code
884 case Template.modes.EVAL:
885 this.source += ' ; ' + line + '\n';
886 break;
887 // Exec, esc, and output
888 case Template.modes.ESCAPED:
889 this.source += ' ; __append(escapeFn(' + stripSemi(line) + '))' + '\n';
890 break;
891 // Exec and output
892 case Template.modes.RAW:
893 this.source += ' ; __append(' + stripSemi(line) + ')' + '\n';
894 break;
895 case Template.modes.COMMENT:
896 // Do nothing
897 break;
898 // Literal <%% mode, append as raw output
899 case Template.modes.LITERAL:
900 this._addOutput(line);
901 break;
902 }
903 }
904 // In string mode, just add the output
905 else {
906 this._addOutput(line);
907 }
908 }
909
910 if (self.opts.compileDebug && newLineCount) {
911 this.currentLine += newLineCount;
912 this.source += ' ; __line = ' + this.currentLine + '\n';
913 }
914 }
915};
916
917/**
918 * Escape characters reserved in XML.
919 *
920 * This is simply an export of {@link module:utils.escapeXML}.
921 *
922 * If `markup` is `undefined` or `null`, the empty string is returned.
923 *
924 * @param {String} markup Input string
925 * @return {String} Escaped string
926 * @public
927 * @func
928 * */
929exports.escapeXML = utils.escapeXML;
930
931/**
932 * Express.js support.
933 *
934 * This is an alias for {@link module:ejs.renderFile}, in order to support
935 * Express.js out-of-the-box.
936 *
937 * @func
938 */
939
940exports.__express = exports.renderFile;
941
942// Add require support
943/* istanbul ignore else */
944if (require.extensions) {
945 require.extensions['.ejs'] = function (module, flnm) {
946 console.log('Deprecated: this API will go away in EJS v2.8');
947 var filename = flnm || /* istanbul ignore next */ module.filename;
948 var options = {
949 filename: filename,
950 client: true
951 };
952 var template = fileLoader(filename).toString();
953 var fn = exports.compile(template, options);
954 module._compile('module.exports = ' + fn.toString() + ';', filename);
955 };
956}
957
958/**
959 * Version of EJS.
960 *
961 * @readonly
962 * @type {String}
963 * @public
964 */
965
966exports.VERSION = _VERSION_STRING;
967
968/**
969 * Name for detection of EJS.
970 *
971 * @readonly
972 * @type {String}
973 * @public
974 */
975
976exports.name = _NAME;
977
978/* istanbul ignore if */
979if (typeof window != 'undefined') {
980 window.ejs = exports;
981}
982
983},{"../package.json":6,"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
984/*
985 * EJS Embedded JavaScript templates
986 * Copyright 2112 Matthew Eernisse (mde@fleegix.org)
987 *
988 * Licensed under the Apache License, Version 2.0 (the "License");
989 * you may not use this file except in compliance with the License.
990 * You may obtain a copy of the License at
991 *
992 * http://www.apache.org/licenses/LICENSE-2.0
993 *
994 * Unless required by applicable law or agreed to in writing, software
995 * distributed under the License is distributed on an "AS IS" BASIS,
996 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
997 * See the License for the specific language governing permissions and
998 * limitations under the License.
999 *
1000*/
1001
1002/**
1003 * Private utility functions
1004 * @module utils
1005 * @private
1006 */
1007
1008'use strict';
1009
1010var regExpChars = /[|\\{}()[\]^$+*?.]/g;
1011
1012/**
1013 * Escape characters reserved in regular expressions.
1014 *
1015 * If `string` is `undefined` or `null`, the empty string is returned.
1016 *
1017 * @param {String} string Input string
1018 * @return {String} Escaped string
1019 * @static
1020 * @private
1021 */
1022exports.escapeRegExpChars = function (string) {
1023 // istanbul ignore if
1024 if (!string) {
1025 return '';
1026 }
1027 return String(string).replace(regExpChars, '\\$&');
1028};
1029
1030var _ENCODE_HTML_RULES = {
1031 '&': '&amp;',
1032 '<': '&lt;',
1033 '>': '&gt;',
1034 '"': '&#34;',
1035 "'": '&#39;'
1036};
1037var _MATCH_HTML = /[&<>'"]/g;
1038
1039function encode_char(c) {
1040 return _ENCODE_HTML_RULES[c] || c;
1041}
1042
1043/**
1044 * Stringified version of constants used by {@link module:utils.escapeXML}.
1045 *
1046 * It is used in the process of generating {@link ClientFunction}s.
1047 *
1048 * @readonly
1049 * @type {String}
1050 */
1051
1052var escapeFuncStr =
1053 'var _ENCODE_HTML_RULES = {\n'
1054+ ' "&": "&amp;"\n'
1055+ ' , "<": "&lt;"\n'
1056+ ' , ">": "&gt;"\n'
1057+ ' , \'"\': "&#34;"\n'
1058+ ' , "\'": "&#39;"\n'
1059+ ' }\n'
1060+ ' , _MATCH_HTML = /[&<>\'"]/g;\n'
1061+ 'function encode_char(c) {\n'
1062+ ' return _ENCODE_HTML_RULES[c] || c;\n'
1063+ '};\n';
1064
1065/**
1066 * Escape characters reserved in XML.
1067 *
1068 * If `markup` is `undefined` or `null`, the empty string is returned.
1069 *
1070 * @implements {EscapeCallback}
1071 * @param {String} markup Input string
1072 * @return {String} Escaped string
1073 * @static
1074 * @private
1075 */
1076
1077exports.escapeXML = function (markup) {
1078 return markup == undefined
1079 ? ''
1080 : String(markup)
1081 .replace(_MATCH_HTML, encode_char);
1082};
1083exports.escapeXML.toString = function () {
1084 return Function.prototype.toString.call(this) + ';\n' + escapeFuncStr;
1085};
1086
1087/**
1088 * Naive copy of properties from one object to another.
1089 * Does not recurse into non-scalar properties
1090 * Does not check to see if the property has a value before copying
1091 *
1092 * @param {Object} to Destination object
1093 * @param {Object} from Source object
1094 * @return {Object} Destination object
1095 * @static
1096 * @private
1097 */
1098exports.shallowCopy = function (to, from) {
1099 from = from || {};
1100 for (var p in from) {
1101 to[p] = from[p];
1102 }
1103 return to;
1104};
1105
1106/**
1107 * Naive copy of a list of key names, from one object to another.
1108 * Only copies property if it is actually defined
1109 * Does not recurse into non-scalar properties
1110 *
1111 * @param {Object} to Destination object
1112 * @param {Object} from Source object
1113 * @param {Array} list List of properties to copy
1114 * @return {Object} Destination object
1115 * @static
1116 * @private
1117 */
1118exports.shallowCopyFromList = function (to, from, list) {
1119 for (var i = 0; i < list.length; i++) {
1120 var p = list[i];
1121 if (typeof from[p] != 'undefined') {
1122 to[p] = from[p];
1123 }
1124 }
1125 return to;
1126};
1127
1128/**
1129 * Simple in-process cache implementation. Does not implement limits of any
1130 * sort.
1131 *
1132 * @implements Cache
1133 * @static
1134 * @private
1135 */
1136exports.cache = {
1137 _data: {},
1138 set: function (key, val) {
1139 this._data[key] = val;
1140 },
1141 get: function (key) {
1142 return this._data[key];
1143 },
1144 remove: function (key) {
1145 delete this._data[key];
1146 },
1147 reset: function () {
1148 this._data = {};
1149 }
1150};
1151
1152},{}],3:[function(require,module,exports){
1153
1154},{}],4:[function(require,module,exports){
1155(function (process){
1156// .dirname, .basename, and .extname methods are extracted from Node.js v8.11.1,
1157// backported and transplited with Babel, with backwards-compat fixes
1158
1159// Copyright Joyent, Inc. and other Node contributors.
1160//
1161// Permission is hereby granted, free of charge, to any person obtaining a
1162// copy of this software and associated documentation files (the
1163// "Software"), to deal in the Software without restriction, including
1164// without limitation the rights to use, copy, modify, merge, publish,
1165// distribute, sublicense, and/or sell copies of the Software, and to permit
1166// persons to whom the Software is furnished to do so, subject to the
1167// following conditions:
1168//
1169// The above copyright notice and this permission notice shall be included
1170// in all copies or substantial portions of the Software.
1171//
1172// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1173// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1174// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1175// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1176// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1177// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1178// USE OR OTHER DEALINGS IN THE SOFTWARE.
1179
1180// resolves . and .. elements in a path array with directory names there
1181// must be no slashes, empty elements, or device names (c:\) in the array
1182// (so also no leading and trailing slashes - it does not distinguish
1183// relative and absolute paths)
1184function normalizeArray(parts, allowAboveRoot) {
1185 // if the path tries to go above the root, `up` ends up > 0
1186 var up = 0;
1187 for (var i = parts.length - 1; i >= 0; i--) {
1188 var last = parts[i];
1189 if (last === '.') {
1190 parts.splice(i, 1);
1191 } else if (last === '..') {
1192 parts.splice(i, 1);
1193 up++;
1194 } else if (up) {
1195 parts.splice(i, 1);
1196 up--;
1197 }
1198 }
1199
1200 // if the path is allowed to go above the root, restore leading ..s
1201 if (allowAboveRoot) {
1202 for (; up--; up) {
1203 parts.unshift('..');
1204 }
1205 }
1206
1207 return parts;
1208}
1209
1210// path.resolve([from ...], to)
1211// posix version
1212exports.resolve = function() {
1213 var resolvedPath = '',
1214 resolvedAbsolute = false;
1215
1216 for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1217 var path = (i >= 0) ? arguments[i] : process.cwd();
1218
1219 // Skip empty and invalid entries
1220 if (typeof path !== 'string') {
1221 throw new TypeError('Arguments to path.resolve must be strings');
1222 } else if (!path) {
1223 continue;
1224 }
1225
1226 resolvedPath = path + '/' + resolvedPath;
1227 resolvedAbsolute = path.charAt(0) === '/';
1228 }
1229
1230 // At this point the path should be resolved to a full absolute path, but
1231 // handle relative paths to be safe (might happen when process.cwd() fails)
1232
1233 // Normalize the path
1234 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
1235 return !!p;
1236 }), !resolvedAbsolute).join('/');
1237
1238 return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
1239};
1240
1241// path.normalize(path)
1242// posix version
1243exports.normalize = function(path) {
1244 var isAbsolute = exports.isAbsolute(path),
1245 trailingSlash = substr(path, -1) === '/';
1246
1247 // Normalize the path
1248 path = normalizeArray(filter(path.split('/'), function(p) {
1249 return !!p;
1250 }), !isAbsolute).join('/');
1251
1252 if (!path && !isAbsolute) {
1253 path = '.';
1254 }
1255 if (path && trailingSlash) {
1256 path += '/';
1257 }
1258
1259 return (isAbsolute ? '/' : '') + path;
1260};
1261
1262// posix version
1263exports.isAbsolute = function(path) {
1264 return path.charAt(0) === '/';
1265};
1266
1267// posix version
1268exports.join = function() {
1269 var paths = Array.prototype.slice.call(arguments, 0);
1270 return exports.normalize(filter(paths, function(p, index) {
1271 if (typeof p !== 'string') {
1272 throw new TypeError('Arguments to path.join must be strings');
1273 }
1274 return p;
1275 }).join('/'));
1276};
1277
1278
1279// path.relative(from, to)
1280// posix version
1281exports.relative = function(from, to) {
1282 from = exports.resolve(from).substr(1);
1283 to = exports.resolve(to).substr(1);
1284
1285 function trim(arr) {
1286 var start = 0;
1287 for (; start < arr.length; start++) {
1288 if (arr[start] !== '') break;
1289 }
1290
1291 var end = arr.length - 1;
1292 for (; end >= 0; end--) {
1293 if (arr[end] !== '') break;
1294 }
1295
1296 if (start > end) return [];
1297 return arr.slice(start, end - start + 1);
1298 }
1299
1300 var fromParts = trim(from.split('/'));
1301 var toParts = trim(to.split('/'));
1302
1303 var length = Math.min(fromParts.length, toParts.length);
1304 var samePartsLength = length;
1305 for (var i = 0; i < length; i++) {
1306 if (fromParts[i] !== toParts[i]) {
1307 samePartsLength = i;
1308 break;
1309 }
1310 }
1311
1312 var outputParts = [];
1313 for (var i = samePartsLength; i < fromParts.length; i++) {
1314 outputParts.push('..');
1315 }
1316
1317 outputParts = outputParts.concat(toParts.slice(samePartsLength));
1318
1319 return outputParts.join('/');
1320};
1321
1322exports.sep = '/';
1323exports.delimiter = ':';
1324
1325exports.dirname = function (path) {
1326 if (typeof path !== 'string') path = path + '';
1327 if (path.length === 0) return '.';
1328 var code = path.charCodeAt(0);
1329 var hasRoot = code === 47 /*/*/;
1330 var end = -1;
1331 var matchedSlash = true;
1332 for (var i = path.length - 1; i >= 1; --i) {
1333 code = path.charCodeAt(i);
1334 if (code === 47 /*/*/) {
1335 if (!matchedSlash) {
1336 end = i;
1337 break;
1338 }
1339 } else {
1340 // We saw the first non-path separator
1341 matchedSlash = false;
1342 }
1343 }
1344
1345 if (end === -1) return hasRoot ? '/' : '.';
1346 if (hasRoot && end === 1) {
1347 // return '//';
1348 // Backwards-compat fix:
1349 return '/';
1350 }
1351 return path.slice(0, end);
1352};
1353
1354function basename(path) {
1355 if (typeof path !== 'string') path = path + '';
1356
1357 var start = 0;
1358 var end = -1;
1359 var matchedSlash = true;
1360 var i;
1361
1362 for (i = path.length - 1; i >= 0; --i) {
1363 if (path.charCodeAt(i) === 47 /*/*/) {
1364 // If we reached a path separator that was not part of a set of path
1365 // separators at the end of the string, stop now
1366 if (!matchedSlash) {
1367 start = i + 1;
1368 break;
1369 }
1370 } else if (end === -1) {
1371 // We saw the first non-path separator, mark this as the end of our
1372 // path component
1373 matchedSlash = false;
1374 end = i + 1;
1375 }
1376 }
1377
1378 if (end === -1) return '';
1379 return path.slice(start, end);
1380}
1381
1382// Uses a mixed approach for backwards-compatibility, as ext behavior changed
1383// in new Node.js versions, so only basename() above is backported here
1384exports.basename = function (path, ext) {
1385 var f = basename(path);
1386 if (ext && f.substr(-1 * ext.length) === ext) {
1387 f = f.substr(0, f.length - ext.length);
1388 }
1389 return f;
1390};
1391
1392exports.extname = function (path) {
1393 if (typeof path !== 'string') path = path + '';
1394 var startDot = -1;
1395 var startPart = 0;
1396 var end = -1;
1397 var matchedSlash = true;
1398 // Track the state of characters (if any) we see before our first dot and
1399 // after any path separator we find
1400 var preDotState = 0;
1401 for (var i = path.length - 1; i >= 0; --i) {
1402 var code = path.charCodeAt(i);
1403 if (code === 47 /*/*/) {
1404 // If we reached a path separator that was not part of a set of path
1405 // separators at the end of the string, stop now
1406 if (!matchedSlash) {
1407 startPart = i + 1;
1408 break;
1409 }
1410 continue;
1411 }
1412 if (end === -1) {
1413 // We saw the first non-path separator, mark this as the end of our
1414 // extension
1415 matchedSlash = false;
1416 end = i + 1;
1417 }
1418 if (code === 46 /*.*/) {
1419 // If this is our first dot, mark it as the start of our extension
1420 if (startDot === -1)
1421 startDot = i;
1422 else if (preDotState !== 1)
1423 preDotState = 1;
1424 } else if (startDot !== -1) {
1425 // We saw a non-dot and non-path separator before our dot, so we should
1426 // have a good chance at having a non-empty extension
1427 preDotState = -1;
1428 }
1429 }
1430
1431 if (startDot === -1 || end === -1 ||
1432 // We saw a non-dot character immediately before the dot
1433 preDotState === 0 ||
1434 // The (right-most) trimmed path component is exactly '..'
1435 preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
1436 return '';
1437 }
1438 return path.slice(startDot, end);
1439};
1440
1441function filter (xs, f) {
1442 if (xs.filter) return xs.filter(f);
1443 var res = [];
1444 for (var i = 0; i < xs.length; i++) {
1445 if (f(xs[i], i, xs)) res.push(xs[i]);
1446 }
1447 return res;
1448}
1449
1450// String.prototype.substr - negative index don't work in IE8
1451var substr = 'ab'.substr(-1) === 'b'
1452 ? function (str, start, len) { return str.substr(start, len) }
1453 : function (str, start, len) {
1454 if (start < 0) start = str.length + start;
1455 return str.substr(start, len);
1456 }
1457;
1458
1459}).call(this,require('_process'))
1460},{"_process":5}],5:[function(require,module,exports){
1461// shim for using process in browser
1462var process = module.exports = {};
1463
1464// cached from whatever global is present so that test runners that stub it
1465// don't break things. But we need to wrap it in a try catch in case it is
1466// wrapped in strict mode code which doesn't define any globals. It's inside a
1467// function because try/catches deoptimize in certain engines.
1468
1469var cachedSetTimeout;
1470var cachedClearTimeout;
1471
1472function defaultSetTimout() {
1473 throw new Error('setTimeout has not been defined');
1474}
1475function defaultClearTimeout () {
1476 throw new Error('clearTimeout has not been defined');
1477}
1478(function () {
1479 try {
1480 if (typeof setTimeout === 'function') {
1481 cachedSetTimeout = setTimeout;
1482 } else {
1483 cachedSetTimeout = defaultSetTimout;
1484 }
1485 } catch (e) {
1486 cachedSetTimeout = defaultSetTimout;
1487 }
1488 try {
1489 if (typeof clearTimeout === 'function') {
1490 cachedClearTimeout = clearTimeout;
1491 } else {
1492 cachedClearTimeout = defaultClearTimeout;
1493 }
1494 } catch (e) {
1495 cachedClearTimeout = defaultClearTimeout;
1496 }
1497} ())
1498function runTimeout(fun) {
1499 if (cachedSetTimeout === setTimeout) {
1500 //normal enviroments in sane situations
1501 return setTimeout(fun, 0);
1502 }
1503 // if setTimeout wasn't available but was latter defined
1504 if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
1505 cachedSetTimeout = setTimeout;
1506 return setTimeout(fun, 0);
1507 }
1508 try {
1509 // when when somebody has screwed with setTimeout but no I.E. maddness
1510 return cachedSetTimeout(fun, 0);
1511 } catch(e){
1512 try {
1513 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1514 return cachedSetTimeout.call(null, fun, 0);
1515 } catch(e){
1516 // 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
1517 return cachedSetTimeout.call(this, fun, 0);
1518 }
1519 }
1520
1521
1522}
1523function runClearTimeout(marker) {
1524 if (cachedClearTimeout === clearTimeout) {
1525 //normal enviroments in sane situations
1526 return clearTimeout(marker);
1527 }
1528 // if clearTimeout wasn't available but was latter defined
1529 if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
1530 cachedClearTimeout = clearTimeout;
1531 return clearTimeout(marker);
1532 }
1533 try {
1534 // when when somebody has screwed with setTimeout but no I.E. maddness
1535 return cachedClearTimeout(marker);
1536 } catch (e){
1537 try {
1538 // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
1539 return cachedClearTimeout.call(null, marker);
1540 } catch (e){
1541 // 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.
1542 // Some versions of I.E. have different rules for clearTimeout vs setTimeout
1543 return cachedClearTimeout.call(this, marker);
1544 }
1545 }
1546
1547
1548
1549}
1550var queue = [];
1551var draining = false;
1552var currentQueue;
1553var queueIndex = -1;
1554
1555function cleanUpNextTick() {
1556 if (!draining || !currentQueue) {
1557 return;
1558 }
1559 draining = false;
1560 if (currentQueue.length) {
1561 queue = currentQueue.concat(queue);
1562 } else {
1563 queueIndex = -1;
1564 }
1565 if (queue.length) {
1566 drainQueue();
1567 }
1568}
1569
1570function drainQueue() {
1571 if (draining) {
1572 return;
1573 }
1574 var timeout = runTimeout(cleanUpNextTick);
1575 draining = true;
1576
1577 var len = queue.length;
1578 while(len) {
1579 currentQueue = queue;
1580 queue = [];
1581 while (++queueIndex < len) {
1582 if (currentQueue) {
1583 currentQueue[queueIndex].run();
1584 }
1585 }
1586 queueIndex = -1;
1587 len = queue.length;
1588 }
1589 currentQueue = null;
1590 draining = false;
1591 runClearTimeout(timeout);
1592}
1593
1594process.nextTick = function (fun) {
1595 var args = new Array(arguments.length - 1);
1596 if (arguments.length > 1) {
1597 for (var i = 1; i < arguments.length; i++) {
1598 args[i - 1] = arguments[i];
1599 }
1600 }
1601 queue.push(new Item(fun, args));
1602 if (queue.length === 1 && !draining) {
1603 runTimeout(drainQueue);
1604 }
1605};
1606
1607// v8 likes predictible objects
1608function Item(fun, array) {
1609 this.fun = fun;
1610 this.array = array;
1611}
1612Item.prototype.run = function () {
1613 this.fun.apply(null, this.array);
1614};
1615process.title = 'browser';
1616process.browser = true;
1617process.env = {};
1618process.argv = [];
1619process.version = ''; // empty string to avoid regexp issues
1620process.versions = {};
1621
1622function noop() {}
1623
1624process.on = noop;
1625process.addListener = noop;
1626process.once = noop;
1627process.off = noop;
1628process.removeListener = noop;
1629process.removeAllListeners = noop;
1630process.emit = noop;
1631process.prependListener = noop;
1632process.prependOnceListener = noop;
1633
1634process.listeners = function (name) { return [] }
1635
1636process.binding = function (name) {
1637 throw new Error('process.binding is not supported');
1638};
1639
1640process.cwd = function () { return '/' };
1641process.chdir = function (dir) {
1642 throw new Error('process.chdir is not supported');
1643};
1644process.umask = function() { return 0; };
1645
1646},{}],6:[function(require,module,exports){
1647module.exports={
1648 "name": "ejs",
1649 "description": "Embedded JavaScript templates",
1650 "keywords": [
1651 "template",
1652 "engine",
1653 "ejs"
1654 ],
1655 "version": "2.7.4",
1656 "author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
1657 "license": "Apache-2.0",
1658 "main": "./lib/ejs.js",
1659 "repository": {
1660 "type": "git",
1661 "url": "git://github.com/mde/ejs.git"
1662 },
1663 "bugs": "https://github.com/mde/ejs/issues",
1664 "homepage": "https://github.com/mde/ejs",
1665 "dependencies": {},
1666 "devDependencies": {
1667 "browserify": "^13.1.1",
1668 "eslint": "^4.14.0",
1669 "git-directory-deploy": "^1.5.1",
1670 "jake": "^10.3.1",
1671 "jsdoc": "^3.4.0",
1672 "lru-cache": "^4.0.1",
1673 "mocha": "^5.0.5",
1674 "uglify-js": "^3.3.16"
1675 },
1676 "engines": {
1677 "node": ">=0.10.0"
1678 },
1679 "scripts": {
1680 "test": "mocha",
1681 "postinstall": "node ./postinstall.js"
1682 }
1683}
1684
1685},{}]},{},[1])(1)
1686});