ecto 4.4.0 → 4.4.1

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/ecto.d.ts CHANGED
@@ -15,7 +15,7 @@ declare class BaseEngine {
15
15
  opts?: any;
16
16
  engine: any;
17
17
  rootTemplatePath?: string;
18
- private __extensions;
18
+ private _extensions;
19
19
  getExtensions(): string[];
20
20
  setExtensions(extensions: string[]): void;
21
21
  deleteExtension(name: string): void;
@@ -113,17 +113,17 @@ declare enum EctoEvents {
113
113
  error = "error"
114
114
  }
115
115
  declare class Ecto extends Hookified {
116
- private readonly __mapping;
117
- private readonly __engines;
118
- private __cache;
119
- private __cacheSync;
120
- private __defaultEngine;
121
- private readonly __ejs;
122
- private readonly __markdown;
123
- private readonly __pug;
124
- private readonly __nunjucks;
125
- private readonly __handlebars;
126
- private readonly __liquid;
116
+ private readonly _mapping;
117
+ private readonly _engines;
118
+ private _cache;
119
+ private _cacheSync;
120
+ private _defaultEngine;
121
+ private readonly _ejs;
122
+ private readonly _markdown;
123
+ private readonly _pug;
124
+ private readonly _nunjucks;
125
+ private readonly _handlebars;
126
+ private readonly _liquid;
127
127
  /**
128
128
  * Ecto constructor
129
129
  * @param {EctoOptions} [options] - The options for the ecto engine
package/dist/ecto.js CHANGED
@@ -59,23 +59,23 @@ var BaseEngine = class {
59
59
  opts = void 0;
60
60
  engine;
61
61
  rootTemplatePath = void 0;
62
- __extensions = new Array();
62
+ _extensions = new Array();
63
63
  getExtensions() {
64
- return this.__extensions;
64
+ return this._extensions;
65
65
  }
66
66
  setExtensions(extensions) {
67
- this.__extensions = new Array();
67
+ this._extensions = new Array();
68
68
  for (const extension of extensions) {
69
69
  const newExtension = extension.trim().toLowerCase();
70
- if (!this.__extensions.includes(newExtension)) {
71
- this.__extensions.push(newExtension);
70
+ if (!this._extensions.includes(newExtension)) {
71
+ this._extensions.push(newExtension);
72
72
  }
73
73
  }
74
74
  }
75
75
  deleteExtension(name) {
76
- for (const [index, extension] of this.__extensions.entries()) {
76
+ for (const [index, extension] of this._extensions.entries()) {
77
77
  if (name.toLowerCase().trim() === extension) {
78
- this.__extensions.splice(index, 1);
78
+ this._extensions.splice(index, 1);
79
79
  }
80
80
  }
81
81
  }
@@ -298,19 +298,19 @@ var EctoEvents = /* @__PURE__ */ ((EctoEvents2) => {
298
298
  return EctoEvents2;
299
299
  })(EctoEvents || {});
300
300
  var Ecto = class extends Hookified {
301
- __mapping = new EngineMap();
302
- __engines = new Array();
301
+ _mapping = new EngineMap();
302
+ _engines = new Array();
303
303
  // Cacheable instance for caching rendered templates
304
- __cache;
305
- __cacheSync;
306
- __defaultEngine = "ejs";
304
+ _cache;
305
+ _cacheSync;
306
+ _defaultEngine = "ejs";
307
307
  // Engines
308
- __ejs;
309
- __markdown;
310
- __pug;
311
- __nunjucks;
312
- __handlebars;
313
- __liquid;
308
+ _ejs;
309
+ _markdown;
310
+ _pug;
311
+ _nunjucks;
312
+ _handlebars;
313
+ _liquid;
314
314
  /**
315
315
  * Ecto constructor
316
316
  * @param {EctoOptions} [options] - The options for the ecto engine
@@ -318,30 +318,26 @@ var Ecto = class extends Hookified {
318
318
  // eslint-disable-next-line complexity
319
319
  constructor(options) {
320
320
  super();
321
- this.__ejs = new EJS(options?.engineOptions?.ejs);
322
- this.__markdown = new Markdown(options?.engineOptions?.markdown);
323
- this.__pug = new Pug(options?.engineOptions?.pug);
324
- this.__nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
325
- this.__handlebars = new Handlebars(options?.engineOptions?.handlebars);
326
- this.__liquid = new Liquid(options?.engineOptions?.liquid);
327
- this.__engines.push(this.__ejs, this.__markdown, this.__pug, this.__nunjucks, this.__handlebars, this.__liquid);
321
+ this._ejs = new EJS(options?.engineOptions?.ejs);
322
+ this._markdown = new Markdown(options?.engineOptions?.markdown);
323
+ this._pug = new Pug(options?.engineOptions?.pug);
324
+ this._nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
325
+ this._handlebars = new Handlebars(options?.engineOptions?.handlebars);
326
+ this._liquid = new Liquid(options?.engineOptions?.liquid);
327
+ this._engines.push(this._ejs, this._markdown, this._pug, this._nunjucks, this._handlebars, this._liquid);
328
328
  this.registerEngineMappings();
329
- if (options?.cache !== void 0) {
330
- if (typeof options.cache === "boolean") {
331
- this.__cache = new Cacheable();
332
- } else {
333
- this.__cache = options.cache;
334
- }
329
+ if (options?.cache === true) {
330
+ this._cache = new Cacheable();
331
+ } else if (options?.cache instanceof Cacheable) {
332
+ this._cache = options.cache;
335
333
  }
336
- if (options?.cacheSync !== void 0) {
337
- if (typeof options.cacheSync === "boolean") {
338
- this.__cacheSync = new CacheableMemory();
339
- } else {
340
- this.__cacheSync = options.cacheSync;
341
- }
334
+ if (options?.cacheSync === true) {
335
+ this._cacheSync = new CacheableMemory();
336
+ } else if (options?.cacheSync instanceof CacheableMemory) {
337
+ this._cacheSync = options.cacheSync;
342
338
  }
343
339
  if (options !== void 0 && this.isValidEngine(options.defaultEngine)) {
344
- this.__defaultEngine = options.defaultEngine;
340
+ this._defaultEngine = options.defaultEngine;
345
341
  }
346
342
  }
347
343
  /**
@@ -349,7 +345,7 @@ var Ecto = class extends Hookified {
349
345
  * @returns {string} - the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
350
346
  */
351
347
  get defaultEngine() {
352
- return this.__defaultEngine;
348
+ return this._defaultEngine;
353
349
  }
354
350
  /**
355
351
  * Set the default engine
@@ -358,9 +354,9 @@ var Ecto = class extends Hookified {
358
354
  set defaultEngine(value) {
359
355
  value = value.toLowerCase().trim();
360
356
  if (this.isValidEngine(value)) {
361
- this.__defaultEngine = value;
357
+ this._defaultEngine = value;
362
358
  } else {
363
- this.emit("warn" /* warn */, `Invalid engine name: ${value}. Defaulting to ${this.__defaultEngine}.`);
359
+ this.emit("warn" /* warn */, `Invalid engine name: ${value}. Defaulting to ${this._defaultEngine}.`);
364
360
  }
365
361
  }
