@kosatyi/ejs 0.0.106 → 0.0.107

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  const isUndefined = (v) => typeof v === 'undefined';
2
2
 
3
3
  Object.prototype.toString.call(
4
- typeof process !== 'undefined' ? process : 0
4
+ typeof process !== 'undefined' ? process : 0,
5
5
  ) === '[object process]';
6
6
 
7
7
  const symbolEntities = {
@@ -32,7 +32,7 @@ regexKeys(symbolEntities);
32
32
  const entities = (string = '') => {
33
33
  return ('' + string).replace(
34
34
  htmlEntitiesMatch,
35
- (match) => htmlEntities[match]
35
+ (match) => htmlEntities[match],
36
36
  )
37
37
  };
38
38
 
@@ -41,8 +41,8 @@ const safeValue = (value, escape) => {
41
41
  return check == null
42
42
  ? ''
43
43
  : Boolean(escape) === true
44
- ? entities(check)
45
- : check
44
+ ? entities(check)
45
+ : check
46
46
  };
47
47
 
48
48
  const each = (object, callback) => {
package/dist/esm/index.js CHANGED
@@ -14,7 +14,7 @@ const isUndefined = (v) => typeof v === 'undefined';
14
14
 
15
15
  const isNodeEnv =
16
16
  Object.prototype.toString.call(
17
- typeof process !== 'undefined' ? process : 0
17
+ typeof process !== 'undefined' ? process : 0,
18
18
  ) === '[object process]';
19
19
 
20
20
  const isNode = () => isNodeEnv;
@@ -47,14 +47,14 @@ const symbolEntitiesMatch = regexKeys(symbolEntities);
47
47
  const entities = (string = '') => {
48
48
  return ('' + string).replace(
49
49
  htmlEntitiesMatch,
50
- (match) => htmlEntities[match]
50
+ (match) => htmlEntities[match],
51
51
  )
52
52
  };
53
53
 
54
54
  const symbols = (string) => {
55
55
  return ('' + string).replace(
56
56
  symbolEntitiesMatch,
57
- (match) => '\\' + symbolEntities[match]
57
+ (match) => '\\' + symbolEntities[match],
58
58
  )
59
59
  };
60
60
 
@@ -63,8 +63,8 @@ const safeValue = (value, escape) => {
63
63
  return check == null
64
64
  ? ''
65
65
  : Boolean(escape) === true
66
- ? entities(check)
67
- : check
66
+ ? entities(check)
67
+ : check
68
68
  };
69
69
 
70
70
  const getPath = (context, name, strict) => {
@@ -189,9 +189,9 @@ defaults.export = 'ejsPrecompiled';
189
189
  defaults.cache = true;
190
190
  defaults.chokidar = null;
191
191
  defaults.path = 'views';
192
- defaults.resolver = function(path, template) {
192
+ defaults.resolver = function (path, template) {
193
193
  return Promise.resolve(
194
- ['resolver is not defined', path, template].join(' ')
194
+ ['resolver is not defined', path, template].join(' '),
195
195
  )
196
196
  };
197
197
  defaults.extension = 'ejs';
@@ -207,12 +207,12 @@ defaults.vars = {
207
207
  LAYOUT: '$$l',
208
208
  BLOCKS: '$$b',
209
209
  MACRO: '$$m',
210
- SAFE: '$$v'
210
+ SAFE: '$$v',
211
211
  };
212
212
  defaults.token = {
213
213
  start: '<%',
214
214
  end: '%>',
215
- regex: '([\\s\\S]+?)'
215
+ regex: '([\\s\\S]+?)',
216
216
  };
217
217
 
218
218
  const configSchema = (config, options) => {
@@ -222,31 +222,31 @@ const configSchema = (config, options) => {
222
222
  isString,
223
223
  defaults.export,
224
224
  config.export,
225
- options.export
225
+ options.export,
226
226
  ),
227
227
  resolver: typeProp(
228
228
  isFunction,
229
229
  defaults.resolver,
230
230
  config.resolver,
231
- options.resolver
231
+ options.resolver,
232
232
  ),
233
233
  extension: typeProp(
234
234
  isString,
235
235
  defaults.extension,
236
236
  config.extension,
237
- options.extension
237
+ options.extension,
238
238
  ),
239
239
  withObject: typeProp(
240
240
  isBoolean,
241
241
  defaults.withObject,
242
242
  config.withObject,
243
- options.withObject
243
+ options.withObject,
244
244
  ),
245
245
  rmWhitespace: typeProp(
246
246
  isBoolean,
247
247
  defaults.rmWhitespace,
248
248
  config.rmWhitespace,
249
- options.rmWhitespace
249
+ options.rmWhitespace,
250
250
  ),
251
251
  cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
252
252
  token: extend({}, defaults.token, config.token, options.token),
@@ -255,7 +255,7 @@ const configSchema = (config, options) => {
255
255
  isArray,
256
256
  defaults.globalHelpers,
257
257
  config.globalHelpers,
258
- options.globalHelpers
258
+ options.globalHelpers,
259
259
  ),
260
260
  })
261
261
  };
@@ -263,7 +263,7 @@ const configSchema = (config, options) => {
263
263
  const Template = (options, cache, compiler) => {
264
264
  const config = {
265
265
  path: null,
266
- resolver: null
266
+ resolver: null,
267
267
  };
268
268
  const resolve = (path) => {
269
269
  return config.resolver(config.path, path)
@@ -284,7 +284,7 @@ const Template = (options, cache, compiler) => {
284
284
  return cache.resolve(template)
285
285
  }
286
286
  return resolve(template).then((content) =>
287
- result(template, compile(content, template))
287
+ result(template, compile(content, template)),
288
288
  )
289
289
  };
290
290
  const configure = (options) => {
@@ -297,7 +297,7 @@ const Template = (options, cache, compiler) => {
297
297
  return {
298
298
  get,
299
299
  configure,
300
- compile
300
+ compile,
301
301
  }
302
302
  };
303
303
 
@@ -348,25 +348,18 @@ const Compiler = (options) => {
348
348
  config.token.start
349
349
  .concat(item.symbol)
350
350
  .concat(config.token.regex)
351
- .concat(config.token.end)
351
+ .concat(config.token.end),
352
352
  );
353
353
  config.formats.push(item.format.bind(config.vars));
354
354
  });
355
- config.regex = new RegExp(
356
- config.matches.join('|').concat('|$'),
357
- 'g'
358
- );
355
+ config.regex = new RegExp(config.matches.join('|').concat('|$'), 'g');
359
356
  config.slurpStart = new RegExp(
360
- [config.slurp.match, config.slurp.start.join('')].join(
361
- ''
362
- ),
363
- 'gm'
357
+ [config.slurp.match, config.slurp.start.join('')].join(''),
358
+ 'gm',
364
359
  );
365
360
  config.slurpEnd = new RegExp(
366
- [config.slurp.end.join(''), config.slurp.match].join(
367
- ''
368
- ),
369
- 'gm'
361
+ [config.slurp.end.join(''), config.slurp.match].join(''),
362
+ 'gm',
370
363
  );
371
364
  };
372
365
  const compile = (content, path) => {
@@ -518,7 +511,7 @@ const element = (tag, attrs, content) => {
518
511
  *
519
512
  * @constructor
520
513
  */
521
- function TemplateError(){
514
+ function TemplateError() {
522
515
  TemplateError.call(this);
523
516
  }
524
517
  Object.setPrototypeOf(TemplateError.prototype, Error.prototype);
@@ -532,28 +525,28 @@ Object.assign(TemplateError.prototype, {
532
525
  },
533
526
  toString() {
534
527
  return this.getMessage()
535
- }
528
+ },
536
529
  });
537
530
 
538
531
  /**
539
532
  *
540
533
  * @constructor
541
534
  */
542
- function TemplateNotFound(){
535
+ function TemplateNotFound() {
543
536
  TemplateError.call(this);
544
537
  }
545
538
  Object.setPrototypeOf(TemplateNotFound.prototype, TemplateError.prototype);
546
- Object.assign(TemplateNotFound.prototype, { code: 404 });
539
+ Object.assign(TemplateNotFound.prototype, { code: 404 });
547
540
 
548
541
  /**
549
542
  *
550
543
  * @constructor
551
544
  */
552
- function TemplateSyntaxError(){
545
+ function TemplateSyntaxError() {
553
546
  TemplateError.call(this);
554
547
  }
555
548
  Object.setPrototypeOf(TemplateSyntaxError.prototype, TemplateError.prototype);
556
- Object.assign(TemplateSyntaxError.prototype, { code: 500 });
549
+ Object.assign(TemplateSyntaxError.prototype, { code: 500 });
557
550
 
558
551
  function resolve(list) {
559
552
  return Promise.all(list || [])
@@ -610,9 +603,8 @@ const createContextScope = (config, methods) => {
610
603
  SAFE,
611
604
  SCOPE,
612
605
  COMPONENT,
613
- ELEMENT
606
+ ELEMENT,
614
607
  } = config.vars;
615
-
616
608
  /**
617
609
  *
618
610
  * @type {symbol}
@@ -629,33 +621,33 @@ const createContextScope = (config, methods) => {
629
621
  this[MACRO] = {};
630
622
  Object.assign(
631
623
  this,
632
- omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT])
624
+ omit(data, [SCOPE, BUFFER, SAFE, COMPONENT, ELEMENT]),
633
625
  );
634
626
  }
635
627
 
636
628
  Object.assign(ContextScope.prototype, methods);
637
629
  Object.defineProperty(ContextScope.prototype, BUFFER, {
638
- value: createBuffer()
630
+ value: createBuffer(),
639
631
  });
640
632
  Object.defineProperty(ContextScope.prototype, BLOCKS, {
641
633
  value: {},
642
- writable: true
634
+ writable: true,
643
635
  });
644
636
  Object.defineProperty(ContextScope.prototype, MACRO, {
645
637
  value: {},
646
- writable: true
638
+ writable: true,
647
639
  });
648
640
  Object.defineProperty(ContextScope.prototype, LAYOUT, {
649
641
  value: false,
650
- writable: true
642
+ writable: true,
651
643
  });
652
644
  Object.defineProperty(ContextScope.prototype, EXTEND, {
653
645
  value: false,
654
- writable: true
646
+ writable: true,
655
647
  });
656
648
  Object.defineProperty(ContextScope.prototype, PARENT, {
657
649
  value: null,
658
- writable: true
650
+ writable: true,
659
651
  });
660
652
  Object.defineProperties(ContextScope.prototype, {
661
653
  /** @type {function} */
@@ -663,17 +655,17 @@ const createContextScope = (config, methods) => {
663
655
  value(value) {
664
656
  this[PARENT] = value;
665
657
  return this
666
- }
658
+ },
667
659
  },
668
660
  /** @type {function} */
669
661
  getParentTemplate: {
670
662
  value() {
671
663
  return this[PARENT]
672
- }
664
+ },
673
665
  },
674
666
  /** @type {function} */
675
667
  useSafeValue: {
676
- get: () => safeValue
668
+ get: () => safeValue,
677
669
  },
678
670
  /** @type {function} */
679
671
  useComponent: {
@@ -685,7 +677,7 @@ const createContextScope = (config, methods) => {
685
677
  throw new Error(`${COMPONENT} must be a function`)
686
678
  }
687
679
  }
688
- }
680
+ },
689
681
  },
690
682
  /** @type {function} */
691
683
  useElement: {
@@ -697,51 +689,51 @@ const createContextScope = (config, methods) => {
697
689
  throw new Error(`${ELEMENT} must be a function`)
698
690
  }
699
691
  }
700
- }
692
+ },
701
693
  },
