@kosatyi/ejs 0.0.105 → 0.0.106

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.
@@ -7,14 +7,6 @@
7
7
  function _OverloadYield(e, d) {
8
8
  this.v = e, this.k = d;
9
9
  }
10
- function _assertClassBrand(e, t, n) {
11
- if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
12
- throw new TypeError("Private element is not present on this object");
13
- }
14
- function _assertThisInitialized(e) {
15
- if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
16
- return e;
17
- }
18
10
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
19
11
  try {
20
12
  var i = n[a](c),
@@ -40,90 +32,6 @@
40
32
  });
41
33
  };
42
34
  }
43
- function _callSuper(t, o, e) {
44
- return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
45
- }
46
- function _checkPrivateRedeclaration(e, t) {
47
- if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
48
- }
49
- function _classCallCheck(a, n) {
50
- if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
51
- }
52
- function _classPrivateFieldGet2(s, a) {
53
- return s.get(_assertClassBrand(s, a));
54
- }
55
- function _classPrivateFieldInitSpec(e, t, a) {
56
- _checkPrivateRedeclaration(e, t), t.set(e, a);
57
- }
58
- function _classPrivateFieldSet2(s, a, r) {
59
- return s.set(_assertClassBrand(s, a), r), r;
60
- }
61
- function _classPrivateMethodInitSpec(e, a) {
62
- _checkPrivateRedeclaration(e, a), a.add(e);
63
- }
64
- function _construct(t, e, r) {
65
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
66
- var o = [null];
67
- o.push.apply(o, e);
68
- var p = new (t.bind.apply(t, o))();
69
- return r && _setPrototypeOf(p, r.prototype), p;
70
- }
71
- function _defineProperties(e, r) {
72
- for (var t = 0; t < r.length; t++) {
73
- var o = r[t];
74
- o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
75
- }
76
- }
77
- function _createClass(e, r, t) {
78
- return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
79
- writable: !1
80
- }), e;
81
- }
82
- function _defineProperty(e, r, t) {
83
- return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
84
- value: t,
85
- enumerable: !0,
86
- configurable: !0,
87
- writable: !0
88
- }) : e[r] = t, e;
89
- }
90
- function _getPrototypeOf(t) {
91
- return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
92
- return t.__proto__ || Object.getPrototypeOf(t);
93
- }, _getPrototypeOf(t);
94
- }
95
- function _inherits(t, e) {
96
- if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
97
- t.prototype = Object.create(e && e.prototype, {
98
- constructor: {
99
- value: t,
100
- writable: !0,
101
- configurable: !0
102
- }
103
- }), Object.defineProperty(t, "prototype", {
104
- writable: !1
105
- }), e && _setPrototypeOf(t, e);
106
- }
107
- function _isNativeFunction(t) {
108
- try {
109
- return -1 !== Function.toString.call(t).indexOf("[native code]");
110
- } catch (n) {
111
- return "function" == typeof t;
112
- }
113
- }
114
- function _isNativeReflectConstruct() {
115
- try {
116
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
117
- } catch (t) {}
118
- return (_isNativeReflectConstruct = function () {
119
- return !!t;
120
- })();
121
- }
122
- function _possibleConstructorReturn(t, e) {
123
- if (e && ("object" == typeof e || "function" == typeof e)) return e;
124
- if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
125
- return _assertThisInitialized(t);
126
- }
127
35
  function _regenerator() {
128
36
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
129
37
  var e,
@@ -297,47 +205,6 @@
297
205
  }
298
206
  throw new TypeError(typeof e + " is not iterable");
299
207
  }
300
- function _setPrototypeOf(t, e) {
301
- return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
302
- return t.__proto__ = e, t;
303
- }, _setPrototypeOf(t, e);
304
- }
305
- function _toPrimitive(t, r) {
306
- if ("object" != typeof t || !t) return t;
307
- var e = t[Symbol.toPrimitive];
308
- if (void 0 !== e) {
309
- var i = e.call(t, r);
310
- if ("object" != typeof i) return i;
311
- throw new TypeError("@@toPrimitive must return a primitive value.");
312
- }
313
- return (String )(t);
314
- }
315
- function _toPropertyKey(t) {
316
- var i = _toPrimitive(t, "string");
317
- return "symbol" == typeof i ? i : i + "";
318
- }
319
- function _wrapNativeSuper(t) {
320
- var r = "function" == typeof Map ? new Map() : void 0;
321
- return _wrapNativeSuper = function (t) {
322
- if (null === t || !_isNativeFunction(t)) return t;
323
- if ("function" != typeof t) throw new TypeError("Super expression must either be null or a function");
324
- if (void 0 !== r) {
325
- if (r.has(t)) return r.get(t);
326
- r.set(t, Wrapper);
327
- }
328
- function Wrapper() {
329
- return _construct(t, arguments, _getPrototypeOf(this).constructor);
330
- }
331
- return Wrapper.prototype = Object.create(t.prototype, {
332
- constructor: {
333
- value: Wrapper,
334
- enumerable: !1,
335
- writable: !0,
336
- configurable: !0
337
- }
338
- }), _setPrototypeOf(Wrapper, t);
339
- }, _wrapNativeSuper(t);
340
- }
341
208
  function _regeneratorRuntime() {
342
209
 
343
210
  var r = _regenerator(),
@@ -468,12 +335,6 @@
468
335
  var check = value;
469
336
  return check == null ? '' : Boolean(escape) === true ? entities(check) : check;
470
337
  };
