@kosatyi/ejs 0.0.105 → 0.0.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -3,140 +3,6 @@
3
3
  var fs = require('node:fs');
4
4
  var path = require('node:path');
5
5
 
6
- function _assertClassBrand(e, t, n) {
7
- if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
8
- throw new TypeError("Private element is not present on this object");
9
- }
10
- function _assertThisInitialized(e) {
11
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
12
- return e;
13
- }
14
- function _callSuper(t, o, e) {
15
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
16
- }
17
- function _checkPrivateRedeclaration(e, t) {
18
- if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
19
- }
20
- function _classCallCheck(a, n) {
21
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
22
- }
23
- function _classPrivateFieldGet2(s, a) {
24
- return s.get(_assertClassBrand(s, a));
25
- }
26
- function _classPrivateFieldInitSpec(e, t, a) {
27
- _checkPrivateRedeclaration(e, t), t.set(e, a);
28
- }
29
- function _classPrivateFieldSet2(s, a, r) {
30
- return s.set(_assertClassBrand(s, a), r), r;
31
- }
32
- function _classPrivateMethodInitSpec(e, a) {
33
- _checkPrivateRedeclaration(e, a), a.add(e);
34
- }
35
- function _construct(t, e, r) {
36
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
37
- var o = [null];
38
- o.push.apply(o, e);
39
- var p = new (t.bind.apply(t, o))();
40
- return r && _setPrototypeOf(p, r.prototype), p;
41
- }
42
- function _defineProperties(e, r) {
43
- for (var t = 0; t < r.length; t++) {
44
- var o = r[t];
45
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
46
- }
47
- }
48
- function _createClass(e, r, t) {
49
- return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
50
- writable: !1
51
- }), e;
52
- }
53
- function _defineProperty(e, r, t) {
54
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
55
- value: t,
56
- enumerable: !0,
57
- configurable: !0,
58
- writable: !0
59
- }) : e[r] = t, e;
60
- }
61
- function _getPrototypeOf(t) {
62
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
63
- return t.__proto__ || Object.getPrototypeOf(t);
64
- }, _getPrototypeOf(t);
65
- }
66
- function _inherits(t, e) {
67
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
68
- t.prototype = Object.create(e && e.prototype, {
69
- constructor: {
70
- value: t,
71
- writable: !0,
72
- configurable: !0
73
- }
74
- }), Object.defineProperty(t, "prototype", {
75
- writable: !1
76
- }), e && _setPrototypeOf(t, e);
77
- }
78
- function _isNativeFunction(t) {
79
- try {
80
- return -1 !== Function.toString.call(t).indexOf("[native code]");
81
- } catch (n) {
82
- return "function" == typeof t;
83
- }
84
- }
85
- function _isNativeReflectConstruct() {
86
- try {
87
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
88
- } catch (t) {}
89
- return (_isNativeReflectConstruct = function () {
90
- return !!t;
91
- })();
92
- }
93
- function _possibleConstructorReturn(t, e) {
94
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
95
- if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
96
- return _assertThisInitialized(t);
97
- }
98
- function _setPrototypeOf(t, e) {
99
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
100
- return t.__proto__ = e, t;
101
- }, _setPrototypeOf(t, e);
102
- }
103
- function _toPrimitive(t, r) {
104
- if ("object" != typeof t || !t) return t;
105
- var e = t[Symbol.toPrimitive];
106
- if (void 0 !== e) {
107
- var i = e.call(t, r);
108
- if ("object" != typeof i) return i;
109
- throw new TypeError("@@toPrimitive must return a primitive value.");
110
- }
111
- return (String )(t);
112
- }
113
- function _toPropertyKey(t) {
114
- var i = _toPrimitive(t, "string");
115
- return "symbol" == typeof i ? i : i + "";
116
- }
117
- function _wrapNativeSuper(t) {
118
- var r = "function" == typeof Map ? new Map() : void 0;
119
- return _wrapNativeSuper = function (t) {
120
- if (null === t || !_isNativeFunction(t)) return t;
121
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
122
- if (void 0 !== r) {
123
- if (r.has(t)) return r.get(t);
124
- r.set(t, Wrapper);
125
- }
126
- function Wrapper() {
127
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
128
- }
129
- return Wrapper.prototype = Object.create(t.prototype, {
130
- constructor: {
131
- value: Wrapper,
132
- enumerable: !1,
133
- writable: !0,
134
- configurable: !0
135
- }
136
- }), _setPrototypeOf(Wrapper, t);
137
- }, _wrapNativeSuper(t);
138
- }
139
-
140
6
  var typeProp = function typeProp() {
141
7
  var args = [].slice.call(arguments);
142
8
  var callback = args.shift();
@@ -198,12 +64,6 @@ var safeValue = function safeValue(value, escape) {
198
64
  var check = value;
199
65
  return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
200
66
  };
201
- var instanceOf = function instanceOf(object, instance) {
202
- return Boolean(object instanceof instance);
203
- };
204
- var assertInstanceOf = function assertInstanceOf(object, instance) {
205
- if (instanceOf(object, instance) === false) throw new TypeError("".concat(object, " in not instance of ").concat(instance));
206
- };
207
67
  var getPath = function getPath(context, name, strict) {
208
68
  var data = context;
209
69
  var chunks = String(name).split('.');
@@ -224,14 +84,6 @@ var getPath = function getPath(context, name, strict) {
224
84
  }
225
85
  return [data, prop];
226
86
  };
227
- var bindContext = function bindContext(object) {
228
- var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
229
- methods.forEach(function (name) {
230
- if (name in object) {
231
- object[name] = object[name].bind(object);
232
- }
233
- });
234
- };
235
87
  var ext = function ext(path, defaults) {
236
88
  var ext = path.split('.').pop();
237
89
  if (ext !== defaults) {
@@ -351,7 +203,7 @@ defaults.token = {
351
203
  };
352
204
 
353
205
  var configSchema = function configSchema(config, options) {
354
- extend(config, {
206
+ return extend(config, {
355
207
  path: typeProp(isString, defaults.path, config.path, options.path),
356
208
  "export": typeProp(isString, defaults["export"], config["export"], options["export"]),
357
209
  resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
@@ -365,223 +217,192 @@ var configSchema = function configSchema(config, options) {
365
217
  });
366
218
  };
367
219
 
368
- var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
369
- var _enabled = /*#__PURE__*/new WeakMap();
370
- var _list = /*#__PURE__*/new WeakMap();
371
- var Cache = /*#__PURE__*/function () {
372
- function Cache(config) {
373
- _classCallCheck(this, Cache);
374
- _classPrivateFieldInitSpec(this, _enabled, true);
375
- _classPrivateFieldInitSpec(this, _list, {});
376
- this.configure(config);
377
- }
378
- return _createClass(Cache, [{
379
- key: "load",
380
- value: function load(data) {
381
- if (_classPrivateFieldGet2(_enabled, this)) {
382
- extend(_classPrivateFieldGet2(_list, this), data || {});
383
- }
384
- }
385
- }, {
386
- key: "get",
387
- value: function get(key) {
388
- if (_classPrivateFieldGet2(_enabled, this)) {
389
- return _classPrivateFieldGet2(_list, this)[key];
390
- }
391
- }
392
- }, {
393
- key: "set",
394
- value: function set(key, value) {
395
- if (_classPrivateFieldGet2(_enabled, this)) {
396
- _classPrivateFieldGet2(_list, this)[key] = value;
397
- }
398
- }
399
- }, {
400
- key: "exist",
401
- value: function exist(key) {
402
- if (_classPrivateFieldGet2(_enabled, this)) {
403
- return hasProp(_classPrivateFieldGet2(_list, this), key);
404
- }
405
- }
406
- }, {
407
- key: "clear",
408
- value: function clear() {
409
- _classPrivateFieldSet2(_list, this, {});
410
- }
411
- }, {
412
- key: "remove",
413
- value: function remove(key) {
414
- delete _classPrivateFieldGet2(_list, this)[key];
220
+ var Template = function Template(options, cache, compiler) {
221
+ var config = {
222
+ path: null,
223
+ resolver: null
224
+ };
225
+ var resolve = function resolve(path) {
226
+ return config.resolver(config.path, path);
227
+ };
228
+ var result = function result(template, content) {
229
+ cache.set(template, content);
230
+ return content;
231
+ };
232
+ var compile = function compile(content, template) {
233
+ if (isFunction(content)) {
234
+ return content;
235
+ } else {
236
+ return compiler.compile(content, template);
415
237
  }
416
- }, {
417
- key: "resolve",
418
- value: function resolve(key) {
419
- return Promise.resolve(this.get(key));
238
+ };
239
+ var get = function get(template) {
240
+ if (cache.exist(template)) {
241
+ return cache.resolve(template);
420
242
  }
421
- }, {
422
- key: "configure",
423
- value: function configure(config) {
424
- _classPrivateFieldSet2(_enabled, this, config.cache);
425
- if (isNode() === false) {
426
- this.load(global[config["export"]]);
427
- }
243
+ return resolve(template).then(function (content) {
244
+ return result(template, compile(content, template));
245
+ });
246
+ };
247
+ var configure = function configure(options) {
248
+ config.path = options.path;
249
+ if (isFunction(options.resolver)) {
250
+ config.resolver = options.resolver;
428
251
  }
429
- }]);
430
- }();
252
+ };
253
+ configure(options);
254
+ return {
255
+ get: get,
256
+ configure: configure,
257
+ compile: compile
258
+ };
259
+ };
431
260
 
432
- var _config$1 = /*#__PURE__*/new WeakMap();
433
- var _symbols = /*#__PURE__*/new WeakMap();
434
- var Compiler = /*#__PURE__*/function () {
435
- function Compiler(config) {
436
- _classCallCheck(this, Compiler);
437
- _classPrivateFieldInitSpec(this, _config$1, {});
438
- _classPrivateFieldInitSpec(this, _symbols, [{
439
- symbol: '-',
440
- format: function format(value) {
441
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
442
- }
443
- }, {
444
- symbol: '=',
445
- format: function format(value) {
446
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
447
- }
448
- }, {
449
- symbol: '#',
450
- format: function format(value) {
451
- return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
452
- }
453
- }, {
454
- symbol: '',
455
- format: function format(value) {
456
- return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
457
- }
458
- }]);
459
- this.configure(config);
261
+ var configSymbols = [{
262
+ symbol: '-',
263
+ format: function format(value) {
264
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
265
+ }
266
+ }, {
267
+ symbol: '=',
268
+ format: function format(value) {
269
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
270
+ }
271
+ }, {
272
+ symbol: '#',
273
+ format: function format(value) {
274
+ return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
460
275
  }
461
- return _createClass(Compiler, [{
462
- key: "configure",
463
- value: function configure(config) {
464
- var _this = this;
465
- _classPrivateFieldGet2(_config$1, this).withObject = config.withObject;
466
- _classPrivateFieldGet2(_config$1, this).rmWhitespace = config.rmWhitespace;
467
- _classPrivateFieldGet2(_config$1, this).token = config.token;
468
- _classPrivateFieldGet2(_config$1, this).vars = config.vars;
469
- _classPrivateFieldGet2(_config$1, this).globalHelpers = config.globalHelpers;
470
- _classPrivateFieldGet2(_config$1, this).matches = [];
471
- _classPrivateFieldGet2(_config$1, this).formats = [];
472
- _classPrivateFieldGet2(_config$1, this).slurp = {
473
- match: '[s\t\n]*',
474
- start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
475
- end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
476
- };
477
- _classPrivateFieldGet2(_symbols, this).forEach(function (item) {
478
- _classPrivateFieldGet2(_config$1, _this).matches.push(_classPrivateFieldGet2(_config$1, _this).token.start.concat(item.symbol).concat(_classPrivateFieldGet2(_config$1, _this).token.regex).concat(_classPrivateFieldGet2(_config$1, _this).token.end));
479
- _classPrivateFieldGet2(_config$1, _this).formats.push(item.format.bind(_classPrivateFieldGet2(_config$1, _this).vars));
276
+ }, {
277
+ symbol: '',
278
+ format: function format(value) {
279
+ return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
280
+ }
281
+ }];
282
+ var Compiler = function Compiler(options) {
283
+ var config = {};
284
+ var configure = function configure(options) {
285
+ config.withObject = options.withObject;
286
+ config.rmWhitespace = options.rmWhitespace;
287
+ config.token = options.token;
288
+ config.vars = options.vars;
289
+ config.globalHelpers = options.globalHelpers;
290
+ config.matches = [];
291
+ config.formats = [];
292
+ config.slurp = {
293
+ match: '[s\t\n]*',
294
+ start: [config.token.start, '_'],
295
+ end: ['_', config.token.end]
296
+ };
297
+ configSymbols.forEach(function (item) {
298
+ config.matches.push(config.token.start.concat(item.symbol).concat(config.token.regex).concat(config.token.end));
299
+ config.formats.push(item.format.bind(config.vars));
300
+ });
301
+ config.regex = new RegExp(config.matches.join('|').concat('|$'), 'g');
302
+ config.slurpStart = new RegExp([config.slurp.match, config.slurp.start.join('')].join(''), 'gm');
303
+ config.slurpEnd = new RegExp([config.slurp.end.join(''), config.slurp.match].join(''), 'gm');
304
+ };
305
+ var compile = function compile(content, path) {
306
+ var _config$vars = config.vars,
307
+ SCOPE = _config$vars.SCOPE,
308
+ SAFE = _config$vars.SAFE,
309
+ BUFFER = _config$vars.BUFFER,
310
+ COMPONENT = _config$vars.COMPONENT,
311
+ ELEMENT = _config$vars.ELEMENT;
312
+ var GLOBALS = config.globalHelpers;
313
+ if (config.rmWhitespace) {
314
+ content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
315
+ }
316
+ content = String(content).replace(config.slurpStart, config.token.start).replace(config.slurpEnd, config.token.end);
317
+ var source = "".concat(BUFFER, "('");
318
+ matchTokens(config.regex, content, function (params, index, offset) {
319
+ source += symbols(content.slice(index, offset));
320
+ params.forEach(function (value, index) {
321
+ if (value) {
322
+ source += config.formats[index](value);
323
+ }
480
324
  });
481
- _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
482
- _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
483
- _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
325
+ });
326
+ source += "');";
327
+ source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
328
+ if (config.withObject) {
329
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
330
+ }
331
+ source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
332
+ source += "\n//# sourceURL=".concat(path);
333
+ var result = null;
334
+ var params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE].concat(GLOBALS);
335
+ try {
336
+ result = Function.apply(null, params.concat(source));
337
+ result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
338
+ } catch (e) {
339
+ e.filename = path;
340
+ e.source = source;
341
+ throw e;
342
+ }
343
+ return result;
344
+ };
345
+ configure(options);
346
+ return {
347
+ configure: configure,
348
+ compile: compile
349
+ };
350
+ };
351
+
352
+ var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
353
+ var Cache = function Cache() {
354
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
355
+ var config = {};
356
+ var list = {};
357
+ var load = function load(data) {
358
+ if (config.enabled) {
359
+ extend(list, data || {});
484
360
  }
485
- }, {
486
- key: "compile",
487
- value: function compile(content, path) {
488
- var _this2 = this;
489
- var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config$1, this).vars,
490
- SCOPE = _classPrivateFieldGet2$1.SCOPE,
491
- SAFE = _classPrivateFieldGet2$1.SAFE,
492
- BUFFER = _classPrivateFieldGet2$1.BUFFER,
493
- COMPONENT = _classPrivateFieldGet2$1.COMPONENT,
494
- ELEMENT = _classPrivateFieldGet2$1.ELEMENT;
495
- var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
496
- if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
497
- content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
498
- }
499
- content = String(content).replace(_classPrivateFieldGet2(_config$1, this).slurpStart, _classPrivateFieldGet2(_config$1, this).token.start).replace(_classPrivateFieldGet2(_config$1, this).slurpEnd, _classPrivateFieldGet2(_config$1, this).token.end);
500
- var source = "".concat(BUFFER, "('");
501
- matchTokens(_classPrivateFieldGet2(_config$1, this).regex, content, function (params, index, offset) {
502
- source += symbols(content.slice(index, offset));
503
- params.forEach(function (value, index) {
504
- if (value) {
505
- source += _classPrivateFieldGet2(_config$1, _this2).formats[index](value);
506
- }
507
- });
508
- });
509
- source += "');";
510
- source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
511
- if (_classPrivateFieldGet2(_config$1, this).withObject) {
512
- source = "with(".concat(SCOPE, "){").concat(source, "}");
513
- }
514
- source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
515
- source += "\n//# sourceURL=".concat(path);
516
- var result = null;
517
- var params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE].concat(GLOBALS);
518
- try {
519
- result = Function.apply(null, params.concat(source));
520
- result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
521
- } catch (e) {
522
- e.filename = path;
523
- e.source = source;
524
- throw e;
525
- }
526
- return result;
361
+ };
362
+ var get = function get(key) {
363
+ if (config.enabled) {
364
+ return list[key];
527
365
  }
528
- }]);
529
- }();
530
-
531
- var _path = /*#__PURE__*/new WeakMap();
532
- var _cache$1 = /*#__PURE__*/new WeakMap();
533
- var _compiler$1 = /*#__PURE__*/new WeakMap();
534
- var _resolver = /*#__PURE__*/new WeakMap();
535
- var _Template_brand = /*#__PURE__*/new WeakSet();
536
- var Template = /*#__PURE__*/function () {
537
- function Template(config, cache, compiler) {
538
- _classCallCheck(this, Template);
539
- _classPrivateMethodInitSpec(this, _Template_brand);
540
- _classPrivateFieldInitSpec(this, _path, void 0);
541
- _classPrivateFieldInitSpec(this, _cache$1, void 0);
542
- _classPrivateFieldInitSpec(this, _compiler$1, void 0);
543
- _classPrivateFieldInitSpec(this, _resolver, void 0);
544
- assertInstanceOf(cache, Cache);
545
- assertInstanceOf(compiler, Compiler);
546
- _classPrivateFieldSet2(_cache$1, this, cache);
547
- _classPrivateFieldSet2(_compiler$1, this, compiler);
548
- this.configure(config);
549
- }
550
- return _createClass(Template, [{
551
- key: "configure",
552
- value: function configure(config) {
553
- _classPrivateFieldSet2(_path, this, config.path);
554
- if (isFunction(config.resolver)) {
555
- _classPrivateFieldSet2(_resolver, this, config.resolver);
556
- }
366
+ };
367
+ var set = function set(key, value) {
368
+ if (config.enabled) {
369
+ list[key] = value;
557
370
  }
558
- }, {
559
- key: "get",
560
- value: function get(template) {
561
- var _this = this;
562
- if (_classPrivateFieldGet2(_cache$1, this).exist(template)) {
563
- return _classPrivateFieldGet2(_cache$1, this).resolve(template);
564
- }
565
- return _assertClassBrand(_Template_brand, this, _resolve).call(this, template).then(function (content) {
566
- return _assertClassBrand(_Template_brand, _this, _result).call(_this, template, _assertClassBrand(_Template_brand, _this, _compile).call(_this, content, template));
567
- });
371
+ };
372
+ var exist = function exist(key) {
373
+ if (config.enabled) {
374
+ return hasProp(list, key);
568
375
  }
569
- }]);
570
- }();
571
- function _resolve(path) {
572
- return _classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path, this), path);
573
- }
574
- function _result(template, content) {
575
- _classPrivateFieldGet2(_cache$1, this).set(template, content);
576
- return content;
577
- }
578
- function _compile(content, template) {
579
- if (isFunction(content)) {
580
- return content;
581
- } else {
582
- return _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
583
- }
584
- }
376
+ };
377
+ var clear = function clear() {
378
+ Object.keys(list).forEach(remove);
379
+ };
380
+ var remove = function remove(key) {
381
+ delete list[key];
382
+ };
383
+ var resolve = function resolve(key) {
384
+ return Promise.resolve(get(key));
385
+ };
386
+ var configure = function configure() {
387
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
388
+ config.enabled = options.cache;
389
+ config["export"] = options["export"];
390
+ if (isNode() === false) {
391
+ load(global[config["export"]]);
392
+ }
393
+ };
394
+ configure(options);
395
+ return {
396
+ configure: configure,
397
+ load: load,
398
+ set: set,
399
+ get: get,
400
+ exist: exist,
401
+ clear: clear,
402
+ remove: remove,
403
+ resolve: resolve
404
+ };
405
+ };
585
406
 
586
407
  var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
587
408
  var space = ' ';
@@ -608,61 +429,50 @@ var element = function element(tag, attrs, content) {
608
429
  return result.join('');
609
430
  };
610
431
 
611
- var TemplateError = /*#__PURE__*/function (_Error) {
612
- function TemplateError(message) {
613
- var _this;
614
- _classCallCheck(this, TemplateError);
615
- _this = _callSuper(this, TemplateError);
616
- _defineProperty(_this, "code", 0);
617
- _this.message = message;
618
- return _this;
619
- }
620
- _inherits(TemplateError, _Error);
621
- return _createClass(TemplateError, [{
622
- key: "getCode",
623
- value: function getCode() {
624
- return this.code;
625
- }
626
- }, {
627
- key: "getMessage",
628
- value: function getMessage() {
629
- return this.message;
630
- }
631
- }, {
632
- key: "toString",
633
- value: function toString() {
634
- return this.getMessage();
635
- }
636
- }]);
637
- }(/*#__PURE__*/_wrapNativeSuper(Error));
638
- var TemplateNotFound = /*#__PURE__*/function (_TemplateError2) {
639
- function TemplateNotFound() {
640
- var _this2;
641
- _classCallCheck(this, TemplateNotFound);
642
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
643
- args[_key] = arguments[_key];
644
- }
645
- _this2 = _callSuper(this, TemplateNotFound, [].concat(args));
646
- _defineProperty(_this2, "code", 404);
647
- return _this2;
648
- }
649
- _inherits(TemplateNotFound, _TemplateError2);
650
- return _createClass(TemplateNotFound);
651
- }(TemplateError);
652
- var TemplateSyntaxError = /*#__PURE__*/function (_TemplateError3) {
653
- function TemplateSyntaxError() {
654
- var _this3;
655
- _classCallCheck(this, TemplateSyntaxError);
656
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
657
- args[_key2] = arguments[_key2];
658
- }
659
- _this3 = _callSuper(this, TemplateSyntaxError, [].concat(args));
660
- _defineProperty(_this3, "code", 500);
661
- return _this3;
432
+ /**
433
+ *
434
+ * @constructor
435
+ */
436
+ function TemplateError() {
437
+ TemplateError.call(this);
438
+ }
439
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
440
+ Object.assign(TemplateError.prototype, {
441
+ code: 0,
442
+ getCode: function getCode() {
443
+ return this.code;
444
+ },
445
+ getMessage: function getMessage() {
446
+ return this.message;
447
+ },
448
+ toString: function toString() {
449
+ return this.getMessage();
662
450
  }
663
- _inherits(TemplateSyntaxError, _TemplateError3);
664
- return _createClass(TemplateSyntaxError);
665
- }(TemplateError);
451
+ });
452
+
453
+ /**
454
+ *
455
+ * @constructor
456
+ */
457
+ function TemplateNotFound() {
458
+ TemplateError.call(this);
459
+ }
460
+ Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
461
+ Object.assign(TemplateNotFound.prototype, {
462
+ code: 404
463
+ });
464
+
465
+ /**
466
+ *
467
+ * @constructor
468
+ */
469
+ function TemplateSyntaxError() {
470
+ TemplateError.call(this);
471
+ }
472
+ Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
473
+ Object.assign(TemplateSyntaxError.prototype, {
474
+ code: 500
475
+ });
666
476
 
667
477
  function resolve(list) {
668
478
  return Promise.all(list || []).then(function (list) {
@@ -1014,161 +824,127 @@ var createContextScope = function createContextScope(config, methods) {
1014
824
  });
1015
825
  return ContextScope;
1016
826
  };
1017
- var _scope = /*#__PURE__*/new WeakMap();
1018
- var Context = /*#__PURE__*/function () {
1019
- function Context(config, methods) {
1020
- _classCallCheck(this, Context);
1021
- _classPrivateFieldInitSpec(this, _scope, void 0);
1022
- this.configure(config, methods);
1023
- }
1024
- return _createClass(Context, [{
1025
- key: "create",
1026
- value: function create(data) {
1027
- return new (_classPrivateFieldGet2(_scope, this))(data);
1028
- }
1029
- }, {
1030
- key: "configure",
1031
- value: function configure(config, methods) {
1032
- _classPrivateFieldSet2(_scope, this, createContextScope(config, methods));
1033
- }
1034
- }, {
1035
- key: "helpers",
1036
- value: function helpers(methods) {
1037
- extend(_classPrivateFieldGet2(_scope, this).prototype, methods || {});
1038
- }
1039
- }]);
1040
- }();
827
+ var Context = function Context(options, methods) {
828
+ var config = {
829
+ Scope: null
830
+ };
831
+ /**
832
+ * @return {ContextScope}
833
+ */
834
+ var create = function create(data) {
835
+ return new config.Scope(data);
836
+ };
837
+ var helpers = function helpers(methods) {
838
+ extend(config.Scope.prototype, methods || {});
839
+ };
840
+ var configure = function configure(options, methods) {
841
+ config.Scope = createContextScope(options, methods);
842
+ };
843
+ configure(options, methods);
844
+ return {
845
+ configure: configure,
846
+ create: create,
847
+ helpers: helpers
848
+ };
849
+ };
1041
850
 
1042
- var _config = /*#__PURE__*/new WeakMap();
1043
- var _extend = /*#__PURE__*/new WeakMap();
1044
- var _context = /*#__PURE__*/new WeakMap();
1045
- var _compiler = /*#__PURE__*/new WeakMap();
1046
- var _cache = /*#__PURE__*/new WeakMap();
1047
- var _template = /*#__PURE__*/new WeakMap();
1048
- var _EJS_brand = /*#__PURE__*/new WeakSet();
1049
- var EJS = /*#__PURE__*/function () {
1050
- function EJS(options) {
1051
- _classCallCheck(this, EJS);
1052
- _classPrivateMethodInitSpec(this, _EJS_brand);
1053
- _classPrivateFieldInitSpec(this, _config, {});
1054
- _classPrivateFieldInitSpec(this, _extend, {});
1055
- _classPrivateFieldInitSpec(this, _context, void 0);
1056
- _classPrivateFieldInitSpec(this, _compiler, void 0);
1057
- _classPrivateFieldInitSpec(this, _cache, void 0);
1058
- _classPrivateFieldInitSpec(this, _template, void 0);
1059
- configSchema(_classPrivateFieldGet2(_config, this), options || {});
1060
- _classPrivateFieldSet2(_context, this, new Context(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this)));
1061
- _classPrivateFieldSet2(_compiler, this, new Compiler(_classPrivateFieldGet2(_config, this)));
1062
- _classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
1063
- _classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
1064
- //
1065
- bindContext(this, ['configure', 'create', 'render', 'require', 'context', 'preload', 'compile', 'helpers']);
1066
- //
1067
- this.helpers({
1068
- require: this.require,
1069
- render: this.render
851
+ var _EJS$1 = function EJS() {
852
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
853
+ var config = configSchema({}, options);
854
+ var methods = {};
855
+ var context = Context(config, methods);
856
+ var compiler = Compiler(config);
857
+ var cache = Cache(config);
858
+ var template = Template(config, cache, compiler);
859
+ var configure = function configure() {
860
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
861
+ configSchema(config, options || {});
862
+ context.configure(config, methods);
863
+ compiler.configure(config);
864
+ cache.configure(config);
865
+ template.configure(config);
866
+ return config;
867
+ };
868
+ var filePath = function filePath(name) {
869
+ return ext(name, config.extension);
870
+ };
871
+ var require = function require(name) {
872
+ var scope = createContext({});
873
+ return output(filePath(name), scope).then(function () {
874
+ return scope.getMacro();
1070
875
  });
1071
- }
1072
- return _createClass(EJS, [{
1073
- key: "configure",
1074
- value: function configure(options) {
1075
- configSchema(_classPrivateFieldGet2(_config, this), options || {});
1076
- _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this));
1077
- _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
1078
- _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
1079
- _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
1080
- return _classPrivateFieldGet2(_config, this);
1081
- }
1082
- }, {
1083
- key: "filePath",
1084
- value: function filePath(name) {
1085
- return ext(name, _classPrivateFieldGet2(_config, this).extension);
1086
- }
1087
- }, {
1088
- key: "require",
1089
- value: function require(name) {
1090
- var scope = this.context({});
1091
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(function () {
1092
- return scope.getMacro();
1093
- });
1094
- }
1095
- }, {
1096
- key: "render",
1097
- value: function render(name, data) {
1098
- var scope = this.context(data);
1099
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(this.outputContent(name, scope));
1100
- }
1101
- }, {
1102
- key: "outputContent",
1103
- value: function outputContent(name, scope) {
1104
- var _this = this;
1105
- return function (content) {
1106
- if (scope.getExtend()) {
1107
- scope.setExtend(false);
1108
- return _this.renderLayout(scope.getLayout(), scope, name);
1109
- }
1110
- return content;
1111
- };
1112
- }
1113
- }, {
1114
- key: "renderLayout",
1115
- value: function renderLayout(name, data, parent) {
1116
- var scope = this.context(data);
1117
- if (parent) scope.setParentTemplate(parent);
1118
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(this.outputContent(name, scope));
1119
- }
1120
- }, {
1121
- key: "helpers",
1122
- value: function helpers(methods) {
1123
- _classPrivateFieldGet2(_context, this).helpers(extend(_classPrivateFieldGet2(_extend, this), methods));
1124
- }
1125
- }, {
1126
- key: "context",
1127
- value: function context(data) {
1128
- return _classPrivateFieldGet2(_context, this).create(data);
1129
- }
1130
- }, {
1131
- key: "compile",
1132
- value: function compile(content, path) {
1133
- return _classPrivateFieldGet2(_compiler, this).compile(content, path);
1134
- }
1135
- }, {
1136
- key: "preload",
1137
- value: function preload(list) {
1138
- return _classPrivateFieldGet2(_cache, this).load(list || {});
1139
- }
1140
- }, {
1141
- key: "create",
1142
- value: function create(options) {
1143
- return new this.constructor(options);
1144
- }
1145
- }]);
1146
- }();
1147
- function _output(path, scope) {
1148
- var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
1149
- globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
1150
- var params = [scope, scope.useComponent, scope.useElement, scope.getBuffer(), scope.useSafeValue];
1151
- var globals = globalHelpers.filter(function (name) {
1152
- return isFunction(scope[name]);
1153
- }).map(function (name) {
1154
- return scope[name].bind(scope);
1155
- });
1156
- return _classPrivateFieldGet2(_template, this).get(path).then(function (callback) {
1157
- return callback.apply(scope, params.concat(globals));
876
+ };
877
+ var render = function render(name, data) {
878
+ var scope = createContext(data);
879
+ return output(filePath(name), scope).then(outputContent(name, scope));
880
+ };
881
+ var outputContent = function outputContent(name, scope) {
882
+ return function (content) {
883
+ if (scope.getExtend()) {
884
+ scope.setExtend(false);
885
+ return renderLayout(scope.getLayout(), scope, name);
886
+ }
887
+ return content;
888
+ };
889
+ };
890
+ var renderLayout = function renderLayout(name, data, parent) {
891
+ var scope = createContext(data);
892
+ if (parent) scope.setParentTemplate(parent);
893
+ return output(filePath(name), scope).then(outputContent(name, scope));
894
+ };
895
+ var helpers = function helpers(extendMethods) {
896
+ context.helpers(extend(methods, extendMethods));
897
+ };
898
+ var createContext = function createContext(data) {
899
+ return context.create(data);
900
+ };
901
+ var compile = function compile(content, path) {
902
+ return compiler.compile(content, path);
903
+ };
904
+ var preload = function preload(list) {
905
+ return cache.load(list || {});
906
+ };
907
+ var create = function create(config) {
908
+ return _EJS$1(config);
909
+ };
910
+ var output = function output(path, scope) {
911
+ var params = [scope, scope.useComponent, scope.useElement, scope.getBuffer(), scope.useSafeValue];
912
+ var globals = config.globalHelpers.filter(function (name) {
913
+ return isFunction(scope[name]);
914
+ }).map(function (name) {
915
+ return scope[name].bind(scope);
916
+ });
917
+ return template.get(path).then(function (callback) {
918
+ return callback.apply(scope, params.concat(globals));
919
+ });
920
+ };
921
+ helpers({
922
+ render: render,
923
+ require: require
1158
924
  });
1159
- }
925
+ return {
926
+ configure: configure,
927
+ create: create,
928
+ createContext: createContext,
929
+ render: render,
930
+ require: require,
931
+ preload: preload,
932
+ compile: compile,
933
+ helpers: helpers
934
+ };
935
+ };
1160
936
 
1161
- function readFile(path, template) {
937
+ var readFile = function readFile(path, template) {
1162
938
  return new Promise(function (resolve, reject) {
1163
939
  fs.readFile(joinPath(path, template), function (error, data) {
1164
940
  if (error) {
1165
- reject(new TemplateError(error));
941
+ reject(new TemplateError());
1166
942
  } else {
1167
943
  resolve(data.toString());
1168
944
  }
1169
945
  });
1170
946
  });
1171
- }
947
+ };
1172
948
 
1173
949
  /**
1174
950
  *
@@ -1176,7 +952,7 @@ function readFile(path, template) {
1176
952
  * @param {function(name: string, data?: object):Promise<string>} render
1177
953
  * @return {function(name:any, options:any, callback: any): Promise<void>}
1178
954
  */
1179
- function expressRenderer(configure, render) {
955
+ var expressRenderer = function expressRenderer(configure, render) {
1180
956
  return function (name, options, callback) {
1181
957
  if (isFunction(options)) {
1182
958
  callback = options;
@@ -1197,13 +973,13 @@ function expressRenderer(configure, render) {
1197
973
  callback(error);
1198
974
  });
1199
975
  };
1200
- }
976
+ };
1201
977
 
1202
- var _EJS = new EJS({
978
+ var _EJS = _EJS$1({
1203
979
  resolver: readFile
1204
980
  }),
1205
981
  render = _EJS.render,
1206
- context = _EJS.context,
982
+ createContext = _EJS.createContext,
1207
983
  compile = _EJS.compile,
1208
984
  helpers = _EJS.helpers,
1209
985
  preload = _EJS.preload,
@@ -1217,8 +993,8 @@ exports.TemplateSyntaxError = TemplateSyntaxError;
1217
993
  exports.__express = __express;
1218
994
  exports.compile = compile;
1219
995
  exports.configure = configure;
1220
- exports.context = context;
1221
996
  exports.create = create;
997
+ exports.createContext = createContext;
1222
998
  exports.helpers = helpers;
1223
999
  exports.preload = preload;
1224
1000
  exports.render = render;