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