366
362
  /**
@@ -368,77 +364,77 @@ var Ecto = class extends Hookified {
368
364
  * @returns {Cacheable | undefined} - The cacheable instance or undefined if caching is disabled
369
365
  */
370
366
  get cache() {
371
- return this.__cache;
367
+ return this._cache;
372
368
  }
373
369
  /**
374
370
  * Set the cacheable instance
375
371
  * @param {Cacheable | undefined} value - The cacheable instance to set. If set to undefined, caching will be disabled.
376
372
  */
377
373
  set cache(value) {
378
- this.__cache = value;
374
+ this._cache = value;
379
375
  }
380
376
  /**
381
377
  * Get the cacheable memory instance
382
378
  * @returns {CacheableMemory | undefined} - The cacheable memory instance or undefined if caching is disabled
383
379
  */
384
380
  get cacheSync() {
385
- return this.__cacheSync;
381
+ return this._cacheSync;
386
382
  }
387
383
  /**
388
384
  * Set the cacheable memory instance
389
385
  * @param {CacheableMemory | undefined} value - The cacheable memory instance to set. If set to undefined, caching will be disabled.
390
386
  */
391
387
  set cacheSync(value) {
392
- this.__cacheSync = value;
388
+ this._cacheSync = value;
393
389
  }
394
390
  /**
395
391
  * Get the Engine Mappings. This is used to map file extensions to engines
396
392
  * @returns {EngineMap}
397
393
  */
398
394
  get mappings() {
399
- return this.__mapping;
395
+ return this._mapping;
400
396
  }
401
397
  /**
402
398
  * Get the EJS Engine
403
399
  * @returns {EJS}
404
400
  */
405
401
  get ejs() {
406
- return this.__ejs;
402
+ return this._ejs;
407
403
  }
408
404
  /**
409
405
  * Get the Markdown Engine
410
406
  * @returns {Markdown}
411
407
  */