702
694
  /** @type {()=>this[MACRO]} */
703
695
  getMacro: {
704
696
  value() {
705
697
  return this[MACRO]
706
- }
698
+ },
707
699
  },
708
700
  /** @type {function} */
709
701
  getBuffer: {
710
702
  value() {
711
703
  return this[BUFFER]
712
- }
704
+ },
713
705
  },
714
706
  /** @type {function} */
715
707
  getBlocks: {
716
708
  value() {
717
709
  return this[BLOCKS]
718
- }
710
+ },
719
711
  },
720
712
  /** @type {function} */
721
713
  setExtend: {
722
714
  value(value) {
723
715
  this[EXTEND] = value;
724
716
  return this
725
- }
717
+ },
726
718
  },
727
719
  /** @type {function} */
728
720
  getExtend: {
729
721
  value() {
730
722
  return this[EXTEND]
731
- }
723
+ },
732
724
  },
733
725
  /** @type {function} */
734
726
  setLayout: {
735
727
  value(layout) {
736
728
  this[LAYOUT] = layout;
737
729
  return this
738
- }
730
+ },
739
731
  },
740
732
  /** @type {function} */
741
733
  getLayout: {
742
734
  value() {
743
735
  return this[LAYOUT]
744
- }
736
+ },
745
737
  },