471
- var instanceOf = function instanceOf(object, instance) {
472
- return Boolean(object instanceof instance);
473
- };
474
- var assertInstanceOf = function assertInstanceOf(object, instance) {
475
- if (instanceOf(object, instance) === false) throw new TypeError("".concat(object, " in not instance of ").concat(instance));
476
- };
477
338
  var getPath = function getPath(context, name, strict) {
478
339
  var data = context;
479
340
  var chunks = String(name).split('.');
@@ -494,14 +355,6 @@
494
355
  }
495
356
  return [data, prop];
496
357
  };
497
- var bindContext = function bindContext(object) {
498
- var methods = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
499
- methods.forEach(function (name) {
500
- if (name in object) {
501
- object[name] = object[name].bind(object);
502
- }
503
- });
504
- };
505
358
  var ext = function ext(path, defaults) {
506
359
  var ext = path.split('.').pop();
507
360
  if (ext !== defaults) {
@@ -616,7 +469,7 @@
616
469
  };
617
470
 
618
471
  var configSchema = function configSchema(config, options) {
619
- extend(config, {
472
+ return extend(config, {
620
473
  path: typeProp(isString, defaults.path, config.path, options.path),
621
474
  "export": typeProp(isString, defaults["export"], config["export"], options["export"]),
622
475
  resolver: typeProp(isFunction, defaults.resolver, config.resolver, options.resolver),
@@ -630,223 +483,192 @@
630
483
  });
631
484
  };
632
485
 
633
- var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
634
- var _enabled = /*#__PURE__*/new WeakMap();
635
- var _list = /*#__PURE__*/new WeakMap();
636
- var Cache = /*#__PURE__*/function () {
637
- function Cache(config) {
638
- _classCallCheck(this, Cache);
639
- _classPrivateFieldInitSpec(this, _enabled, true);
640
- _classPrivateFieldInitSpec(this, _list, {});
641
- this.configure(config);
642
- }
643
- return _createClass(Cache, [{
644
- key: "load",
645
- value: function load(data) {
646
- if (_classPrivateFieldGet2(_enabled, this)) {
647
- extend(_classPrivateFieldGet2(_list, this), data || {});
648
- }
649
- }
650
- }, {
651
- key: "get",
652
- value: function get(key) {
653
- if (_classPrivateFieldGet2(_enabled, this)) {
654
- return _classPrivateFieldGet2(_list, this)[key];
655
- }
656
- }
657
- }, {
658
- key: "set",
659
- value: function set(key, value) {
660
- if (_classPrivateFieldGet2(_enabled, this)) {
661
- _classPrivateFieldGet2(_list, this)[key] = value;
662
- }
663
- }
664
- }, {
665
- key: "exist",
666
- value: function exist(key) {
667
- if (_classPrivateFieldGet2(_enabled, this)) {
668
- return hasProp(_classPrivateFieldGet2(_list, this), key);
669
- }
670
- }
671
- }, {
672
- key: "clear",
673
- value: function clear() {
674
- _classPrivateFieldSet2(_list, this, {});
675
- }
676
- }, {
677
- key: "remove",
678
- value: function remove(key) {
679
- delete _classPrivateFieldGet2(_list, this)[key];
486
+ var Template = function Template(options, cache, compiler) {
487
+ var config = {
488
+ path: null,
489
+ resolver: null
490
+ };
491
+ var resolve = function resolve(path) {
492
+ return config.resolver(config.path, path);
493
+ };
494
+ var result = function result(template, content) {
495
+ cache.set(template, content);
496
+ return content;
497
+ };
498
+ var compile = function compile(content, template) {
499
+ if (isFunction(content)) {
500
+ return content;
501
+ } else {
502
+ return compiler.compile(content, template);
680
503
  }
681
- }, {
682
- key: "resolve",
683
- value: function resolve(key) {
684
- return Promise.resolve(this.get(key));
504
+ };
505
+ var get = function get(template) {
506
+ if (cache.exist(template)) {
507
+ return cache.resolve(template);
685
508
  }
686
- }, {
687
- key: "configure",
688
- value: function configure(config) {
689
- _classPrivateFieldSet2(_enabled, this, config.cache);
690
- if (isNode() === false) {
691
- this.load(global[config["export"]]);
692
- }
509
+ return resolve(template).then(function (content) {
510
+ return result(template, compile(content, template));
511
+ });
512
+ };
513
+ var configure = function configure(options) {
514
+ config.path = options.path;
515
+ if (isFunction(options.resolver)) {
516
+ config.resolver = options.resolver;
693
517
  }
694
- }]);
695
- }();
518
+ };
519
+ configure(options);
520
+ return {
521
+ get: get,
522
+ configure: configure,
523
+ compile: compile
524
+ };
525
+ };
696
526
 
697
- var _config$1 = /*#__PURE__*/new WeakMap();
698
- var _symbols = /*#__PURE__*/new WeakMap();
699
- var Compiler = /*#__PURE__*/function () {
700
- function Compiler(config) {
701
- _classCallCheck(this, Compiler);
702
- _classPrivateFieldInitSpec(this, _config$1, {});
703
- _classPrivateFieldInitSpec(this, _symbols, [{
704
- symbol: '-',
705
- format: function format(value) {
706
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
707
- }
708
- }, {
709
- symbol: '=',
710
- format: function format(value) {
711
- return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
712
- }
713
- }, {
714
- symbol: '#',
715
- format: function format(value) {
716
- return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
717
- }
718
- }, {
719
- symbol: '',
720
- format: function format(value) {
721
- return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
722
- }
723
- }]);
724
- this.configure(config);
527
+ var configSymbols = [{
528
+ symbol: '-',
529
+ format: function format(value) {
530
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, ",1))\n").concat(this.BUFFER, "('");
725
531
  }
726
- return _createClass(Compiler, [{
727
- key: "configure",
728
- value: function configure(config) {
729
- var _this = this;
730
- _classPrivateFieldGet2(_config$1, this).withObject = config.withObject;
731
- _classPrivateFieldGet2(_config$1, this).rmWhitespace = config.rmWhitespace;
732
- _classPrivateFieldGet2(_config$1, this).token = config.token;
733
- _classPrivateFieldGet2(_config$1, this).vars = config.vars;
734
- _classPrivateFieldGet2(_config$1, this).globalHelpers = config.globalHelpers;
735
- _classPrivateFieldGet2(_config$1, this).matches = [];
736
- _classPrivateFieldGet2(_config$1, this).formats = [];
737
- _classPrivateFieldGet2(_config$1, this).slurp = {
738
- match: '[s\t\n]*',
739
- start: [_classPrivateFieldGet2(_config$1, this).token.start, '_'],
740
- end: ['_', _classPrivateFieldGet2(_config$1, this).token.end]
741
- };
742
- _classPrivateFieldGet2(_symbols, this).forEach(function (item) {
743
- _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));
744
- _classPrivateFieldGet2(_config$1, _this).formats.push(item.format.bind(_classPrivateFieldGet2(_config$1, _this).vars));
745
- });
746
- _classPrivateFieldGet2(_config$1, this).regex = new RegExp(_classPrivateFieldGet2(_config$1, this).matches.join('|').concat('|$'), 'g');
747
- _classPrivateFieldGet2(_config$1, this).slurpStart = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.match, _classPrivateFieldGet2(_config$1, this).slurp.start.join('')].join(''), 'gm');
748
- _classPrivateFieldGet2(_config$1, this).slurpEnd = new RegExp([_classPrivateFieldGet2(_config$1, this).slurp.end.join(''), _classPrivateFieldGet2(_config$1, this).slurp.match].join(''), 'gm');
532
+ }, {
533
+ symbol: '=',
534
+ format: function format(value) {
535
+ return "')\n".concat(this.BUFFER, "(").concat(this.SAFE, "(").concat(value, "))\n").concat(this.BUFFER, "('");
536
+ }
537
+ }, {
538
+ symbol: '#',
539
+ format: function format(value) {
540
+ return "')\n/**".concat(value, "**/\n").concat(this.BUFFER, "('");
541
+ }
542
+ }, {
543
+ symbol: '',
544
+ format: function format(value) {
545
+ return "')\n".concat(value.trim(), "\n").concat(this.BUFFER, "('");
546
+ }
547
+ }];
548
+ var Compiler = function Compiler(options) {
549
+ var config = {};
550
+ var configure = function configure(options) {
551
+ config.withObject = options.withObject;
552
+ config.rmWhitespace = options.rmWhitespace;
553
+ config.token = options.token;
554
+ config.vars = options.vars;
555
+ config.globalHelpers = options.globalHelpers;
556
+ config.matches = [];
557
+ config.formats = [];
558
+ config.slurp = {
559
+ match: '[s\t\n]*',
560
+ start: [config.token.start, '_'],
561
+ end: ['_', config.token.end]
562
+ };
563
+ configSymbols.forEach(function (item) {
564
+ config.matches.push(config.token.start.concat(item.symbol).concat(config.token.regex).concat(config.token.end));
565
+ config.formats.push(item.format.bind(config.vars));
566
+ });
567
+ config.regex = new RegExp(config.matches.join('|').concat('|$'), 'g');
568
+ config.slurpStart = new RegExp([config.slurp.match, config.slurp.start.join('')].join(''), 'gm');
569
+ config.slurpEnd = new RegExp([config.slurp.end.join(''), config.slurp.match].join(''), 'gm');
570
+ };
571
+ var compile = function compile(content, path) {
572
+ var _config$vars = config.vars,
573
+ SCOPE = _config$vars.SCOPE,
574
+ SAFE = _config$vars.SAFE,
575
+ BUFFER = _config$vars.BUFFER,
576
+ COMPONENT = _config$vars.COMPONENT,
577
+ ELEMENT = _config$vars.ELEMENT;
578
+ var GLOBALS = config.globalHelpers;
579
+ if (config.rmWhitespace) {
580
+ content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
749
581
  }
750
- }, {
751
- key: "compile",
752
- value: function compile(content, path) {
753
- var _this2 = this;
754
- var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config$1, this).vars,
755
- SCOPE = _classPrivateFieldGet2$1.SCOPE,
756
- SAFE = _classPrivateFieldGet2$1.SAFE,
757
- BUFFER = _classPrivateFieldGet2$1.BUFFER,
758
- COMPONENT = _classPrivateFieldGet2$1.COMPONENT,
759
- ELEMENT = _classPrivateFieldGet2$1.ELEMENT;
760
- var GLOBALS = _classPrivateFieldGet2(_config$1, this).globalHelpers;
761
- if (_classPrivateFieldGet2(_config$1, this).rmWhitespace) {
762
- content = String(content).replace(/[\r\n]+/g, '\n').replace(/^\s+|\s+$/gm, '');
763
- }
764
- 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);
765
- var source = "".concat(BUFFER, "('");
766
- matchTokens(_classPrivateFieldGet2(_config$1, this).regex, content, function (params, index, offset) {
767
- source += symbols(content.slice(index, offset));
768
- params.forEach(function (value, index) {
769
- if (value) {
770
- source += _classPrivateFieldGet2(_config$1, _this2).formats[index](value);
771
- }
772
- });
582
+ content = String(content).replace(config.slurpStart, config.token.start).replace(config.slurpEnd, config.token.end);
583
+ var source = "".concat(BUFFER, "('");
584
+ matchTokens(config.regex, content, function (params, index, offset) {
585
+ source += symbols(content.slice(index, offset));
586
+ params.forEach(function (value, index) {
587
+ if (value) {
588
+ source += config.formats[index](value);
589
+ }
773
590
  });
774
- source += "');";
775
- source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
776
- if (_classPrivateFieldGet2(_config$1, this).withObject) {
777
- source = "with(".concat(SCOPE, "){").concat(source, "}");
778
- }
779
- source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
780
- source += "\n//# sourceURL=".concat(path);
781
- var result = null;
782
- var params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE].concat(GLOBALS);
783
- try {
784
- result = Function.apply(null, params.concat(source));
785
- result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
786
- } catch (e) {
787
- e.filename = path;
788
- e.source = source;
789
- throw e;
790
- }
791
- return result;
591
+ });
592
+ source += "');";
593
+ source = "try{".concat(source, "}catch(e){return ").concat(BUFFER, ".error(e)}");
594
+ if (config.withObject) {
595
+ source = "with(".concat(SCOPE, "){").concat(source, "}");
596
+ }
597
+ source = "".concat(BUFFER, ".start();").concat(source, "return ").concat(BUFFER, ".end();");
598
+ source += "\n//# sourceURL=".concat(path);
599
+ var result = null;
600
+ var params = [SCOPE, COMPONENT, ELEMENT, BUFFER, SAFE].concat(GLOBALS);
601
+ try {
602
+ result = Function.apply(null, params.concat(source));
603
+ result.source = "(function(".concat(params.join(','), "){\n").concat(source, "\n});");
604
+ } catch (e) {
605
+ e.filename = path;
606
+ e.source = source;
607
+ throw e;
792
608
  }
793
- }]);
794
- }();
609
+ return result;
610
+ };
611
+ configure(options);
612
+ return {
613
+ configure: configure,
614
+ compile: compile
615
+ };
616
+ };
795
617
 
796
- var _path = /*#__PURE__*/new WeakMap();
797
- var _cache$1 = /*#__PURE__*/new WeakMap();
798
- var _compiler$1 = /*#__PURE__*/new WeakMap();
799
- var _resolver = /*#__PURE__*/new WeakMap();
800
- var _Template_brand = /*#__PURE__*/new WeakSet();
801
- var Template = /*#__PURE__*/function () {
802
- function Template(config, cache, compiler) {
803
- _classCallCheck(this, Template);
804
- _classPrivateMethodInitSpec(this, _Template_brand);
805
- _classPrivateFieldInitSpec(this, _path, void 0);
806
- _classPrivateFieldInitSpec(this, _cache$1, void 0);
807
- _classPrivateFieldInitSpec(this, _compiler$1, void 0);
808
- _classPrivateFieldInitSpec(this, _resolver, void 0);
809
- assertInstanceOf(cache, Cache);
810
- assertInstanceOf(compiler, Compiler);
811
- _classPrivateFieldSet2(_cache$1, this, cache);
812
- _classPrivateFieldSet2(_compiler$1, this, compiler);
813
- this.configure(config);
814
- }
815
- return _createClass(Template, [{
816
- key: "configure",
817
- value: function configure(config) {
818
- _classPrivateFieldSet2(_path, this, config.path);
819
- if (isFunction(config.resolver)) {
820
- _classPrivateFieldSet2(_resolver, this, config.resolver);
821
- }
618
+ var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
619
+ var Cache = function Cache() {
620
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
621
+ var config = {};
622
+ var list = {};
623
+ var load = function load(data) {
624
+ if (config.enabled) {
625
+ extend(list, data || {});
822
626
  }
823
- }, {
824
- key: "get",
825
- value: function get(template) {
826
- var _this = this;
827
- if (_classPrivateFieldGet2(_cache$1, this).exist(template)) {
828
- return _classPrivateFieldGet2(_cache$1, this).resolve(template);
829
- }
830
- return _assertClassBrand(_Template_brand, this, _resolve).call(this, template).then(function (content) {
831
- return _assertClassBrand(_Template_brand, _this, _result).call(_this, template, _assertClassBrand(_Template_brand, _this, _compile).call(_this, content, template));
832
- });
627
+ };
628
+ var get = function get(key) {
629
+ if (config.enabled) {
630
+ return list[key];
833
631
  }
834
- }]);
835
- }();
836
- function _resolve(path) {
837
- return _classPrivateFieldGet2(_resolver, this).call(this, _classPrivateFieldGet2(_path, this), path);
838
- }
839
- function _result(template, content) {
840
- _classPrivateFieldGet2(_cache$1, this).set(template, content);
841
- return content;
842
- }
843
- function _compile(content, template) {
844
- if (isFunction(content)) {
845
- return content;
846
- } else {
847
- return _classPrivateFieldGet2(_compiler$1, this).compile(content, template);
848
- }
849
- }
632
+ };
633
+ var set = function set(key, value) {
634
+ if (config.enabled) {
635
+ list[key] = value;
636
+ }
637
+ };
638
+ var exist = function exist(key) {
639
+ if (config.enabled) {
640
+ return hasProp(list, key);
641
+ }
642
+ };
643
+ var clear = function clear() {
644
+ Object.keys(list).forEach(remove);
645
+ };
646
+ var remove = function remove(key) {
647
+ delete list[key];
648
+ };
649
+ var resolve = function resolve(key) {
650
+ return Promise.resolve(get(key));
651
+ };
652
+ var configure = function configure() {
653
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
654
+ config.enabled = options.cache;
655
+ config["export"] = options["export"];
656
+ if (isNode() === false) {
657
+ load(global[config["export"]]);
658
+ }
659
+ };
660
+ configure(options);
661
+ return {
662
+ configure: configure,
663
+ load: load,
664
+ set: set,
665
+ get: get,
666
+ exist: exist,
667
+ clear: clear,
668
+ remove: remove,
669
+ resolve: resolve
670
+ };
671
+ };
850
672
 
851
673
  var selfClosed = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
852
674
  var space = ' ';
@@ -873,61 +695,50 @@
873
695
  return result.join('');
874
696
  };
875
697
 
876
- var TemplateError = /*#__PURE__*/function (_Error) {
877
- function TemplateError(message) {
878
- var _this;
879
- _classCallCheck(this, TemplateError);
880
- _this = _callSuper(this, TemplateError);
881
- _defineProperty(_this, "code", 0);
882
- _this.message = message;
883
- return _this;
884
- }
885
- _inherits(TemplateError, _Error);
886
- return _createClass(TemplateError, [{
887
- key: "getCode",
888
- value: function getCode() {
889
- return this.code;
890
- }
891
- }, {
892
- key: "getMessage",
893
- value: function getMessage() {
894
- return this.message;
895
- }
896
- }, {
897
- key: "toString",
898
- value: function toString() {
899
- return this.getMessage();
900
- }
901
- }]);
902
- }(/*#__PURE__*/_wrapNativeSuper(Error));
903
- var TemplateNotFound = /*#__PURE__*/function (_TemplateError2) {
904
- function TemplateNotFound() {
905
- var _this2;
906
- _classCallCheck(this, TemplateNotFound);
907
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
908
- args[_key] = arguments[_key];
909
- }
910
- _this2 = _callSuper(this, TemplateNotFound, [].concat(args));
911
- _defineProperty(_this2, "code", 404);
912
- return _this2;
913
- }
914
- _inherits(TemplateNotFound, _TemplateError2);
915
- return _createClass(TemplateNotFound);
916
- }(TemplateError);
917
- var TemplateSyntaxError = /*#__PURE__*/function (_TemplateError3) {
918
- function TemplateSyntaxError() {
919
- var _this3;
920
- _classCallCheck(this, TemplateSyntaxError);
921
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
922
- args[_key2] = arguments[_key2];
923
- }
924
- _this3 = _callSuper(this, TemplateSyntaxError, [].concat(args));
925
- _defineProperty(_this3, "code", 500);
926
- return _this3;
698
+ /**
699
+ *
700
+ * @constructor
701
+ */
702
+ function TemplateError() {
703
+ TemplateError.call(this);
704
+ }
705
+ Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
706
+ Object.assign(TemplateError.prototype, {
707
+ code: 0,
708
+ getCode: function getCode() {
709
+ return this.code;
710
+ },
711
+ getMessage: function getMessage() {
712
+ return this.message;
713
+ },
714
+ toString: function toString() {
715
+ return this.getMessage();
927
716
  }
928
- _inherits(TemplateSyntaxError, _TemplateError3);
929
- return _createClass(TemplateSyntaxError);
930
- }(TemplateError);
717
+ });
718
+
719
+ /**
720
+ *
721
+ * @constructor
722
+ */
723
+ function TemplateNotFound() {
724
+ TemplateError.call(this);
725
+ }
726
+ Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
727
+ Object.assign(TemplateNotFound.prototype, {
728
+ code: 404
729
+ });
730
+
731
+ /**
732
+ *
733
+ * @constructor
734
+ */
735
+ function TemplateSyntaxError() {
736
+ TemplateError.call(this);
737
+ }
738
+ Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
739
+ Object.assign(TemplateSyntaxError.prototype, {
740
+ code: 500
741
+ });
931
742
 
932
743
  function resolve(list) {
933
744
  return Promise.all(list || []).then(function (list) {
@@ -983,6 +794,7 @@
983
794
  SCOPE = _config$vars.SCOPE,
984
795
  COMPONENT = _config$vars.COMPONENT,
985
796
  ELEMENT = _config$vars.ELEMENT;
797
+
986
798
  /**
987
799
  *
988
800
  * @type {symbol}
@@ -1279,149 +1091,113 @@
1279
1091
  });
1280
1092
  return ContextScope;
1281
1093
  };
1282
- var _scope = /*#__PURE__*/new WeakMap();
1283
- var Context = /*#__PURE__*/function () {
1284
- function Context(config, methods) {
1285
- _classCallCheck(this, Context);
1286
- _classPrivateFieldInitSpec(this, _scope, void 0);
1287
- this.configure(config, methods);
1288
- }
1289
- return _createClass(Context, [{
1290
- key: "create",
1291
- value: function create(data) {
1292
- return new (_classPrivateFieldGet2(_scope, this))(data);
1293
- }
1294
- }, {
1295
- key: "configure",
1296
- value: function configure(config, methods) {
1297
- _classPrivateFieldSet2(_scope, this, createContextScope(config, methods));
1298
- }
1299
- }, {
1300
- key: "helpers",
1301
- value: function helpers(methods) {
1302
- extend(_classPrivateFieldGet2(_scope, this).prototype, methods || {});
1303
- }
1304
- }]);
1305
- }();
1094
+ var Context = function Context(options, methods) {
1095
+ /**
1096
+ * @type {InstanceType<ContextScope>}
1097
+ */
1098
+ var Scope;
1099
+ var create = function create(data) {
1100
+ return new Scope(data);
1101
+ };
1102
+ var helpers = function helpers(methods) {
1103
+ extend(Scope.prototype, methods || {});
1104
+ };
1105
+ var configure = function configure(options, methods) {
1106
+ Scope = createContextScope(options, methods);
1107
+ };
1108
+ configure(options, methods);
1109
+ return {
1110
+ configure: configure,
1111
+ create: create,
1112
+ helpers: helpers
1113
+ };
1114
+ };
1306
1115
 
1307
- var _config = /*#__PURE__*/new WeakMap();
1308
- var _extend = /*#__PURE__*/new WeakMap();
1309
- var _context = /*#__PURE__*/new WeakMap();
1310
- var _compiler = /*#__PURE__*/new WeakMap();
1311
- var _cache = /*#__PURE__*/new WeakMap();
1312
- var _template = /*#__PURE__*/new WeakMap();
1313
- var _EJS_brand = /*#__PURE__*/new WeakSet();
1314
- var EJS = /*#__PURE__*/function () {
1315
- function EJS(options) {
1316
- _classCallCheck(this, EJS);
1317
- _classPrivateMethodInitSpec(this, _EJS_brand);
1318
- _classPrivateFieldInitSpec(this, _config, {});
1319
- _classPrivateFieldInitSpec(this, _extend, {});
1320
- _classPrivateFieldInitSpec(this, _context, void 0);
1321
- _classPrivateFieldInitSpec(this, _compiler, void 0);
1322
- _classPrivateFieldInitSpec(this, _cache, void 0);
1323
- _classPrivateFieldInitSpec(this, _template, void 0);
1324
- configSchema(_classPrivateFieldGet2(_config, this), options || {});
1325
- _classPrivateFieldSet2(_context, this, new Context(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this)));
1326
- _classPrivateFieldSet2(_compiler, this, new Compiler(_classPrivateFieldGet2(_config, this)));
1327
- _classPrivateFieldSet2(_cache, this, new Cache(_classPrivateFieldGet2(_config, this)));
1328
- _classPrivateFieldSet2(_template, this, new Template(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_cache, this), _classPrivateFieldGet2(_compiler, this)));
1329
- //
1330
- bindContext(this, ['configure', 'create', 'render', 'require', 'context', 'preload', 'compile', 'helpers']);
1331
- //
1332
- this.helpers({
1333
- require: this.require,
1334
- render: this.render
1116
+ var _EJS$1 = function EJS() {
1117
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1118
+ var config = configSchema({}, options);
1119
+ var methods = {};
1120
+ var context = Context(config, methods);
1121
+ var compiler = Compiler(config);
1122
+ var cache = Cache(config);
1123
+ var template = Template(config, cache, compiler);
1124
+ var configure = function configure() {
1125
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1126
+ configSchema(config, options || {});
1127
+ context.configure(config, methods);
1128
+ compiler.configure(config);
1129
+ cache.configure(config);
1130
+ template.configure(config);
1131
+ return config;
1132
+ };
1133
+ var filePath = function filePath(name) {
1134
+ return ext(name, config.extension);
1135
+ };
1136
+ var require = function require(name) {
1137
+ var scope = createContext({});
1138
+ return output(filePath(name), scope).then(function () {
1139
+ return scope.getMacro();
1335
1140
  });
1336
- }
1337
- return _createClass(EJS, [{
1338
- key: "configure",
1339
- value: function configure(options) {
1340
- configSchema(_classPrivateFieldGet2(_config, this), options || {});
1341
- _classPrivateFieldGet2(_context, this).configure(_classPrivateFieldGet2(_config, this), _classPrivateFieldGet2(_extend, this));
1342
- _classPrivateFieldGet2(_compiler, this).configure(_classPrivateFieldGet2(_config, this));
1343
- _classPrivateFieldGet2(_cache, this).configure(_classPrivateFieldGet2(_config, this));
1344
- _classPrivateFieldGet2(_template, this).configure(_classPrivateFieldGet2(_config, this));
1345
- return _classPrivateFieldGet2(_config, this);
1346
- }
1347
- }, {
1348
- key: "filePath",
1349
- value: function filePath(name) {
1350
- return ext(name, _classPrivateFieldGet2(_config, this).extension);
1351
- }
1352
- }, {
1353
- key: "require",
1354
- value: function require(name) {
1355
- var scope = this.context({});
1356
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(function () {
1357
- return scope.getMacro();
1358
- });
1359
- }
1360
- }, {
1361
- key: "render",
1362
- value: function render(name, data) {
1363
- var scope = this.context(data);
1364
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(this.outputContent(name, scope));
1365
- }
1366
- }, {
1367
- key: "outputContent",
1368
- value: function outputContent(name, scope) {
1369
- var _this = this;
1370
- return function (content) {
1371
- if (scope.getExtend()) {
1372
- scope.setExtend(false);
1373
- return _this.renderLayout(scope.getLayout(), scope, name);
1374
- }
1375
- return content;
1376
- };
1377
- }
1378
- }, {
1379
- key: "renderLayout",
1380
- value: function renderLayout(name, data, parent) {
1381
- var scope = this.context(data);
1382
- if (parent) scope.setParentTemplate(parent);
1383
- return _assertClassBrand(_EJS_brand, this, _output).call(this, this.filePath(name), scope).then(this.outputContent(name, scope));
1384
- }
1385
- }, {
1386
- key: "helpers",
1387
- value: function helpers(methods) {
1388
- _classPrivateFieldGet2(_context, this).helpers(extend(_classPrivateFieldGet2(_extend, this), methods));
1389
- }
1390
- }, {
1391
- key: "context",
1392
- value: function context(data) {
1393
- return _classPrivateFieldGet2(_context, this).create(data);
1394
- }
1395
- }, {
1396
- key: "compile",
1397
- value: function compile(content, path) {
1398
- return _classPrivateFieldGet2(_compiler, this).compile(content, path);
1399
- }
1400
- }, {
1401
- key: "preload",
1402
- value: function preload(list) {
1403
- return _classPrivateFieldGet2(_cache, this).load(list || {});
1404
- }
1405
- }, {
1406
- key: "create",
1407
- value: function create(options) {
1408
- return new this.constructor(options);
1409
- }
1410
- }]);
1411
- }();
1412
- function _output(path, scope) {
1413
- var _classPrivateFieldGet2$1 = _classPrivateFieldGet2(_config, this),
1414
- globalHelpers = _classPrivateFieldGet2$1.globalHelpers;
1415
- var params = [scope, scope.useComponent, scope.useElement, scope.getBuffer(), scope.useSafeValue];
1416
- var globals = globalHelpers.filter(function (name) {
1417
- return isFunction(scope[name]);
1418
- }).map(function (name) {
1419
- return scope[name].bind(scope);
1420
- });
1421
- return _classPrivateFieldGet2(_template, this).get(path).then(function (callback) {
1422
- return callback.apply(scope, params.concat(globals));
1141
+ };
1142
+ var render = function render(name, data) {
1143
+ var scope = createContext(data);
1144
+ return output(filePath(name), scope).then(outputContent(name, scope));
1145
+ };
1146
+ var outputContent = function outputContent(name, scope) {
1147
+ return function (content) {
1148
+ if (scope.getExtend()) {
1149
+ scope.setExtend(false);
1150
+ return renderLayout(scope.getLayout(), scope, name);
1151
+ }
1152
+ return content;
1153
+ };
1154
+ };
1155
+ var renderLayout = function renderLayout(name, data, parent) {
1156
+ var scope = createContext(data);
1157
+ if (parent) scope.setParentTemplate(parent);
1158
+ return output(filePath(name), scope).then(outputContent(name, scope));
1159
+ };
1160
+ var helpers = function helpers(extendMethods) {
1161
+ context.helpers(extend(methods, extendMethods));
1162
+ };
1163
+ var createContext = function createContext(data) {
1164
+ return context.create(data);
1165
+ };
1166
+ var compile = function compile(content, path) {
1167
+ return compiler.compile(content, path);
1168
+ };
1169
+ var preload = function preload(list) {
1170
+ return cache.load(list || {});
1171
+ };
1172
+ var create = function create(config) {
1173
+ return _EJS$1(config);
1174
+ };
1175
+ var output = function output(path, scope) {
1176
+ var params = [scope, scope.useComponent, scope.useElement, scope.getBuffer(), scope.useSafeValue];
1177
+ var globals = config.globalHelpers.filter(function (name) {
1178
+ return isFunction(scope[name]);
1179
+ }).map(function (name) {
1180
+ return scope[name].bind(scope);
1181
+ });
1182
+ return template.get(path).then(function (callback) {
1183
+ return callback.apply(scope, params.concat(globals));
1184
+ });
1185
+ };
1186
+ helpers({
1187
+ render: render,
1188
+ require: require
1423
1189
  });
1424
- }
1190
+ return {
1191
+ configure: configure,
1192
+ create: create,
1193
+ createContext: createContext,
1194
+ render: render,
1195
+ require: require,
1196
+ preload: preload,
1197
+ compile: compile,
1198
+ helpers: helpers
1199
+ };
1200
+ };
1425
1201
 
1426
1202
  var templateCache = {};
1427
1203
  var getOrigin = function getOrigin(url, secure) {
@@ -1429,7 +1205,7 @@
1429
1205
  url.protocol = secure ? 'https:' : 'http:';
1430
1206
  return url.origin;
1431
1207
  };
1432
- var _EJS = new EJS({
1208
+ var _EJS = _EJS$1({
1433
1209
  cache: false,
1434
1210
  withObject: false,
1435
1211
  resolver: function resolver(path, name) {
@@ -1437,13 +1213,13 @@
1437
1213
  if (isFunction(templateCache[name])) {
1438
1214
  resolve(templateCache[name]);
1439
1215
  } else {
1440
- reject(new TemplateNotFound("template ".concat(name, " not found")));
1216
+ reject(new TemplateNotFound());
1441
1217
  }
1442
1218
  });
1443
1219
  }
1444
1220
  }),
1445
1221
  render = _EJS.render,
1446
- context = _EJS.context,
1222
+ createContext = _EJS.createContext,
1447
1223
  helpers = _EJS.helpers,
1448
1224
  configure = _EJS.configure;
1449
1225
  function useTemplates() {
@@ -1484,7 +1260,7 @@
1484
1260
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1485
1261
  while (1) switch (_context.prev = _context.next) {
1486
1262
  case 0:
1487
- c.data = context({});
1263
+ c.data = createContext({});
1488
1264
  c.data.set('version', version);
1489
1265
  c.data.set('origin', getOrigin(c.req.url, secure));
1490
1266
  c.data.set('path', c.req.path);
@@ -1523,7 +1299,7 @@
1523
1299
  exports.TemplateNotFound = TemplateNotFound;
1524
1300
  exports.TemplateSyntaxError = TemplateSyntaxError;
1525
1301
  exports.configure = configure;
1526
- exports.context = context;
1302
+ exports.createContext = createContext;
1527
1303
  exports.helpers = helpers;
1528
1304
  exports.render = render;
1529
1305
  exports.setRenderer = setRenderer;