412
408
  get markdown() {
413
- return this.__markdown;
409
+ return this._markdown;
414
410
  }
415
411
  /**
416
412
  * Get the Pug Engine
417
413
  * @returns {Pug}
418
414
  */
419
415
  get pug() {
420
- return this.__pug;
416
+ return this._pug;
421
417
  }
422
418
  /**
423
419
  * Get the Nunjucks Engine
424
420
  * @returns {Nunjucks}
425
421
  */
426
422
  get nunjucks() {
427
- return this.__nunjucks;
423
+ return this._nunjucks;
428
424
  }
429
425
  /**
430
426
  * Get the Handlebars Engine
431
427
  * @returns {Handlebars}
432
428
  */
433
429
  get handlebars() {
434
- return this.__handlebars;
430
+ return this._handlebars;
435
431
  }
436
432
  /**
437
433
  * Get the Liquid Engine
438
434
  * @returns {Liquid}
439
435
  */
440
436
  get liquid() {
441
- return this.__liquid;
437
+ return this._liquid;
442
438
  }
443
439
  /**
444
440
  * Async render the source with the data
@@ -452,9 +448,9 @@ var Ecto = class extends Hookified {
452
448
  // eslint-disable-next-line max-params
453
449
  async render(source, data, engineName, rootTemplatePath, filePathOutput) {
454
450
  try {
455
- const cacheKey = `${engineName ?? this.__defaultEngine}-${source}-${JSON.stringify(data)}`;
456
- if (this.__cache) {
457
- const cachedResult = await this.__cache.get(cacheKey);
451
+ const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
452
+ if (this._cache) {
453
+ const cachedResult = await this._cache.get(cacheKey);
458
454
  if (cachedResult) {
459
455
  this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
460
456
  await this.writeFile(filePathOutput, cachedResult);
@@ -463,15 +459,15 @@ var Ecto = class extends Hookified {
463
459
  this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
464
460
  }
465
461
  let result = "";
466
- let renderEngineName = this.__defaultEngine;
462
+ let renderEngineName = this._defaultEngine;
467
463
  if (this.isValidEngine(engineName) && engineName !== void 0) {
468
464
  renderEngineName = engineName;
469
465
  }
470
466
  const renderEngine = this.getRenderEngine(renderEngineName);
471
467
  renderEngine.rootTemplatePath = rootTemplatePath;
472
468
  result = await renderEngine.render(source, data);
473
- if (this.__cache) {
474
- await this.__cache.set(cacheKey, result);
469
+ if (this._cache) {
470
+ await this._cache.set(cacheKey, result);
475
471
  }
476
472
  await this.writeFile(filePathOutput, result);
477
473
  return result;
@@ -492,9 +488,9 @@ var Ecto = class extends Hookified {
492
488
  // eslint-disable-next-line max-params
493
489
  renderSync(source, data, engineName, rootTemplatePath, filePathOutput) {
494
490
  try {
495
- const cacheKey = `${engineName ?? this.__defaultEngine}-${source}-${JSON.stringify(data)}`;
496
- if (this.__cacheSync) {
497
- const cachedResult = this.__cacheSync.get(cacheKey);
491
+ const cacheKey = `${engineName ?? this._defaultEngine}-${source}-${JSON.stringify(data)}`;
492
+ if (this._cacheSync) {
493
+ const cachedResult = this._cacheSync.get(cacheKey);
498
494
  if (cachedResult) {
499
495
  this.emit("cacheHit" /* cacheHit */, `Cache hit for key: ${cacheKey}`);
500
496
  this.writeFileSync(filePathOutput, cachedResult);
@@ -503,15 +499,15 @@ var Ecto = class extends Hookified {
503
499
  this.emit("cacheMiss" /* cacheMiss */, `Cache miss for key: ${cacheKey}`);
504
500
  }
505
501
  let result = "";
506
- let renderEngineName = this.__defaultEngine;
502
+ let renderEngineName = this._defaultEngine;
507
503
  if (this.isValidEngine(engineName) && engineName !== void 0) {
508
504
  renderEngineName = engineName;
509
505
  }
510
506
  const renderEngine = this.getRenderEngine(renderEngineName);
511
507
  renderEngine.rootTemplatePath = rootTemplatePath;
512
508
  result = renderEngine.renderSync(source, data);