746
738
  /** @type {function} */
747
739
  clone: {
@@ -751,14 +743,14 @@ const createContextScope = (config, methods) => {
751
743
  filter.push(BLOCKS);
752
744
  }
753
745
  return omit(this, filter)
754
- }
746
+ },
755
747
  },
756
748
  /** @type {function} */
757
749
  extend: {
758
750
  value(layout) {
759
751
  this.setExtend(true);
760
752
  this.setLayout(layout);
761
- }
753
+ },
762
754
  },
763
755
  /** @type {function} */
764
756
  echo: {
@@ -766,21 +758,21 @@ const createContextScope = (config, methods) => {
766
758
  const buffer = this.getBuffer();
767
759
  const params = [].slice.call(arguments);
768
760
  params.forEach(buffer);
769
- }
761
+ },
770
762
  },
771
763
  /** @type {function} */
772
764
  fn: {
773
765
  value(callback) {
774
766
  const buffer = this.getBuffer();
775
767
  const context = this;
776
- return function() {
768
+ return function () {
777
769
  if (isFunction(callback)) {
778
770
  buffer.backup();
779
771
  buffer(callback.apply(context, arguments));
780
772
  return buffer.restore()
781
773
  }
782
774
  }
783
- }
775
+ },
784
776
  },
785
777
  /** @type {function} */
