@kosatyi/ejs 0.0.63 → 0.0.64
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 +16 -35
- package/dist/esm/index.js +16 -39
- package/dist/umd/index.js +687 -706
- package/dist/umd/index.min.js +1 -1
- package/package.json +1 -1
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
|
};
|
|
@@ -165,7 +152,7 @@ var hasProp = function hasProp(object, prop) {
|
|
|
165
152
|
|
|
166
153
|
var defaults = {};
|
|
167
154
|
defaults["export"] = 'ejsPrecompiled';
|
|
168
|
-
defaults.
|
|
155
|
+
defaults.cache = true;
|
|
169
156
|
defaults.chokidar = null;
|
|
170
157
|
defaults.path = 'views';
|
|
171
158
|
defaults.resolver = null;
|
|
@@ -221,8 +208,7 @@ 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
|
-
|
|
225
|
-
chokidar: typeProp(isObject, defaults["export"], config["export"], options["export"]),
|
|
211
|
+
cache: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
|
|
226
212
|
token: extend({}, defaults.token, config.token, options.token),
|
|
227
213
|
vars: extend({}, defaults.vars, config.vars, options.vars)
|
|
228
214
|
});
|
|
@@ -269,23 +255,10 @@ function Template(config, cache, compiler) {
|
|
|
269
255
|
return compiler.compile(content, template);
|
|
270
256
|
}
|
|
271
257
|
};
|
|
272
|
-
var watcher = function watcher(config) {
|
|
273
|
-
if (template.watcher) {
|
|
274
|
-
template.watcher.unwatch('.');
|
|
275
|
-
}
|
|
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
|
-
});
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
258
|
this.configure = function (config) {
|
|
285
259
|
template.path = config.path;
|
|
286
|
-
template.
|
|
260
|
+
template.cache = config.cache;
|
|
287
261
|
template.resolver = fileResolver(config.resolver);
|
|
288
|
-
template.watcher = watcher(config);
|
|
289
262
|
};
|
|
290
263
|
this.get = function (template) {
|
|
291
264
|
if (cache.exist(template)) {
|
|
@@ -397,23 +370,31 @@ var global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
|
397
370
|
function Cache(config) {
|
|
398
371
|
if (instanceOf(this, Cache) === false) return new Cache();
|
|
399
372
|
var cache = {
|
|
373
|
+
enabled: true,
|
|
400
374
|
list: {}
|
|
401
375
|
};
|
|
402
376
|
this.configure = function (config) {
|
|
403
377
|
cache.list = {};
|
|
378
|
+
cache.enabled = config.cache;
|
|
404
379
|
if (isNode() === false) {
|
|
405
380
|
this.load(global[config["export"]]);
|
|
406
381
|
}
|
|
407
382
|
};
|
|
408
383
|
this.load = function (data) {
|
|
409
|
-
|
|
384
|
+
if (cache.enabled) {
|
|
385
|
+
extend(cache.list, data || {});
|
|
386
|
+
}
|
|
410
387
|
return this;
|
|
411
388
|
};
|
|
412
389
|
this.get = function (key) {
|
|
413
|
-
|
|
390
|
+
if (cache.enabled) {
|
|
391
|
+
return cache.list[key];
|
|
392
|
+
}
|
|
414
393
|
};
|
|
415
394
|
this.set = function (key, value) {
|
|
416
|
-
cache.
|
|
395
|
+
if (cache.enabled) {
|
|
396
|
+
cache.list[key] = value;
|
|
397
|
+
}
|
|
417
398
|
return this;
|
|
418
399
|
};
|
|
419
400
|
this.resolve = function (key) {
|
|
@@ -720,7 +701,7 @@ var render = ejs.render,
|
|
|
720
701
|
compile = ejs.compile,
|
|
721
702
|
helpers = ejs.helpers,
|
|
722
703
|
preload = ejs.preload,
|
|
723
|
-
configure
|
|
704
|
+
configure = ejs.configure,
|
|
724
705
|
create = ejs.create;
|
|
725
706
|
|
|
726
707
|
function __express(name, options, callback) {
|
|
@@ -747,7 +728,7 @@ function __express(name, options, callback) {
|
|
|
747
728
|
exports.EJS = EJS;
|
|
748
729
|
exports.__express = __express;
|
|
749
730
|
exports.compile = compile;
|
|
750
|
-
exports.configure = configure
|
|
731
|
+
exports.configure = configure;
|
|
751
732
|
exports.context = context;
|
|
752
733
|
exports.create = create;
|
|
753
734
|
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 =
|
|
@@ -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,13 +262,7 @@ const configSchema = (config, options) => {
|
|
|
273
262
|
config.rmWhitespace,
|
|
274
263
|
options.rmWhitespace
|
|
275
264
|
),
|
|
276
|
-
|
|
277
|
-
chokidar: typeProp(
|
|
278
|
-
isObject,
|
|
279
|
-
defaults.export,
|
|
280
|
-
config.export,
|
|
281
|
-
options.export
|
|
282
|
-
),
|
|
265
|
+
cache: typeProp(isBoolean, defaults.watch, config.watch, options.watch),
|
|
283
266
|
token: extend({}, defaults.token, config.token, options.token),
|
|
284
267
|
vars: extend({}, defaults.vars, config.vars, options.vars),
|
|
285
268
|
});
|
|
@@ -335,24 +318,10 @@ function Template(config, cache, compiler) {
|
|
|
335
318
|
return compiler.compile(content, template)
|
|
336
319
|
}
|
|
337
320
|
};
|
|
338
|
-
|
|
339
|
-
const watcher = function (config) {
|
|
340
|
-
if (template.watcher) {
|
|
341
|
-
template.watcher.unwatch('.');
|
|
342
|
-
}
|
|
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
|
-
})
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
321
|
this.configure = function (config) {
|
|
352
322
|
template.path = config.path;
|
|
353
|
-
template.
|
|
323
|
+
template.cache = config.cache;
|
|
354
324
|
template.resolver = fileResolver(config.resolver);
|
|
355
|
-
template.watcher = watcher(config);
|
|
356
325
|
};
|
|
357
326
|
this.get = function (template) {
|
|
358
327
|
if (cache.exist(template)) {
|
|
@@ -493,23 +462,31 @@ const global = typeof globalThis !== 'undefined' ? globalThis : window || self;
|
|
|
493
462
|
function Cache(config) {
|
|
494
463
|
if (instanceOf(this, Cache) === false) return new Cache()
|
|
495
464
|
const cache = {
|
|
465
|
+
enabled: true,
|
|
496
466
|
list: {},
|
|
497
467
|
};
|
|
498
468
|
this.configure = function (config) {
|
|
499
469
|
cache.list = {};
|
|
470
|
+
cache.enabled = config.cache;
|
|
500
471
|
if (isNode() === false) {
|
|
501
472
|
this.load(global[config.export]);
|
|
502
473
|
}
|
|
503
474
|
};
|
|
504
475
|
this.load = function (data) {
|
|
505
|
-
|
|
476
|
+
if (cache.enabled) {
|
|
477
|
+
extend(cache.list, data || {});
|
|
478
|
+
}
|
|
506
479
|
return this
|
|
507
480
|
};
|
|
508
481
|
this.get = function (key) {
|
|
509
|
-
|
|
482
|
+
if (cache.enabled) {
|
|
483
|
+
return cache.list[key]
|
|
484
|
+
}
|
|
510
485
|
};
|
|
511
486
|
this.set = function (key, value) {
|
|
512
|
-
cache.
|
|
487
|
+
if (cache.enabled) {
|
|
488
|
+
cache.list[key] = value;
|
|
489
|
+
}
|
|
513
490
|
return this
|
|
514
491
|
};
|
|
515
492
|
this.resolve = function (key) {
|
|
@@ -874,7 +851,7 @@ function EJS(options) {
|
|
|
874
851
|
|
|
875
852
|
const ejs = new EJS();
|
|
876
853
|
|
|
877
|
-
const { render, context, compile, helpers, preload, configure
|
|
854
|
+
const { render, context, compile, helpers, preload, configure, create } =
|
|
878
855
|
ejs;
|
|
879
856
|
|
|
880
857
|
function __express(name, options, callback) {
|
|
@@ -904,4 +881,4 @@ function __express(name, options, callback) {
|
|
|
904
881
|
})
|
|
905
882
|
}
|
|
906
883
|
|
|
907
|
-
export { EJS, __express, compile, configure
|
|
884
|
+
export { EJS, __express, compile, configure, context, create, element, helpers, preload, render, safeValue };
|