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