786
778
  macro: {
@@ -788,10 +780,10 @@ const createContextScope = (config, methods) => {
788
780
  const list = this.getMacro();
789
781
  const macro = this.fn(callback);
790
782
  const context = this;
791
- list[name] = function() {
783
+ list[name] = function () {
792
784
  return context.echo(macro.apply(undefined, arguments))
793
785
  };
794
- }
786
+ },
795
787
  },
796
788
  /** @type {function} */
797
789
  call: {
@@ -802,7 +794,7 @@ const createContextScope = (config, methods) => {
802
794
  if (isFunction(macro)) {
803
795
  return macro.apply(macro, params)
804
796
  }
805
- }
797
+ },
806
798
  },
807
799
  /** @type {function} */
808
800
  block: {
@@ -826,13 +818,13 @@ const createContextScope = (config, methods) => {
826
818
  }
827
819
  };
828
820
  this.echo(current()(next()));
829
- }
821
+ },
830
822
  },
831
823
  /** @type {function} */
832
824
  hasBlock: {
833
825
  value(name) {
834
826
  return this.getBlocks().hasOwnProperty(name)
835
- }
827
+ },
836
828
  },
837
829
  /** @type {function} */
838
830
  include: {
@@ -841,7 +833,7 @@ const createContextScope = (config, methods) => {
841
833
  const params = extend(context, data || {});
842
834
  const promise = this.render(path, params);
843
835
  this.echo(promise);
844
- }
836
+ },
845
837
  },
846
838
  /** @type {function} */
847
839
  use: {
@@ -849,18 +841,18 @@ const createContextScope = (config, methods) => {
849
841
  this.echo(
850
842
  Promise.resolve(this.require(path)).then((exports) => {
851
843
  const list = this.getMacro();
852
- each(exports, function(macro, name) {
844
+ each(exports, function (macro, name) {
853
845
  list[[namespace, name].join('.')] = macro;
854
846
  });
855
- })
847
+ }),
856
848
  );
857
- }
849
+ },
858
850
  },
859
851
  /** @type {function} */
860
852
  async: {
861
853
  value(promise, callback) {
862
854
  this.echo(Promise.resolve(promise).then(callback));
863
- }
855
+ },
864
856
  },
865
857
  /** @type {function} */
866
858
  get: {
@@ -869,7 +861,7 @@ const createContextScope = (config, methods) => {
869
861
  const result = path.shift();
870
862
  const prop = path.pop();
871
863
  return hasProp(result, prop) ? result[prop] : defaults
872
- }
864
+ },
873
865
  },
874
866
  /** @type {function} */
