@kosatyi/ejs 0.0.63 → 0.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -3,16 +3,6 @@
3
3
  var path = require('path');
4
4
  var fs = require('fs');
5
5
 
6
- function _typeof(o) {
7
- "@babel/helpers - typeof";
8
-
9
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
10
- return typeof o;
11
- } : function (o) {
12
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
13
- }, _typeof(o);
14
- }
15
-
16
6
  var typeProp = function typeProp() {
17
7
  var args = [].slice.call(arguments);
18
8
  var callback = args.shift();
@@ -27,9 +17,6 @@ var isString = function isString(v) {
27
17
  var isBoolean = function isBoolean(v) {
28
18
  return typeof v === 'boolean';
29
19
  };
30
- var isObject = function isObject(v) {
31
- return _typeof(v) === 'object';
32
- };
33
20
  var isUndefined = function isUndefined(v) {
34
21
  return typeof v === 'undefined';
35
22
  };
@@ -75,7 +62,7 @@ var safeValue = function safeValue(value, escape) {
75
62
  return check == null ? '' : escape === true ? entities(check) : check;
76
63
  };
77
64
  var instanceOf = function instanceOf(object, instance) {
78
- return object instanceof instance;
65
+ return Boolean(object instanceof instance);
79
66
  };
80
67
  var getPath = function getPath(context, name, strict) {
81
68
  var data = context;
@@ -165,7 +152,7 @@ var hasProp = function hasProp(object, prop) {
165
152
 
166
153
  var defaults = {};
167
154
  defaults["export"] = 'ejsPrecompiled';
168
- defaults.watch = false;
155
+ defaults.cache = true;
169
156
  defaults.chokidar = null;
170
157
  defaults.path = 'views';
171
158
  defaults.resolver = null;
@@ -221,81 +208,54 @@ var configSchema = function configSchema(config, options) {
221
208
  extension: typeProp(isString, defaults.extension, config.extension, options.extension),
222
209
  withObject: typeProp(isBoolean, defaults.withObject, config.withObject, options.withObject),
223
210
  rmWhitespace: typeProp(isBoolean, defaults.rmWhitespace, config.rmWhitespace, options.rmWhitespace),
224
- watch: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
225
- chokidar: typeProp(isObject, defaults["export"], config["export"], options["export"]),
211
+ cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
226
212
  token: extend({}, defaults.token, config.token, options.token),
227
213
  vars: extend({}, defaults.vars, config.vars, options.vars)
228
214
  });
229
215
  };
230
216
 
231
- var resolvePath = function resolvePath(path, template) {
232
- template = [path, template].join('/');
233
- template = template.replace(/\/\//g, '/');
234
- return template;
235
- };
236
- var httpRequest = function httpRequest(path, template) {
237
- return fetch(resolvePath(path, template)).then(function (response) {
238
- return response.text();
239
- });
240
- };
241
- var fileSystem = function fileSystem(path, template) {
242
- return new Promise(function (resolve, reject) {
243
- fs.readFile(resolvePath(path, template), function (error, data) {
244
- if (error) {
245
- reject(error);
246
- } else {
247
- resolve(data.toString());
248
- }
249
- });
250
- });
251
- };
252
- var fileResolver = function fileResolver(resolver) {
253
- return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
254
- };
255
- function Template(config, cache, compiler) {
256
- if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
257
- var template = {};
258
- var result = function result(template, content) {
259
- cache.set(template, content);
260
- return content;
217
+ var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
218
+ function Cache(config) {
219
+ if (instanceOf(this, Cache) === false) return new Cache();
220
+ var cache = {
221
+ enabled: true,
222
+ list: {}
261
223
  };
262
- var resolve = function resolve(path) {
263
- return template.resolver(template.path, path);
224
+ this.configure = function (config) {
225
+ cache.enabled = config.cache;
226
+ if (isNode() === false) {
227
+ this.load(global[config["export"]]);
228
+ }
264
229
  };
265
- var compile = function compile(content, template) {
266
- if (isFunction(content)) {
267
- return content;
268
- } else {
269
- return compiler.compile(content, template);
230
+ this.clear = function () {
231
+ cache.list = {};
232
+ };
233
+ this.load = function (data) {
234
+ if (cache.enabled) {
235
+ extend(cache.list, data || {});
270
236
  }
237
+ return this;
271
238
  };
272
- var watcher = function watcher(config) {
273
- if (template.watcher) {
274
- template.watcher.unwatch('.');
239
+ this.get = function (key) {
240
+ if (cache.enabled) {
241
+ return cache.list[key];
275
242
  }
276
- if (config.watch && config.chokidar && isNode()) {
277
- return config.chokidar.watch('.', {
278
- cwd: template.path
279
- }).on('change', function (name) {
280
- cache.remove(name);
281
- });
243
+ };
244
+ this.set = function (key, value) {
245
+ if (cache.enabled) {
246
+ cache.list[key] = value;
282
247
  }
248
+ return this;
283
249
  };
284
- this.configure = function (config) {
285
- template.path = config.path;
286
- template.chokidar = config.chokidar;
287
- template.resolver = fileResolver(config.resolver);
288
- template.watcher = watcher(config);
250
+ this.resolve = function (key) {
251
+ return Promise.resolve(this.get(key));
289
252
  };
290
- this.get = function (template) {
291
- if (cache.exist(template)) {
292
- return cache.resolve(template);
293
- }
294
- return result(template, resolve(template).then(function (content) {
295
- return result(template, compile(content, template));
296
- }));
253
+ this.remove = function (key) {
254
+ delete cache.list[key];
255
+ };
256
+ this.exist = function (key) {
257
+ return hasProp(cache.list, key);
297
258
  };
298
- this.configure(config);
299
259
  }
300
260
 
301
261
  var tagList = [{
@@ -393,38 +353,63 @@ function Compiler(config) {
393
353
  this.configure(config);
394
354
  }
395
355
 
396
- var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
397
- function Cache(config) {
398
- if (instanceOf(this, Cache) === false) return new Cache();
399
- var cache = {
400
- list: {}
401
- };
402
- this.configure = function (config) {
403
- cache.list = {};
404
- if (isNode() === false) {
405
- this.load(global[config["export"]]);
406
- }
407
- };
408
- this.load = function (data) {
409
- extend(cache.list, data || {});
410
- return this;
411
- };
412
- this.get = function (key) {
413
- return cache.list[key];
356
+ var resolvePath = function resolvePath(path, template) {
357
+ template = [path, template].join('/');
358
+ template = template.replace(/\/\//g, '/');
359
+ return template;
360
+ };
361
+ var httpRequest = function httpRequest(path, template) {
362
+ return fetch(resolvePath(path, template)).then(function (response) {
363
+ return response.text();
364
+ });
365
+ };
366
+ var fileSystem = function fileSystem(path, template) {
367
+ return new Promise(function (resolve, reject) {
368
+ fs.readFile(resolvePath(path, template), function (error, data) {
369
+ if (error) {
370
+ reject(error);
371
+ } else {
372
+ resolve(data.toString());
373
+ }
374
+ });
375
+ });
376
+ };
377
+ var fileResolver = function fileResolver(resolver) {
378
+ return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest;
379
+ };
380
+ function Template(config, cache, compiler) {
381
+ if (instanceOf(this, Template) === false) return new Template(config, cache, compiler);
382
+ if (instanceOf(cache, Cache) === false) throw new TypeError('cache is not instance of Cache');
383
+ if (instanceOf(compiler, Compiler) === false) throw new TypeError('compiler is not instance of Compiler');
384
+ var template = {};
385
+ var result = function result(template, content) {
386
+ cache.set(template, content);
387
+ return content;
414
388
  };
415
- this.set = function (key, value) {
416
- cache.list[key] = value;
417
- return this;
389
+ var resolve = function resolve(path) {
390
+ return template.resolver(template.path, path);
418
391
  };
419
- this.resolve = function (key) {
420
- return Promise.resolve(this.get(key));
392
+ var compile = function compile(content, template) {
393
+ if (isFunction(content)) {
394
+ return content;
395
+ } else {
396
+ return compiler.compile(content, template);
397
+ }
421
398
  };
422
- this.remove = function (key) {
423
- delete cache.list[key];
399
+ this.configure = function (config) {
400
+ template.path = config.path;
401
+ template.cache = config.cache;
402
+ template.resolver = fileResolver(config.resolver);
424
403
  };
425
- this.exist = function (key) {
426
- return hasProp(cache.list, key);
404
+ this.get = function (template) {
405
+ if (cache.exist(template)) {
406
+ return cache.resolve(template);
407
+ }
408
+ return result(template, resolve(template).then(function (content) {
409
+ return result(template, compile(content, template));
410
+ }));
427
411
  };
412
+ this.configure(config);
428
413
  }
429
414
 
430
415
  function resolve(list) {
@@ -720,7 +705,7 @@ var render = ejs.render,
720
705
  compile = ejs.compile,
721
706
  helpers = ejs.helpers,
722
707
  preload = ejs.preload,
723
- configure$1 = ejs.configure,
708
+ configure = ejs.configure,
724
709
  create = ejs.create;
725
710
 
726
711
  function __express(name, options, callback) {
@@ -737,7 +722,7 @@ function __express(name, options, callback) {
737
722
  viewOptions.path = viewPath;
738
723
  viewOptions.cache = viewCache;
739
724
  configure(viewOptions);
740
- return this.render(filename, options).then(function (content) {
725
+ return render(filename, options).then(function (content) {
741
726
  callback(null, content);
742
727
  })["catch"](function (error) {
743
728
  callback(error);
@@ -747,7 +732,7 @@ function __express(name, options, callback) {
747
732
  exports.EJS = EJS;
748
733
  exports.__express = __express;
749
734
  exports.compile = compile;
750
- exports.configure = configure$1;
735
+ exports.configure = configure;
751
736
  exports.context = context;
752
737
  exports.create = create;
753
738
  exports.element = element;
package/dist/esm/index.js CHANGED
@@ -9,7 +9,6 @@ const typeProp = function () {
9
9
  const isFunction = (v) => typeof v === 'function';
10
10
  const isString = (v) => typeof v === 'string';
11
11
  const isBoolean = (v) => typeof v === 'boolean';
12
- const isObject = (v) => typeof v === 'object';
13
12
  const isUndefined = (v) => typeof v === 'undefined';
14
13
 
15
14
  const isNodeEnv =
@@ -64,7 +63,7 @@ const safeValue = (value, escape) => {
64
63
  };
65
64
 
66
65
  const instanceOf = (object, instance) => {
67
- return object instanceof instance
66
+ return Boolean(object instanceof instance)
68
67
  };
69
68
 
70
69
  const getPath = (context, name, strict) => {
@@ -161,23 +160,14 @@ const hasProp = (object, prop) => {
161
160
  };
162
161
 
163
162
  const defaults = {};
164
-
165
163
  defaults.export = 'ejsPrecompiled';
166
-
167
- defaults.watch = false;
168
-
164
+ defaults.cache = true;
169
165
  defaults.chokidar = null;
170
-
171
166
  defaults.path = 'views';
172
-
173
167
  defaults.resolver = null;
174
-
175
168
  defaults.extension = 'ejs';
176
-
177
169
  defaults.rmWhitespace = true;
178
-
179
170
  defaults.withObject = true;
180
-
181
171
  defaults.vars = {
182
172
  SCOPE: 'ejs',
183
173
  COMPONENT: 'ui',
@@ -188,7 +178,6 @@ defaults.vars = {
188
178
  MACRO: '$$m',
189
179
  SAFE: '$$v',
190
180
  };
191
-
192
181
  defaults.token = {
193
182
  start: '<%',
194
183
  end: '%>',
@@ -273,99 +262,55 @@ const configSchema = (config, options) => {
273
262
  config.rmWhitespace,
274
263
  options.rmWhitespace
275
264
  ),
276
- watch: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
277
- chokidar: typeProp(
278
- isObject,
279
- defaults.export,
280
- config.export,
281
- options.export
282
- ),
265
+ cache: typeProp(isBoolean, defaults.cache, config.cache, options.cache),
283
266
  token: extend({}, defaults.token, config.token, options.token),
284
267
  vars: extend({}, defaults.vars, config.vars, options.vars),
285
268
  });
286
269
  };
287
270
 
288
- const resolvePath = (path, template) => {
289
- template = [path, template].join('/');
290
- template = template.replace(/\/\//g, '/');
291
- return template
292
- };
293
-
294
- const httpRequest = (path, template) => {
295
- return fetch(resolvePath(path, template)).then((response) =>
296
- response.text()
297
- )
298
- };
299
-
300
- const fileSystem = (path, template) => {
301
- return new Promise((resolve, reject) => {
302
- fs.readFile(resolvePath(path, template), (error, data) => {
303
- if (error) {
304
- reject(error);
305
- } else {
306
- resolve(data.toString());
307
- }
308
- });
309
- })
310
- };
311
-
312
- const fileResolver = (resolver) => {
313
- return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest
314
- };
315
-
316
- function Template(config, cache, compiler) {
317
- if (instanceOf(this, Template) === false)
318
- return new Template(config, cache, compiler)
319
-
320
- const template = {};
271
+ const global = typeof globalThis !== 'undefined' ? globalThis : window || self;
321
272
 
322
- const result = function (template, content) {
323
- cache.set(template, content);
324
- return content
273
+ function Cache(config) {
274
+ if (instanceOf(this, Cache) === false) return new Cache()
275
+ const cache = {
276
+ enabled: true,
277
+ list: {},
325
278
  };
326
-
327
- const resolve = function (path) {
328
- return template.resolver(template.path, path)
279
+ this.configure = function (config) {
280
+ cache.enabled = config.cache;
281
+ if (isNode() === false) {
282
+ this.load(global[config.export]);
283
+ }
329
284
  };
330
-
331
- const compile = function (content, template) {
332
- if (isFunction(content)) {
333
- return content
334
- } else {
335
- return compiler.compile(content, template)
285
+ this.clear = function () {
286
+ cache.list = {};
287
+ };
288
+ this.load = function (data) {
289
+ if (cache.enabled) {
290
+ extend(cache.list, data || {});
336
291
  }
292
+ return this
337
293
  };
338
-
339
- const watcher = function (config) {
340
- if (template.watcher) {
341
- template.watcher.unwatch('.');
294
+ this.get = function (key) {
295
+ if (cache.enabled) {
296
+ return cache.list[key]
342
297
  }
343
- if (config.watch && config.chokidar && isNode()) {
344
- return config.chokidar
345
- .watch('.', { cwd: template.path })
346
- .on('change', (name) => {
347
- cache.remove(name);
348
- })
298
+ };
299
+ this.set = function (key, value) {
300
+ if (cache.enabled) {
301
+ cache.list[key] = value;
349
302
  }
303
+ return this
350
304
  };
351
- this.configure = function (config) {
352
- template.path = config.path;
353
- template.chokidar = config.chokidar;
354
- template.resolver = fileResolver(config.resolver);
355
- template.watcher = watcher(config);
305
+ this.resolve = function (key) {
306
+ return Promise.resolve(this.get(key))
356
307
  };
357
- this.get = function (template) {
358
- if (cache.exist(template)) {
359
- return cache.resolve(template)
360
- }
361
- return result(
362
- template,
363
- resolve(template).then((content) =>
364
- result(template, compile(content, template))
365
- )
366
- )
308
+ this.remove = function (key) {
309
+ delete cache.list[key];
310
+ };
311
+ this.exist = function (key) {
312
+ return hasProp(cache.list, key)
367
313
  };
368
- this.configure(config);
369
314
  }
370
315
 
371
316
  const tagList = [
@@ -488,39 +433,73 @@ function Compiler(config) {
488
433
  this.configure(config);
489
434
  }
490
435
 
491
- const global = typeof globalThis !== 'undefined' ? globalThis : window || self;
436
+ const resolvePath = (path, template) => {
437
+ template = [path, template].join('/');
438
+ template = template.replace(/\/\//g, '/');
439
+ return template
440
+ };
492
441
 
493
- function Cache(config) {
494
- if (instanceOf(this, Cache) === false) return new Cache()
495
- const cache = {
496
- list: {},
497
- };
498
- this.configure = function (config) {
499
- cache.list = {};
500
- if (isNode() === false) {
501
- this.load(global[config.export]);
502
- }
503
- };
504
- this.load = function (data) {
505
- extend(cache.list, data || {});
506
- return this
507
- };
508
- this.get = function (key) {
509
- return cache.list[key]
442
+ const httpRequest = (path, template) => {
443
+ return fetch(resolvePath(path, template)).then((response) =>
444
+ response.text()
445
+ )
446
+ };
447
+
448
+ const fileSystem = (path, template) => {
449
+ return new Promise((resolve, reject) => {
450
+ fs.readFile(resolvePath(path, template), (error, data) => {
451
+ if (error) {
452
+ reject(error);
453
+ } else {
454
+ resolve(data.toString());
455
+ }
456
+ });
457
+ })
458
+ };
459
+
460
+ const fileResolver = (resolver) => {
461
+ return isFunction(resolver) ? resolver : isNode() ? fileSystem : httpRequest
462
+ };
463
+
464
+ function Template(config, cache, compiler) {
465
+ if (instanceOf(this, Template) === false)
466
+ return new Template(config, cache, compiler)
467
+ if (instanceOf(cache, Cache) === false)
468
+ throw new TypeError('cache is not instance of Cache')
469
+ if (instanceOf(compiler, Compiler) === false)
470
+ throw new TypeError('compiler is not instance of Compiler')
471
+ const template = {};
472
+ const result = function (template, content) {
473
+ cache.set(template, content);
474
+ return content
510
475
  };
511
- this.set = function (key, value) {
512
- cache.list[key] = value;
513
- return this
476
+ const resolve = function (path) {
477
+ return template.resolver(template.path, path)
514
478
  };
515
- this.resolve = function (key) {
516
- return Promise.resolve(this.get(key))
479
+ const compile = function (content, template) {
480
+ if (isFunction(content)) {
481
+ return content
482
+ } else {
483
+ return compiler.compile(content, template)
484
+ }
517
485
  };
518
- this.remove = function (key) {
519
- delete cache.list[key];
486
+ this.configure = function (config) {
487
+ template.path = config.path;
488
+ template.cache = config.cache;
489
+ template.resolver = fileResolver(config.resolver);
520
490
  };
521
- this.exist = function (key) {
522
- return hasProp(cache.list, key)
491
+ this.get = function (template) {
492
+ if (cache.exist(template)) {
493
+ return cache.resolve(template)
494
+ }
495
+ return result(
496
+ template,
497
+ resolve(template).then((content) =>
498
+ result(template, compile(content, template))
499
+ )
500
+ )
523
501
  };
502
+ this.configure(config);
524
503
  }
525
504
 
526
505
  function resolve(list) {
@@ -790,17 +769,13 @@ function Context(config) {
790
769
 
791
770
  function EJS(options) {
792
771
  if (instanceOf(this, EJS) === false) return new EJS(options)
793
-
794
772
  const scope = {};
795
773
  const config = {};
796
-
797
774
  configSchema(config, options || {});
798
-
799
775
  const context = new Context(config);
800
776
  const compiler = new Compiler(config);
801
777
  const cache = new Cache();
802
778
  const template = new Template(config, cache, compiler);
803
-
804
779
  const output = function (path, scope) {
805
780
  return template.get(path).then(function (callback) {
806
781
  return callback.call(
@@ -812,7 +787,6 @@ function EJS(options) {
812
787
  )
813
788
  })
814
789
  };
815
-
816
790
  const require = function (name) {
817
791
  const filepath = ext(name, config.extension);
818
792
  const scope = context.create({});
@@ -874,7 +848,7 @@ function EJS(options) {
874
848
 
875
849
  const ejs = new EJS();
876
850
 
877
- const { render, context, compile, helpers, preload, configure: configure$1, create } =
851
+ const { render, context, compile, helpers, preload, configure, create } =
878
852
  ejs;
879
853
 
880
854
  function __express(name, options, callback) {
@@ -895,7 +869,7 @@ function __express(name, options, callback) {
895
869
  viewOptions.path = viewPath;
896
870
  viewOptions.cache = viewCache;
897
871
  configure(viewOptions);
898
- return this.render(filename, options)
872
+ return render(filename, options)
899
873
  .then((content) => {
900
874
  callback(null, content);
901
875
  })
@@ -904,4 +878,4 @@ function __express(name, options, callback) {
904
878
  })
905
879
  }
906
880
 
907
- export { EJS, __express, compile, configure$1 as configure, context, create, element, helpers, preload, render, safeValue };
881
+ export { EJS, __express, compile, configure, context, create, element, helpers, preload, render, safeValue };