1 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | "use strict";
|
21 |
|
22 | var utils = require('./utils')
|
23 | , ejs
|
24 | , templateCache = {}
|
25 | , jsCache = {}
|
26 | , includeFile
|
27 | , includeSource
|
28 | , resolveInclude
|
29 | , compile
|
30 | , rethrow
|
31 | , _DEFAULT_DELIMITER = '%'
|
32 | , _REGEX_STRING = '(<%%)|(<%=)|(<%-)|(<%#)|(<%)|(%>)|(-%>)'
|
33 | , _OPTS_MAP = {
|
34 | cache: 'cache'
|
35 | , filename: 'filename'
|
36 | , delimiter: 'delimiter'
|
37 | , scope: 'context'
|
38 | , context: 'context'
|
39 | , debug: 'debug'
|
40 | , compileDebug: 'compileDebug'
|
41 | , client: 'client'
|
42 | };
|
43 |
|
44 | resolveInclude = function (name, filename) {
|
45 | var path = require('path')
|
46 | , dirname = path.dirname
|
47 | , extname = path.extname
|
48 | , resolve = path.resolve
|
49 | , includePath = resolve(dirname(filename), name)
|
50 | , ext = extname(name);
|
51 | if (!ext) {
|
52 | includePath += '.ejs';
|
53 | }
|
54 | return includePath;
|
55 | };
|
56 |
|
57 | includeFile = function (path, options) {
|
58 | var fn
|
59 | , opts = utils.shallowCopy({}, options || {})
|
60 | , fs = require('fs')
|
61 | , includePath
|
62 | , template;
|
63 | if (!opts.filename) {
|
64 | throw new Error('`include` requires the \'filename\' option.');
|
65 | }
|
66 | includePath = resolveInclude(path, opts.filename);
|
67 | if (opts.cache) {
|
68 | template = templateCache[includePath];
|
69 | if (!template) {
|
70 | template = fs.readFileSync(includePath).toString().trim();
|
71 | templateCache[includePath] = template;
|
72 | }
|
73 | }
|
74 | else {
|
75 | template = fs.readFileSync(includePath).toString().trim();
|
76 | }
|
77 |
|
78 | opts.filename = includePath;
|
79 | fn = exports.compile(template, opts);
|
80 | return fn;
|
81 | };
|
82 |
|
83 | includeSource = function (path, options) {
|
84 | var fn
|
85 | , opts = utils.shallowCopy({}, options || {})
|
86 | , fs = require('fs')
|
87 | , includePath
|
88 | , template;
|
89 | if (!opts.filename) {
|
90 | throw new Error('`include` requires the \'filename\' option.');
|
91 | }
|
92 | includePath = resolveInclude(path, opts.filename);
|
93 | if (opts.cache) {
|
94 | template = templateCache[includePath];
|
95 | if (!template) {
|
96 | template = fs.readFileSync(includePath).toString().trim();
|
97 | templateCache[includePath] = template;
|
98 | }
|
99 | }
|
100 | else {
|
101 | template = fs.readFileSync(includePath).toString().trim();
|
102 | }
|
103 |
|
104 | opts.filename = includePath;
|
105 | var templ = new Template(template, opts);
|
106 | templ.generateSource();
|
107 | return templ.source;
|
108 | };
|
109 |
|
110 | rethrow = function (err, str, filename, lineno){
|
111 | var lines = str.split('\n')
|
112 | , start = Math.max(lineno - 3, 0)
|
113 | , end = Math.min(lines.length, lineno + 3);
|
114 |
|
115 |
|
116 | var context = lines.slice(start, end).map(function(line, i){
|
117 | var curr = i + start + 1;
|
118 | return (curr == lineno ? ' >> ' : ' ')
|
119 | + curr
|
120 | + '| '
|
121 | + line;
|
122 | }).join('\n');
|
123 |
|
124 |
|
125 | err.path = filename;
|
126 | err.message = (filename || 'ejs') + ':'
|
127 | + lineno + '\n'
|
128 | + context + '\n\n'
|
129 | + err.message;
|
130 |
|
131 | throw err;
|
132 | }
|
133 |
|
134 | compile = exports.compile = function (template, opts) {
|
135 | var templ = new Template(template, opts);
|
136 | return templ.compile();
|
137 | };
|
138 |
|
139 |
|
140 |
|
141 | exports.render = function () {
|
142 | var args = Array.prototype.slice.call(arguments)
|
143 | , template = args.shift()
|
144 | , data = args.shift() || {}
|
145 | , opts = args.shift() || {}
|
146 | , fn
|
147 | , filename;
|
148 |
|
149 |
|
150 |
|
151 | if (arguments.length == 2) {
|
152 | for (var p in _OPTS_MAP) {
|
153 | if (typeof data[p] != 'undefined') {
|
154 | opts[_OPTS_MAP[p]] = data[p];
|
155 | }
|
156 | }
|
157 | }
|
158 |
|
159 |
|
160 |
|
161 | if (opts.scope) {
|
162 | if (!opts.context) {
|
163 | opts.context = opts.scope;
|
164 | }
|
165 | delete opts.scope;
|
166 | }
|
167 |
|
168 | if (opts.cache) {
|
169 | filename = opts.filename;
|
170 | if (!filename) {
|
171 | throw new Error('cache option requires a filename');
|
172 | }
|
173 | fn = jsCache[filename];
|
174 | if (!fn) {
|
175 | fn = exports.compile(template, opts);
|
176 | jsCache[filename] = fn;
|
177 | }
|
178 | }
|
179 | else {
|
180 | fn = exports.compile(template, opts);
|
181 | }
|
182 | return fn.call(opts.context, data);
|
183 | };
|
184 |
|
185 |
|
186 |
|
187 | exports.renderFile = function () {
|
188 | var read = require('fs').readFile
|
189 | , args = Array.prototype.slice.call(arguments)
|
190 | , path = args.shift()
|
191 | , cb = args.pop()
|
192 | , data = args.shift() || {}
|
193 | , opts = args.pop() || {}
|
194 | , template
|
195 | , handleTemplate;
|
196 |
|
197 |
|
198 | opts.filename = path;
|
199 |
|
200 | handleTemplate = function (template) {
|
201 | var result
|
202 | , failed = false;
|
203 | try {
|
204 | result = exports.render(template, data, opts);
|
205 | }
|
206 | catch(err) {
|
207 | cb(err);
|
208 | failed = true;
|
209 | }
|
210 | if (!failed) cb(null, result);
|
211 | };
|
212 |
|
213 | template = templateCache[path];
|
214 | if (opts.cache && template) {
|
215 | handleTemplate(template);
|
216 | }
|
217 | else {
|
218 | read(path, function (err, data) {
|
219 | var tmpl;
|
220 | if (err) {
|
221 | return cb(err);
|
222 | }
|
223 | tmpl = data.toString().trim();
|
224 | if (opts.cache) {
|
225 | templateCache[path] = tmpl;
|
226 | }
|
227 | handleTemplate(tmpl);
|
228 | });
|
229 | }
|
230 | };
|
231 |
|
232 | exports.clearCache = function () {
|
233 | templateCache = {};
|
234 | jsCache = {};
|
235 | };
|
236 |
|
237 | var Template = function (text, opts) {
|
238 | opts = opts || {};
|
239 | var options = {};
|
240 | this.templateText = text;
|
241 | this.mode = null;
|
242 | this.truncate = false;
|
243 | this.currentLine = 1;
|
244 | this.source = '';
|
245 | options.client = opts.client || false;
|
246 | options.escapeFunction = opts.escape || utils.escapeXML;
|
247 | options.compileDebug = opts.compileDebug !== false;
|
248 | options.debug = !!opts.debug;
|
249 | options.filename = opts.filename;
|
250 | options.delimiter = opts.delimiter || exports.delimiter || _DEFAULT_DELIMITER;
|
251 | options._with = opts._with != null ? opts._with : true
|
252 | this.opts = options;
|
253 |
|
254 | this.regex = this.createRegex();
|
255 | };
|
256 |
|
257 | Template.prototype = new function () {
|
258 |
|
259 | this.modes = {
|
260 | EVAL: 'eval'
|
261 | , ESCAPED: 'escaped'
|
262 | , RAW: 'raw'
|
263 | , APPEND: 'append'
|
264 | , COMMENT: 'comment'
|
265 | , LITERAL: 'literal'
|
266 | };
|
267 |
|
268 | this.createRegex = function () {
|
269 | var str = _REGEX_STRING
|
270 | , delim = utils.escapeRegExpChars(this.opts.delimiter);
|
271 | str = str.replace(/%/g, delim);
|
272 | return new RegExp(str);
|
273 | };
|
274 |
|
275 | this.compile = function () {
|
276 | var self = this
|
277 | , src
|
278 | , fn
|
279 | , opts = this.opts
|
280 | , escape = opts.escapeFunction;
|
281 |
|
282 | if (!this.source) {
|
283 | this.generateSource();
|
284 | var appended = 'var __output = "";';
|
285 | if (opts._with !== false) appended += ' with (locals || {}) { ';
|
286 | this.source = appended + this.source;
|
287 | if (opts._with !== false) this.source += '}';
|
288 | this.source += 'return __output.trim();';
|
289 | }
|
290 |
|
291 | if (opts.compileDebug) {
|
292 | src = 'var __line = 1' +
|
293 | ', __lines = ' + JSON.stringify(this.templateText) +
|
294 | ', __filename = ' + (opts.filename ?
|
295 | JSON.stringify(opts.filename) : 'undefined') +
|
296 | '; try {' +
|
297 | this.source + '} catch (e) { rethrow(e, __lines, __filename, __line); }';
|
298 | }
|
299 | else {
|
300 | src = this.source;
|
301 | }
|
302 |
|
303 | if (opts.debug) {
|
304 | console.log(src);
|
305 | }
|
306 |
|
307 | if (opts.client) {
|
308 | src = 'escape = escape || ' + escape.toString() + ';\n' + src;
|
309 | src = 'rethrow = rethrow || ' + rethrow.toString() + ';\n' + src;
|
310 | }
|
311 |
|
312 | try {
|
313 | fn = new Function('locals, escape, include, rethrow', src);
|
314 | }
|
315 | catch(e) {
|
316 | if (e instanceof SyntaxError) {
|
317 | if (opts.filename) {
|
318 | e.message += ' in ' + opts.filename;
|
319 | }
|
320 | e.message += ' while compiling ejs';
|
321 | throw e;
|
322 | }
|
323 | }
|
324 |
|
325 | if (opts.client) {
|
326 | return fn;
|
327 | }
|
328 |
|
329 |
|
330 |
|
331 | return function (data) {
|
332 | var include = function (path, includeData) {
|
333 | var d = utils.shallowCopy({}, data);
|
334 | if (includeData) {
|
335 | d = utils.shallowCopy(d, includeData);
|
336 | }
|
337 | return includeFile(path, opts).apply(this, [d]);
|
338 | };
|
339 | return fn.apply(this, [data || {}, escape, include, rethrow]);
|
340 | };
|
341 |
|
342 | };
|
343 |
|
344 | this.generateSource = function () {
|
345 | var self = this
|
346 | , matches = this.parseTemplateText()
|
347 | , d = this.opts.delimiter;
|
348 |
|
349 | if (matches && matches.length) {
|
350 | matches.forEach(function (line, index) {
|
351 | var closing
|
352 | , include
|
353 | , includeOpts
|
354 | , includeSrc;
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | if (line.indexOf('<' + d) === 0) {
|
360 | closing = matches[index + 2];
|
361 | if (!(closing == d + '>' || closing == '-' + d + '>')) {
|
362 | throw new Error('Could not find matching close tag for "' + line + '".');
|
363 | }
|
364 | }
|
365 |
|
366 | if ((include = line.match(/^\s*include\s+(\S+)/))) {
|
367 | includeOpts = utils.shallowCopy({}, self.opts);
|
368 | includeSrc = includeSource(include[1], includeOpts);
|
369 | includeSrc = ";(function(){" + includeSrc + "})();";
|
370 | self.source += includeSrc;
|
371 | }
|
372 | else {
|
373 | self.scanLine(line);
|
374 | }
|
375 | });
|
376 | }
|
377 |
|
378 | };
|
379 |
|
380 | this.parseTemplateText = function () {
|
381 | var str = this.templateText
|
382 | , pat = this.regex
|
383 | , result = pat.exec(str)
|
384 | , arr = []
|
385 | , firstPos
|
386 | , lastPos;
|
387 |
|
388 | while (result) {
|
389 | firstPos = result.index;
|
390 | lastPos = pat.lastIndex;
|
391 |
|
392 | if (firstPos !== 0) {
|
393 | arr.push(str.substring(0, firstPos));
|
394 | str = str.slice(firstPos);
|
395 | }
|
396 |
|
397 | arr.push(result[0]);
|
398 | str = str.slice(result[0].length);
|
399 | result = pat.exec(str);
|
400 | }
|
401 |
|
402 | if (str !== '') {
|
403 | arr.push(str);
|
404 | }
|
405 |
|
406 | return arr;
|
407 | };
|
408 |
|
409 | this.scanLine = function (line) {
|
410 | var self = this
|
411 | , d = this.opts.delimiter
|
412 | , newLineCount = 0
|
413 | , _addOutput;
|
414 |
|
415 | _addOutput = function () {
|
416 | if (self.truncate) {
|
417 | line = line.replace('\n', '');
|
418 | }
|
419 |
|
420 |
|
421 | line = line.replace(/\\/g, '\\\\');
|
422 |
|
423 |
|
424 | line = line.replace(/\n/g, '\\n');
|
425 | line = line.replace(/\r/g, '\\r');
|
426 |
|
427 |
|
428 |
|
429 | line = line.replace(/"/g, '\\"');
|
430 | self.source += ';__output += "' + line + '";';
|
431 | };
|
432 |
|
433 | newLineCount = (line.split('\n').length - 1);
|
434 |
|
435 | switch (line) {
|
436 | case '<' + d:
|
437 | this.mode = this.modes.EVAL;
|
438 | break;
|
439 | case '<' + d + '=':
|
440 | this.mode = this.modes.ESCAPED;
|
441 | break;
|
442 | case '<' + d + '-':
|
443 | this.mode = this.modes.RAW;
|
444 | break;
|
445 | case '<' + d + '#':
|
446 | this.mode = this.modes.COMMENT;
|
447 | break;
|
448 | case '<' + d + d:
|
449 | this.mode = this.modes.LITERAL;
|
450 | this.source += ';__output += "' + line.replace('<' + d + d, '<' + d) + '";';
|
451 | break;
|
452 | case d + '>':
|
453 | case '-' + d + '>':
|
454 | if (this.mode == this.modes.LITERAL) {
|
455 | _addOutput();
|
456 | }
|
457 |
|
458 | this.mode = null;
|
459 | this.truncate = line.indexOf('-') === 0;
|
460 | break;
|
461 | default:
|
462 |
|
463 | if (this.mode) {
|
464 |
|
465 | switch (this.mode) {
|
466 | case this.modes.EVAL:
|
467 | case this.modes.ESCAPED:
|
468 | case this.modes.RAW:
|
469 | line = line.replace(/\/\/.*$/, '');
|
470 | }
|
471 | switch (this.mode) {
|
472 |
|
473 | case this.modes.EVAL:
|
474 | this.source += ';' + line;
|
475 | break;
|
476 |
|
477 | case this.modes.ESCAPED:
|
478 |
|
479 | this.source += ';__output += escape(' +
|
480 | line.replace(/;\S*/, '').trim() + ');';
|
481 | break;
|
482 |
|
483 | case this.modes.RAW:
|
484 |
|
485 | this.source += ';__output += ' + line.trim() + ';';
|
486 | break;
|
487 | case this.modes.COMMENT:
|
488 |
|
489 | break;
|
490 |
|
491 | case this.modes.LITERAL:
|
492 | _addOutput();
|
493 | break;
|
494 | }
|
495 | }
|
496 |
|
497 | else {
|
498 | _addOutput();
|
499 | }
|
500 | }
|
501 |
|
502 | if (newLineCount) {
|
503 | this.currentLine += newLineCount;
|
504 | this.source += ';__line = ' + this.currentLine + ';';
|
505 | }
|
506 | };
|
507 | };
|
508 |
|
509 |
|
510 | exports.__express = exports.renderFile;
|
511 |
|
512 |
|
513 |
|
514 | if (require.extensions) {
|
515 | require.extensions['.ejs'] = function (module, filename) {
|
516 | filename = filename || module.filename;
|
517 | var fs = require('fs')
|
518 | , options = {
|
519 | filename: filename
|
520 | , client: true
|
521 | }
|
522 | , template = fs.readFileSync(filename).toString().trim()
|
523 | , fn = compile(template, options);
|
524 | module._compile('module.exports = ' + fn.toString() + ';', filename);
|
525 | };
|
526 | }
|
527 |
|
528 |
|
529 | if (typeof window != 'undefined') {
|
530 | window.ejs = exports;
|
531 | }
|
532 |
|
533 | },{"./utils":2,"fs":3,"path":4}],2:[function(require,module,exports){
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 |
|
552 | "use strict";
|
553 |
|
554 | exports.escapeRegExpChars = (function () {
|
555 | var specials = [ '^', '$', '/', '.', '*', '+', '?', '|', '(', ')',
|
556 | '[', ']', '{', '}', '\\' ];
|
557 | var sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
|
558 | return function (string) {
|
559 | var str = string || '';
|
560 | str = String(str);
|
561 | return str.replace(sRE, '\\$1');
|
562 | };
|
563 | })();
|
564 |
|
565 | exports.escapeXML = function (markup) {
|
566 | var chars = {
|
567 | '&': '&'
|
568 | , '<': '<'
|
569 | , '>': '>'
|
570 | , '"': '"'
|
571 | , '\'': '''
|
572 | }
|
573 | , str = String(markup);
|
574 | Object.keys(chars).forEach(function (k) {
|
575 | str = str.replace(new RegExp(k, 'g'), chars[k]);
|
576 | });
|
577 | return str;
|
578 | };
|
579 |
|
580 | exports.shallowCopy = function (to, from) {
|
581 | for (var p in from) {
|
582 | to[p] = from[p];
|
583 | }
|
584 | return to;
|
585 | };
|
586 |
|
587 |
|
588 | },{}],3:[function(require,module,exports){
|
589 |
|
590 | },{}],4:[function(require,module,exports){
|
591 | (function (process){
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 | function normalizeArray(parts, allowAboveRoot) {
|
618 |
|
619 | var up = 0;
|
620 | for (var i = parts.length - 1; i >= 0; i--) {
|
621 | var last = parts[i];
|
622 | if (last === '.') {
|
623 | parts.splice(i, 1);
|
624 | } else if (last === '..') {
|
625 | parts.splice(i, 1);
|
626 | up++;
|
627 | } else if (up) {
|
628 | parts.splice(i, 1);
|
629 | up--;
|
630 | }
|
631 | }
|
632 |
|
633 |
|
634 | if (allowAboveRoot) {
|
635 | for (; up--; up) {
|
636 | parts.unshift('..');
|
637 | }
|
638 | }
|
639 |
|
640 | return parts;
|
641 | }
|
642 |
|
643 |
|
644 |
|
645 | var splitPathRe =
|
646 | /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;
|
647 | var splitPath = function(filename) {
|
648 | return splitPathRe.exec(filename).slice(1);
|
649 | };
|
650 |
|
651 |
|
652 |
|
653 | exports.resolve = function() {
|
654 | var resolvedPath = '',
|
655 | resolvedAbsolute = false;
|
656 |
|
657 | for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
658 | var path = (i >= 0) ? arguments[i] : process.cwd();
|
659 |
|
660 |
|
661 | if (typeof path !== 'string') {
|
662 | throw new TypeError('Arguments to path.resolve must be strings');
|
663 | } else if (!path) {
|
664 | continue;
|
665 | }
|
666 |
|
667 | resolvedPath = path + '/' + resolvedPath;
|
668 | resolvedAbsolute = path.charAt(0) === '/';
|
669 | }
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 | resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {
|
676 | return !!p;
|
677 | }), !resolvedAbsolute).join('/');
|
678 |
|
679 | return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
680 | };
|
681 |
|
682 |
|
683 |
|
684 | exports.normalize = function(path) {
|
685 | var isAbsolute = exports.isAbsolute(path),
|
686 | trailingSlash = substr(path, -1) === '/';
|
687 |
|
688 |
|
689 | path = normalizeArray(filter(path.split('/'), function(p) {
|
690 | return !!p;
|
691 | }), !isAbsolute).join('/');
|
692 |
|
693 | if (!path && !isAbsolute) {
|
694 | path = '.';
|
695 | }
|
696 | if (path && trailingSlash) {
|
697 | path += '/';
|
698 | }
|
699 |
|
700 | return (isAbsolute ? '/' : '') + path;
|
701 | };
|
702 |
|
703 |
|
704 | exports.isAbsolute = function(path) {
|
705 | return path.charAt(0) === '/';
|
706 | };
|
707 |
|
708 |
|
709 | exports.join = function() {
|
710 | var paths = Array.prototype.slice.call(arguments, 0);
|
711 | return exports.normalize(filter(paths, function(p, index) {
|
712 | if (typeof p !== 'string') {
|
713 | throw new TypeError('Arguments to path.join must be strings');
|
714 | }
|
715 | return p;
|
716 | }).join('/'));
|
717 | };
|
718 |
|
719 |
|
720 |
|
721 |
|
722 | exports.relative = function(from, to) {
|
723 | from = exports.resolve(from).substr(1);
|
724 | to = exports.resolve(to).substr(1);
|
725 |
|
726 | function trim(arr) {
|
727 | var start = 0;
|
728 | for (; start < arr.length; start++) {
|
729 | if (arr[start] !== '') break;
|
730 | }
|
731 |
|
732 | var end = arr.length - 1;
|
733 | for (; end >= 0; end--) {
|
734 | if (arr[end] !== '') break;
|
735 | }
|
736 |
|
737 | if (start > end) return [];
|
738 | return arr.slice(start, end - start + 1);
|
739 | }
|
740 |
|
741 | var fromParts = trim(from.split('/'));
|
742 | var toParts = trim(to.split('/'));
|
743 |
|
744 | var length = Math.min(fromParts.length, toParts.length);
|
745 | var samePartsLength = length;
|
746 | for (var i = 0; i < length; i++) {
|
747 | if (fromParts[i] !== toParts[i]) {
|
748 | samePartsLength = i;
|
749 | break;
|
750 | }
|
751 | }
|
752 |
|
753 | var outputParts = [];
|
754 | for (var i = samePartsLength; i < fromParts.length; i++) {
|
755 | outputParts.push('..');
|
756 | }
|
757 |
|
758 | outputParts = outputParts.concat(toParts.slice(samePartsLength));
|
759 |
|
760 | return outputParts.join('/');
|
761 | };
|
762 |
|
763 | exports.sep = '/';
|
764 | exports.delimiter = ':';
|
765 |
|
766 | exports.dirname = function(path) {
|
767 | var result = splitPath(path),
|
768 | root = result[0],
|
769 | dir = result[1];
|
770 |
|
771 | if (!root && !dir) {
|
772 |
|
773 | return '.';
|
774 | }
|
775 |
|
776 | if (dir) {
|
777 |
|
778 | dir = dir.substr(0, dir.length - 1);
|
779 | }
|
780 |
|
781 | return root + dir;
|
782 | };
|
783 |
|
784 |
|
785 | exports.basename = function(path, ext) {
|
786 | var f = splitPath(path)[2];
|
787 |
|
788 | if (ext && f.substr(-1 * ext.length) === ext) {
|
789 | f = f.substr(0, f.length - ext.length);
|
790 | }
|
791 | return f;
|
792 | };
|
793 |
|
794 |
|
795 | exports.extname = function(path) {
|
796 | return splitPath(path)[3];
|
797 | };
|
798 |
|
799 | function filter (xs, f) {
|
800 | if (xs.filter) return xs.filter(f);
|
801 | var res = [];
|
802 | for (var i = 0; i < xs.length; i++) {
|
803 | if (f(xs[i], i, xs)) res.push(xs[i]);
|
804 | }
|
805 | return res;
|
806 | }
|
807 |
|
808 |
|
809 | var substr = 'ab'.substr(-1) === 'b'
|
810 | ? function (str, start, len) { return str.substr(start, len) }
|
811 | : function (str, start, len) {
|
812 | if (start < 0) start = str.length + start;
|
813 | return str.substr(start, len);
|
814 | }
|
815 | ;
|
816 |
|
817 | }).call(this,require('_process'))
|
818 | },{"_process":5}],5:[function(require,module,exports){
|
819 |
|
820 |
|
821 | var process = module.exports = {};
|
822 |
|
823 | process.nextTick = (function () {
|
824 | var canSetImmediate = typeof window !== 'undefined'
|
825 | && window.setImmediate;
|
826 | var canMutationObserver = typeof window !== 'undefined'
|
827 | && window.MutationObserver;
|
828 | var canPost = typeof window !== 'undefined'
|
829 | && window.postMessage && window.addEventListener
|
830 | ;
|
831 |
|
832 | if (canSetImmediate) {
|
833 | return function (f) { return window.setImmediate(f) };
|
834 | }
|
835 |
|
836 | var queue = [];
|
837 |
|
838 | if (canMutationObserver) {
|
839 | var hiddenDiv = document.createElement("div");
|
840 | var observer = new MutationObserver(function () {
|
841 | var queueList = queue.slice();
|
842 | queue.length = 0;
|
843 | queueList.forEach(function (fn) {
|
844 | fn();
|
845 | });
|
846 | });
|
847 |
|
848 | observer.observe(hiddenDiv, { attributes: true });
|
849 |
|
850 | return function nextTick(fn) {
|
851 | if (!queue.length) {
|
852 | hiddenDiv.setAttribute('yes', 'no');
|
853 | }
|
854 | queue.push(fn);
|
855 | };
|
856 | }
|
857 |
|
858 | if (canPost) {
|
859 | window.addEventListener('message', function (ev) {
|
860 | var source = ev.source;
|
861 | if ((source === window || source === null) && ev.data === 'process-tick') {
|
862 | ev.stopPropagation();
|
863 | if (queue.length > 0) {
|
864 | var fn = queue.shift();
|
865 | fn();
|
866 | }
|
867 | }
|
868 | }, true);
|
869 |
|
870 | return function nextTick(fn) {
|
871 | queue.push(fn);
|
872 | window.postMessage('process-tick', '*');
|
873 | };
|
874 | }
|
875 |
|
876 | return function nextTick(fn) {
|
877 | setTimeout(fn, 0);
|
878 | };
|
879 | })();
|
880 |
|
881 | process.title = 'browser';
|
882 | process.browser = true;
|
883 | process.env = {};
|
884 | process.argv = [];
|
885 |
|
886 | function noop() {}
|
887 |
|
888 | process.on = noop;
|
889 | process.addListener = noop;
|
890 | process.once = noop;
|
891 | process.off = noop;
|
892 | process.removeListener = noop;
|
893 | process.removeAllListeners = noop;
|
894 | process.emit = noop;
|
895 |
|
896 | process.binding = function (name) {
|
897 | throw new Error('process.binding is not supported');
|
898 | };
|
899 |
|
900 |
|
901 | process.cwd = function () { return '/' };
|
902 | process.chdir = function (dir) {
|
903 | throw new Error('process.chdir is not supported');
|
904 | };
|
905 |
|
906 | },{}]},{},[1]);
|