875
867
  set: {
@@ -881,17 +873,17 @@ const createContextScope = (config, methods) => {
881
873
  return result[prop]
882
874
  }
883
875
  return (result[prop] = value)
884
- }
876
+ },
885
877
  },
886
878
  /** @type {function} */
887
879
  each: {
888
- value: function(object, callback) {
880
+ value: function (object, callback) {
889
881
  if (isString(object)) {
890
882
  object = this.get(object, []);
891
883
  }
892
884
  each(object, callback);
893
885
  },
894
- writable: true
886
+ writable: true,
895
887
  },
896
888
  /** @type {function} */
897
889
  el: {
@@ -899,41 +891,42 @@ const createContextScope = (config, methods) => {
899
891
  content = isFunction(content) ? this.fn(content)() : content;
900
892
  this.echo(
901
893
  Promise.resolve(content).then((content) =>
902
- element(tag, attr, content)
903
- )
894
+ element(tag, attr, content),
895
+ ),
904
896
  );
905
897
  },
906
- writable: true
898
+ writable: true,
907
899
  },
908
900
  /** @type {function} */
909
901
  ui: {
910
- value(layout) {
911
- },
912
- writable: true
913
- }
902
+ value(layout) {},
903
+ writable: true,
904
+ },
914
905
  });
915
906
  return ContextScope
916
907
  };
917
908
 
918
909
  const Context = (options, methods) => {
910
+ const config = {
911
+ Scope: null,
912
+ };
919
913
  /**
920
- * @type {InstanceType<ContextScope>}
914
+ * @return {ContextScope}
921
915
  */
922
- let Scope;
923
916
  const create = (data) => {
924
- return new Scope(data)
917
+ return new config.Scope(data)
925
918
  };
926
919
  const helpers = (methods) => {
927
- extend(Scope.prototype, methods || {});
920
+ extend(config.Scope.prototype, methods || {});
928
921
  };
929
922
  const configure = (options, methods) => {
930
- Scope = createContextScope(options, methods);
923
+ config.Scope = createContextScope(options, methods);
931
924
  };
932
925
  configure(options, methods);
933
926
  return {
934
927
  configure,
935
928
  create,
936
- helpers
929
+ helpers,
937
930
  }
938
931
  };
939
932
 
@@ -993,7 +986,13 @@ const EJS = (options = {}) => {
993
986
  return EJS(config)
994
987
  };
995
988
  const output = (path, scope) => {
996
- const params = [scope, scope.useComponent, scope.useElement, scope.getBuffer(), scope.useSafeValue];
989
+ const params = [
990
+ scope,
991
+ scope.useComponent,
992
+ scope.useElement,
993
+ scope.getBuffer(),
994
+ scope.useSafeValue,
995
+ ];
997
996
  const globals = config.globalHelpers
998
997
  .filter((name) => isFunction(scope[name]))
999
998
  .map((name) => scope[name].bind(scope));
@@ -1010,7 +1009,7 @@ const EJS = (options = {}) => {
1010
1009
  require,
1011
1010
  preload,
1012
1011
  compile,
1013
- helpers
1012
+ helpers,
1014
1013
  }
1015
1014
  };
1016
1015
 
@@ -1044,7 +1043,7 @@ const expressRenderer = (configure, render) => {
1044
1043
  const viewCache = typeProp(
1045
1044
  isBoolean,
1046
1045
  defaults.cache,
1047
- settings['view cache']
1046
+ settings['view cache'],
1048
1047
  );
1049
1048
  const viewOptions = extend({}, settings['view options']);
1050
1049
  const filename = path.relative(viewPath, name);
@@ -1061,10 +1060,17 @@ const expressRenderer = (configure, render) => {
1061
1060
  }
1062
1061
  };
1063
1062
 
1064
- const { render, createContext, compile, helpers, preload, configure, create } =
1065
- EJS({
1066
- resolver: readFile,
1067
- });
1063
+ const {
1064
+ render,
1065
+ createContext,
1066
+ compile,
1067
+ helpers,
1068
+ preload,
1069
+ configure,
1070
+ create,
1071
+ } = EJS({
1072
+ resolver: readFile,
1073
+ });
1068
1074
 
1069
1075
  const __express = expressRenderer(configure, render);
1070
1076