513
- if (this.__cacheSync) {
514
- this.__cacheSync.set(cacheKey, result);
509
+ if (this._cacheSync) {
510
+ this._cacheSync.set(cacheKey, result);
515
511
  }
516
512
  this.writeFileSync(filePathOutput, result);
517
513
  return result;
@@ -586,10 +582,10 @@ var Ecto = class extends Hookified {
586
582
  * @returns {string} - will return the engine name such as 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
587
583
  */
588
584
  getEngineByFilePath(filePath) {
589
- let result = this.__defaultEngine;
585
+ let result = this._defaultEngine;
590
586
  if (filePath !== void 0) {
591
587
  const extension = filePath.includes(".") ? filePath.slice(filePath.lastIndexOf(".") + 1) : "";
592
- const engExtension = this.__mapping.getName(extension);
588
+ const engExtension = this._mapping.getName(extension);
593
589
  if (engExtension !== void 0) {
594
590
  result = engExtension;
595
591
  }
@@ -637,7 +633,7 @@ var Ecto = class extends Hookified {
637
633
  */
638
634
  isValidEngine(engineName) {
639
635
  let result = false;
640
- if (engineName !== void 0 && this.__mapping.get(engineName) !== void 0) {
636
+ if (engineName !== void 0 && this._mapping.get(engineName) !== void 0) {
641
637
  result = true;
642
638
  }
643
639
  return result;
@@ -647,9 +643,9 @@ var Ecto = class extends Hookified {
647
643
  * @returns {void}
648
644
  */
649
645
  registerEngineMappings() {
650
- for (const eng of this.__engines) {
646
+ for (const eng of this._engines) {
651
647
  for (const name of eng.names) {
652
- this.__mapping.set(name, eng.getExtensions());
648
+ this._mapping.set(name, eng.getExtensions());
653
649
  }
654
650
  }
655
651
  }
@@ -659,35 +655,35 @@ var Ecto = class extends Hookified {
659
655
  * @returns {EngineInterface}
660
656
  */
661
657
  getRenderEngine(engineName) {
662
- let result = this.__ejs;
658
+ let result = this._ejs;
663
659
  const cleanEngineName = engineName.trim().toLowerCase();
664
660
  switch (cleanEngineName) {
665
661
  case "markdown": {
666
- result = this.__markdown;
662
+ result = this._markdown;
667
663
  break;
668
664
  }
669
665
  case "pug": {
670
- result = this.__pug;
666
+ result = this._pug;
671
667
  break;
672
668
  }
673
669
  case "nunjucks": {
674
- result = this.__nunjucks;
670
+ result = this._nunjucks;
675
671
  break;
676
672
  }
677
673
  case "mustache": {
678
- result = this.__handlebars;
674
+ result = this._handlebars;
679
675
  break;
680
676
  }
681
677
  case "handlebars": {
682
- result = this.__handlebars;
678
+ result = this._handlebars;
683
679
  break;
684
680
  }
685
681
  case "liquid": {
686
- result = this.__liquid;
682
+ result = this._liquid;
687
683
  break;
688
684
  }
689
685
  default: {
690
- result = this.__ejs;
686
+ result = this._ejs;
691
687
  break;
692
688
  }
693
689
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecto",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, Liquid, and Handlebars",
5
5
  "type": "module",
6
6
  "main": "./dist/ecto.js",
@@ -47,28 +47,28 @@
47
47
  ],
48
48
  "dependencies": {
49
49
  "@jaredwray/fumanchu": "^3.1.2",
50
- "cacheable": "^1.10.1",
50
+ "cacheable": "^1.10.4",
51
51
  "ejs": "^3.1.10",
52
- "hookified": "^1.10.0",
52
+ "hookified": "^1.11.0",
53
53
  "liquidjs": "^10.21.1",
54
54
  "nunjucks": "^3.2.4",
55
55
  "pug": "^3.0.3",
56
56
  "underscore": "^1.13.7",
57
- "writr": "^4.4.5"
57
+ "writr": "^4.4.6"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/ejs": "^3.1.5",
61
- "@types/node": "^24.0.14",
61
+ "@types/node": "^24.3.0",
62
62
  "@types/nunjucks": "^3.2.6",
63
63
  "@types/pug": "^2.0.10",
64
64
  "@types/underscore": "^1.13.0",
65
65
  "@vitest/coverage-v8": "^3.2.4",
66
- "docula": "^0.13.0",
66
+ "docula": "^0.20.0",
67
67
  "rimraf": "^6.0.1",
68
68
  "tsup": "^8.5.0",
69
- "typescript": "^5.8.3",
69
+ "typescript": "^5.9.2",
70
70
  "vitest": "^3.2.4",
71
- "webpack": "^5.100.2",
71
+ "webpack": "^5.101.3",
72
72
  "xo": "^1.2.0"
73
73
  },
74
74
  "files": [