@jaredwray/fumanchu 4.6.0 → 4.7.0

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/index.js DELETED
@@ -1,3170 +0,0 @@
1
- // src/index.ts
2
- import {
3
- CacheableMemory
4
- } from "@cacheable/memory";
5
- import HandlebarsLib from "handlebars";
6
-
7
- // src/helpers/array.ts
8
- var after = (array, n) => {
9
- if (!Array.isArray(array)) return [];
10
- return array.slice(n);
11
- };
12
- var before = (array, n) => {
13
- if (!Array.isArray(array)) return [];
14
- return array.slice(0, -n);
15
- };
16
- var arrayify = (value) => {
17
- if (value == null) return [];
18
- return Array.isArray(value) ? value : [value];
19
- };
20
- var first = (array, n) => {
21
- if (!Array.isArray(array)) return void 0;
22
- if (typeof n !== "number") {
23
- return array[0];
24
- }
25
- return array.slice(0, n);
26
- };
27
- var last = (value, n) => {
28
- if (!Array.isArray(value) && typeof value !== "string") {
29
- return void 0;
30
- }
31
- if (typeof n !== "number") {
32
- const array = value;
33
- return array[array.length - 1];
34
- }
35
- const start = Math.abs(n);
36
- if (typeof value === "string") {
37
- return value.slice(-start);
38
- }
39
- return value.slice(-start);
40
- };
41
- var length = (value) => {
42
- if (value && typeof value === "object" && !Array.isArray(value)) {
43
- return Object.keys(value).length;
44
- }
45
- if (typeof value === "string" || Array.isArray(value)) {
46
- return value.length;
47
- }
48
- return 0;
49
- };
50
- var join = (array, separator = ", ") => {
51
- if (typeof array === "string") return array;
52
- if (!Array.isArray(array)) return "";
53
- return array.join(separator);
54
- };
55
- var forEach = function(collection, options2) {
56
- if (!Array.isArray(collection) || !options2 || typeof options2.fn !== "function") {
57
- return options2?.inverse ? options2.inverse(this) ?? "" : "";
58
- }
59
- if (collection.length === 0) {
60
- return options2.inverse ? options2.inverse(this) ?? "" : "";
61
- }
62
- const total = collection.length;
63
- const hash = options2.hash ?? {};
64
- const baseData = options2.data ? { ...options2.data } : void 0;
65
- let result = "";
66
- for (let index = 0; index < total; index++) {
67
- const value = collection[index];
68
- const meta = {
69
- index,
70
- total,
71
- isFirst: index === 0,
72
- isLast: index === total - 1
73
- };
74
- const data = {
75
- ...baseData ? { ...baseData } : {},
76
- ...hash,
77
- ...meta
78
- };
79
- let context;
80
- if (value != null && typeof value === "object") {
81
- context = { ...value, ...hash, ...meta };
82
- } else {
83
- context = { value, ...hash, ...meta };
84
- }
85
- result += options2.fn(context, { data });
86
- }
87
- return result;
88
- };
89
- var inArray = function(array, value, options2) {
90
- if (!Array.isArray(array) || !options2) {
91
- return "";
92
- }
93
- const found = array.includes(value);
94
- if (found && options2.fn) {
95
- return options2.fn(this);
96
- }
97
- if (!found && options2.inverse) {
98
- return options2.inverse(this);
99
- }
100
- return "";
101
- };
102
- var isArray = (value) => {
103
- return Array.isArray(value);
104
- };
105
- var itemAt = (array, idx) => {
106
- if (!Array.isArray(array)) return void 0;
107
- return array[idx];
108
- };
109
- var equalsLength = function(value, targetLength, options2) {
110
- const actualLength = length(value);
111
- const isEqual = actualLength === targetLength;
112
- if (options2 && (options2.fn || options2.inverse)) {
113
- if (isEqual && options2.fn) {
114
- return options2.fn(this);
115
- }
116
- if (!isEqual && options2.inverse) {
117
- return options2.inverse(this);
118
- }
119
- return "";
120
- }
121
- return isEqual;
122
- };
123
- var some = function(array, iter, options2) {
124
- if (!Array.isArray(array) || typeof iter !== "function" || !options2) {
125
- return options2?.inverse ? options2.inverse(this) ?? "" : "";
126
- }
127
- const hasSome = array.some(iter);
128
- if (hasSome && options2.fn) {
129
- return options2.fn(this);
130
- }
131
- if (!hasSome && options2.inverse) {
132
- return options2.inverse(this);
133
- }
134
- return "";
135
- };
136
- var eachIndex = function(array, options2) {
137
- if (!Array.isArray(array) || !options2 || typeof options2.fn !== "function") {
138
- return options2?.inverse ? options2.inverse(this) ?? "" : "";
139
- }
140
- if (array.length === 0) {
141
- return options2.inverse ? options2.inverse(this) ?? "" : "";
142
- }
143
- let result = "";
144
- for (let index = 0; index < array.length; index++) {
145
- const context = {
146
- item: array[index],
147
- index
148
- };
149
- result += options2.fn(context);
150
- }
151
- return result;
152
- };
153
- var withAfter = function(array, idx, options2) {
154
- if (!Array.isArray(array) || !options2 || typeof options2.fn !== "function") {
155
- return "";
156
- }
157
- const sliced = array.slice(idx + 1);
158
- if (sliced.length === 0) {
159
- return options2.inverse ? options2.inverse(this) ?? "" : "";
160
- }
161
- let result = "";
162
- for (const item of sliced) {
163
- result += options2.fn(item);
164
- }
165
- return result;
166
- };
167
- var withBefore = function(array, idx, options2) {
168
- if (!Array.isArray(array) || !options2 || typeof options2.fn !== "function") {
169
- return "";
170
- }
171
- const sliced = array.slice(0, idx);
172
- if (sliced.length === 0) {
173
- return options2.inverse ? options2.inverse(this) ?? "" : "";
174
- }
175
- let result = "";
176
- for (const item of sliced) {
177
- result += options2.fn(item);
178
- }
179
- return result;
180
- };
181
- var withFirst = function(array, n, options2) {
182
- let count = 1;
183
- let opts = options2;
184
- if (typeof n === "object" && n !== null && !Array.isArray(n)) {
185
- opts = n;
186
- } else if (typeof n === "number") {
187
- count = n;
188
- }
189
- if (!Array.isArray(array) || !opts || typeof opts.fn !== "function") {
190
- return "";
191
- }
192
- if (array.length === 0) {
193
- return opts.inverse ? opts.inverse(this) ?? "" : "";
194
- }
195
- const items = array.slice(0, count);
196
- let result = "";
197
- for (const item of items) {
198
- result += opts.fn(item);
199
- }
200
- return result;
201
- };
202
- var withLast = function(array, n, options2) {
203
- let count = 1;
204
- let opts = options2;
205
- if (typeof n === "object" && n !== null && !Array.isArray(n)) {
206
- opts = n;
207
- } else if (typeof n === "number") {
208
- count = n;
209
- }
210
- if (!Array.isArray(array) || !opts || typeof opts.fn !== "function") {
211
- return "";
212
- }
213
- if (array.length === 0) {
214
- return opts.inverse ? opts.inverse(this) ?? "" : "";
215
- }
216
- const items = array.slice(-count);
217
- let result = "";
218
- for (const item of items) {
219
- result += opts.fn(item);
220
- }
221
- return result;
222
- };
223
- var withGroup = function(array, size, options2) {
224
- if (!Array.isArray(array) || typeof size !== "number" || size <= 0 || !options2 || typeof options2.fn !== "function") {
225
- return "";
226
- }
227
- if (array.length === 0) {
228
- return options2.inverse ? options2.inverse(this) ?? "" : "";
229
- }
230
- let result = "";
231
- const groups = [];
232
- for (let i = 0; i < array.length; i += size) {
233
- groups.push(array.slice(i, i + size));
234
- }
235
- for (const group of groups) {
236
- result += options2.fn(group);
237
- }
238
- return result;
239
- };
240
- var withSort = function(array, prop, options2) {
241
- let sortProp;
242
- let opts = options2;
243
- if (typeof prop === "object" && prop !== null && !Array.isArray(prop)) {
244
- opts = prop;
245
- } else if (typeof prop === "string") {
246
- sortProp = prop;
247
- }
248
- if (!Array.isArray(array) || !opts || typeof opts.fn !== "function") {
249
- return "";
250
- }
251
- if (array.length === 0) {
252
- return opts.inverse ? opts.inverse(this) ?? "" : "";
253
- }
254
- const sorted = [...array];
255
- if (sortProp) {
256
- sorted.sort((a, b) => {
257
- const aVal = a?.[sortProp];
258
- const bVal = b?.[sortProp];
259
- if (aVal === bVal) return 0;
260
- if (aVal == null) return 1;
261
- if (bVal == null) return -1;
262
- if (typeof aVal === "string" && typeof bVal === "string") {
263
- return aVal.localeCompare(bVal);
264
- }
265
- return aVal < bVal ? -1 : 1;
266
- });
267
- } else {
268
- sorted.sort((a, b) => {
269
- if (a === b) return 0;
270
- if (a == null) return 1;
271
- if (b == null) return -1;
272
- if (typeof a === "string" && typeof b === "string") {
273
- return a.localeCompare(b);
274
- }
275
- return a < b ? -1 : 1;
276
- });
277
- }
278
- const shouldReverse = opts.hash?.reverse === true || opts.hash?.reverse === "true";
279
- if (shouldReverse) {
280
- sorted.reverse();
281
- }
282
- let result = "";
283
- for (const item of sorted) {
284
- result += opts.fn(item);
285
- }
286
- return result;
287
- };
288
- var filter = function(array, value, options2) {
289
- if (!Array.isArray(array) || !options2) {
290
- return options2?.inverse ? options2.inverse(this) ?? "" : "";
291
- }
292
- const filtered = array.filter((item) => item === value);
293
- if (filtered.length > 0 && options2.fn) {
294
- return options2.fn(this);
295
- }
296
- if (filtered.length === 0 && options2.inverse) {
297
- return options2.inverse(this);
298
- }
299
- return "";
300
- };
301
- var map = (array, fn) => {
302
- if (!Array.isArray(array) || typeof fn !== "function") {
303
- return [];
304
- }
305
- return array.map(fn);
306
- };
307
- var pluck = (collection, prop) => {
308
- if (!Array.isArray(collection) || typeof prop !== "string") {
309
- return [];
310
- }
311
- return collection.map((item) => {
312
- if (item == null || typeof item !== "object") {
313
- return void 0;
314
- }
315
- const parts = prop.split(".");
316
- let value = item;
317
- for (const part of parts) {
318
- if (value == null || typeof value !== "object") {
319
- return void 0;
320
- }
321
- value = value[part];
322
- }
323
- return value;
324
- });
325
- };
326
- var reverse = (value) => {
327
- if (typeof value === "string") {
328
- return value.split("").reverse().join("");
329
- }
330
- if (Array.isArray(value)) {
331
- return [...value].reverse();
332
- }
333
- return void 0;
334
- };
335
- var sort = (array, key) => {
336
- if (!Array.isArray(array)) {
337
- return [];
338
- }
339
- const sorted = [...array];
340
- if (typeof key === "function") {
341
- sorted.sort(key);
342
- } else if (typeof key === "string") {
343
- sorted.sort((a, b) => {
344
- const aVal = a?.[key];
345
- const bVal = b?.[key];
346
- if (aVal === bVal) return 0;
347
- if (aVal == null) return 1;
348
- if (bVal == null) return -1;
349
- if (typeof aVal === "string" && typeof bVal === "string") {
350
- return aVal.localeCompare(bVal);
351
- }
352
- return aVal < bVal ? -1 : 1;
353
- });
354
- } else {
355
- sorted.sort((a, b) => {
356
- if (a === b) return 0;
357
- if (a == null) return 1;
358
- if (b == null) return -1;
359
- if (typeof a === "string" && typeof b === "string") {
360
- return a.localeCompare(b);
361
- }
362
- return a < b ? -1 : 1;
363
- });
364
- }
365
- return sorted;
366
- };
367
- var sortBy = (array, ...props) => {
368
- if (!Array.isArray(array) || props.length === 0) {
369
- return [];
370
- }
371
- const sorted = [...array];
372
- sorted.sort((a, b) => {
373
- for (const prop of props) {
374
- const aVal = a?.[prop];
375
- const bVal = b?.[prop];
376
- if (aVal === bVal) continue;
377
- if (aVal == null) return 1;
378
- if (bVal == null) return -1;
379
- if (typeof aVal === "string" && typeof bVal === "string") {
380
- const result = aVal.localeCompare(bVal);
381
- if (result !== 0) return result;
382
- } else {
383
- return aVal < bVal ? -1 : 1;
384
- }
385
- }
386
- return 0;
387
- });
388
- return sorted;
389
- };
390
- var unique = function(array, options2) {
391
- if (!Array.isArray(array)) {
392
- if (!options2) {
393
- return [];
394
- }
395
- return options2.inverse ? options2.inverse(this) ?? "" : "";
396
- }
397
- const uniqueArray = [...new Set(array)];
398
- if (!options2) {
399
- return uniqueArray;
400
- }
401
- if (uniqueArray.length === 0 && options2.inverse) {
402
- return options2.inverse(this);
403
- }
404
- if (uniqueArray.length > 0 && options2.fn) {
405
- let result = "";
406
- for (const item of uniqueArray) {
407
- result += options2.fn(item);
408
- }
409
- return result;
410
- }
411
- return "";
412
- };
413
- var helpers = [
414
- {
415
- name: "after",
416
- category: "array",
417
- compatibility: ["browser", "nodejs"],
418
- fn: after
419
- },
420
- {
421
- name: "before",
422
- category: "array",
423
- compatibility: ["browser", "nodejs"],
424
- fn: before
425
- },
426
- {
427
- name: "arrayify",
428
- category: "array",
429
- compatibility: ["browser", "nodejs"],
430
- fn: arrayify
431
- },
432
- {
433
- name: "first",
434
- category: "array",
435
- compatibility: ["browser", "nodejs"],
436
- fn: first
437
- },
438
- {
439
- name: "last",
440
- category: "array",
441
- compatibility: ["browser", "nodejs"],
442
- fn: last
443
- },
444
- {
445
- name: "length",
446
- category: "array",
447
- compatibility: ["browser", "nodejs"],
448
- fn: length
449
- },
450
- {
451
- name: "join",
452
- category: "array",
453
- compatibility: ["browser", "nodejs"],
454
- fn: join
455
- },
456
- {
457
- name: "forEach",
458
- category: "array",
459
- compatibility: ["browser", "nodejs"],
460
- fn: forEach
461
- },
462
- {
463
- name: "inArray",
464
- category: "array",
465
- compatibility: ["browser", "nodejs"],
466
- fn: inArray
467
- },
468
- {
469
- name: "isArray",
470
- category: "array",
471
- compatibility: ["browser", "nodejs"],
472
- fn: isArray
473
- },
474
- {
475
- name: "itemAt",
476
- category: "array",
477
- compatibility: ["browser", "nodejs"],
478
- fn: itemAt
479
- },
480
- {
481
- name: "equalsLength",
482
- category: "array",
483
- compatibility: ["browser", "nodejs"],
484
- fn: equalsLength
485
- },
486
- {
487
- name: "some",
488
- category: "array",
489
- compatibility: ["browser", "nodejs"],
490
- fn: some
491
- },
492
- {
493
- name: "eachIndex",
494
- category: "array",
495
- compatibility: ["browser", "nodejs"],
496
- fn: eachIndex
497
- },
498
- {
499
- name: "withAfter",
500
- category: "array",
501
- compatibility: ["browser", "nodejs"],
502
- fn: withAfter
503
- },
504
- {
505
- name: "withBefore",
506
- category: "array",
507
- compatibility: ["browser", "nodejs"],
508
- fn: withBefore
509
- },
510
- {
511
- name: "withFirst",
512
- category: "array",
513
- compatibility: ["browser", "nodejs"],
514
- fn: withFirst
515
- },
516
- {
517
- name: "withLast",
518
- category: "array",
519
- compatibility: ["browser", "nodejs"],
520
- fn: withLast
521
- },
522
- {
523
- name: "withGroup",
524
- category: "array",
525
- compatibility: ["browser", "nodejs"],
526
- fn: withGroup
527
- },
528
- {
529
- name: "withSort",
530
- category: "array",
531
- compatibility: ["browser", "nodejs"],
532
- fn: withSort
533
- },
534
- {
535
- name: "filter",
536
- category: "array",
537
- compatibility: ["browser", "nodejs"],
538
- fn: filter
539
- },
540
- {
541
- name: "map",
542
- category: "array",
543
- compatibility: ["browser", "nodejs"],
544
- fn: map
545
- },
546
- {
547
- name: "pluck",
548
- category: "array",
549
- compatibility: ["browser", "nodejs"],
550
- fn: pluck
551
- },
552
- {
553
- name: "reverse",
554
- category: "array",
555
- compatibility: ["browser", "nodejs"],
556
- fn: reverse
557
- },
558
- {
559
- name: "sort",
560
- category: "array",
561
- compatibility: ["browser", "nodejs"],
562
- fn: sort
563
- },
564
- {
565
- name: "sortBy",
566
- category: "array",
567
- compatibility: ["browser", "nodejs"],
568
- fn: sortBy
569
- },
570
- {
571
- name: "unique",
572
- category: "array",
573
- compatibility: ["browser", "nodejs"],
574
- fn: unique
575
- }
576
- ];
577
-
578
- // src/helpers/code.ts
579
- import fs from "fs";
580
- import path from "path";
581
- import tag from "html-tag";
582
- import codeBlock from "to-gfm-code-block";
583
- var embed = (filepath, language) => {
584
- let ext = typeof language === "string" ? language : path.extname(filepath).slice(1);
585
- let code = fs.readFileSync(filepath, "utf8");
586
- if (ext === "markdown" || ext === "md") {
587
- ext = "markdown";
588
- code = code.split("`").join("&#x60");
589
- }
590
- return `${codeBlock(code, ext).trim()}
591
- `;
592
- };
593
- var gist = (id) => {
594
- return tag("script", { src: `https://gist.github.com/${id}.js` });
595
- };
596
- var jsfiddle = (options2) => {
597
- if (!options2 || !options2.id) {
598
- throw new Error("jsfiddle helper expects an `id`");
599
- }
600
- const {
601
- id,
602
- width = "100%",
603
- height = "300",
604
- skin = "/presentation/",
605
- tabs = "result,js,html,css",
606
- allowfullscreen = "allowfullscreen",
607
- frameborder = "0"
608
- } = options2;
609
- const src = `http://jsfiddle.net/${id}/embedded/${tabs}${skin}`;
610
- return tag("iframe", { width, height, src, allowfullscreen, frameborder });
611
- };
612
- var helpers2 = [
613
- {
614
- name: "embed",
615
- category: "code",
616
- compatibility: ["nodejs"],
617
- fn: embed
618
- },
619
- {
620
- name: "gist",
621
- category: "code",
622
- compatibility: ["browser", "nodejs"],
623
- fn: gist
624
- },
625
- {
626
- name: "jsfiddle",
627
- category: "code",
628
- compatibility: ["browser", "nodejs"],
629
- fn: jsfiddle
630
- }
631
- ];
632
-
633
- // src/helpers/collection.ts
634
- var isEmpty = (collection) => {
635
- if (collection == null) return true;
636
- if (Array.isArray(collection)) return collection.length === 0;
637
- if (typeof collection === "object")
638
- return Object.keys(collection).length === 0;
639
- return false;
640
- };
641
- var iterate = (collection, fn, inverse) => {
642
- if (Array.isArray(collection)) {
643
- let result = "";
644
- for (let i = 0; i < collection.length; i++) {
645
- result += fn(collection[i], i);
646
- }
647
- return result;
648
- }
649
- if (collection && typeof collection === "object") {
650
- let result = "";
651
- for (const key of Object.keys(collection)) {
652
- result += fn(collection[key], key);
653
- }
654
- return result;
655
- }
656
- return inverse ? inverse() : "";
657
- };
658
- var helpers3 = [
659
- {
660
- name: "isEmpty",
661
- category: "collection",
662
- compatibility: ["browser", "nodejs"],
663
- fn: isEmpty
664
- },
665
- {
666
- name: "iterate",
667
- category: "collection",
668
- compatibility: ["browser", "nodejs"],
669
- fn: iterate
670
- }
671
- ];
672
-
673
- // src/helpers/comparison.ts
674
- var and = (...values) => values.every(Boolean);
675
- var compare = (a, operator, b) => {
676
- switch (operator) {
677
- case "==":
678
- return a == b;
679
- case "===":
680
- return a === b;
681
- case "!=":
682
- return a != b;
683
- case "!==":
684
- return a !== b;
685
- case "<":
686
- return a < b;
687
- case ">":
688
- return a > b;
689
- case "<=":
690
- return a <= b;
691
- case ">=":
692
- return a >= b;
693
- case "typeof":
694
- return typeof a === b;
695
- default:
696
- throw new Error(`helper {{compare}}: invalid operator: '${operator}'`);
697
- }
698
- };
699
- var contains = (collection, value, startIndex = 0) => {
700
- if (collection == null) return false;
701
- if (typeof collection === "string" || Array.isArray(collection)) {
702
- return collection.indexOf(value, startIndex) > -1;
703
- }
704
- if (typeof collection === "object") {
705
- return value in collection;
706
- }
707
- return false;
708
- };
709
- var defaultHelper = (...values) => {
710
- for (const val of values) {
711
- if (val != null) return val;
712
- }
713
- return "";
714
- };
715
- var eq = (a, b) => a === b;
716
- var gt = (a, b) => a > b;
717
- var gte = (a, b) => a >= b;
718
- var has = (value, pattern) => {
719
- if (value == null || pattern == null) return false;
720
- if (Array.isArray(value) || typeof value === "string") {
721
- return value.indexOf(pattern) > -1;
722
- }
723
- if (typeof value === "object") {
724
- return pattern in value;
725
- }
726
- return false;
727
- };
728
- var falsey = (val, keywords) => {
729
- if (!val) return true;
730
- const words = Array.isArray(keywords) ? keywords : keywords != null ? [keywords] : [
731
- "0",
732
- "false",
733
- "nada",
734
- "nil",
735
- "nay",
736
- "nah",
737
- "negative",
738
- "no",
739
- "none",
740
- "nope",
741
- "nul",
742
- "null",
743
- "nix",
744
- "nyet",
745
- "uh-uh",
746
- "veto",
747
- "zero"
748
- ];
749
- const lower = typeof val === "string" ? val.toLowerCase() : null;
750
- for (const word of words) {
751
- if (word === val) return true;
752
- if (lower != null && word === lower) return true;
753
- }
754
- return false;
755
- };
756
- var isFalsey = (val) => falsey(val);
757
- var isTruthy = (val) => !falsey(val);
758
- var ifEven = (num) => typeof num === "number" && num % 2 === 0;
759
- var ifNth = (a, b) => typeof a === "number" && typeof b === "number" && b % a === 0;
760
- var ifOdd = (val) => typeof val === "number" && Math.abs(val % 2) === 1;
761
- var is = (a, b) => a == b;
762
- var isnt = (a, b) => a != b;
763
- var lt = (a, b) => a < b;
764
- var lte = (a, b) => a <= b;
765
- var neither = (a, b) => !a && !b;
766
- var not = (val) => !val;
767
- var or = (...values) => values.some(Boolean);
768
- var unlessEq = (a, b) => a !== b;
769
- var unlessGt = (a, b) => a <= b;
770
- var unlessLt = (a, b) => a >= b;
771
- var unlessGteq = (a, b) => a < b;
772
- var unlessLteq = (a, b) => a > b;
773
- var helpers4 = [
774
- {
775
- name: "and",
776
- category: "comparison",
777
- compatibility: ["browser", "nodejs"],
778
- fn: and
779
- },
780
- {
781
- name: "compare",
782
- category: "comparison",
783
- compatibility: ["browser", "nodejs"],
784
- fn: compare
785
- },
786
- {
787
- name: "contains",
788
- category: "comparison",
789
- compatibility: ["browser", "nodejs"],
790
- fn: contains
791
- },
792
- {
793
- name: "default",
794
- category: "comparison",
795
- compatibility: ["browser", "nodejs"],
796
- fn: defaultHelper
797
- },
798
- {
799
- name: "eq",
800
- category: "comparison",
801
- compatibility: ["browser", "nodejs"],
802
- fn: eq
803
- },
804
- {
805
- name: "gt",
806
- category: "comparison",
807
- compatibility: ["browser", "nodejs"],
808
- fn: gt
809
- },
810
- {
811
- name: "gte",
812
- category: "comparison",
813
- compatibility: ["browser", "nodejs"],
814
- fn: gte
815
- },
816
- {
817
- name: "has",
818
- category: "comparison",
819
- compatibility: ["browser", "nodejs"],
820
- fn: has
821
- },
822
- {
823
- name: "isFalsey",
824
- category: "comparison",
825
- compatibility: ["browser", "nodejs"],
826
- fn: isFalsey
827
- },
828
- {
829
- name: "isTruthy",
830
- category: "comparison",
831
- compatibility: ["browser", "nodejs"],
832
- fn: isTruthy
833
- },
834
- {
835
- name: "ifEven",
836
- category: "comparison",
837
- compatibility: ["browser", "nodejs"],
838
- fn: ifEven
839
- },
840
- {
841
- name: "ifNth",
842
- category: "comparison",
843
- compatibility: ["browser", "nodejs"],
844
- fn: ifNth
845
- },
846
- {
847
- name: "ifOdd",
848
- category: "comparison",
849
- compatibility: ["browser", "nodejs"],
850
- fn: ifOdd
851
- },
852
- {
853
- name: "is",
854
- category: "comparison",
855
- compatibility: ["browser", "nodejs"],
856
- fn: is
857
- },
858
- {
859
- name: "isnt",
860
- category: "comparison",
861
- compatibility: ["browser", "nodejs"],
862
- fn: isnt
863
- },
864
- {
865
- name: "lt",
866
- category: "comparison",
867
- compatibility: ["browser", "nodejs"],
868
- fn: lt
869
- },
870
- {
871
- name: "lte",
872
- category: "comparison",
873
- compatibility: ["browser", "nodejs"],
874
- fn: lte
875
- },
876
- {
877
- name: "neither",
878
- category: "comparison",
879
- compatibility: ["browser", "nodejs"],
880
- fn: neither
881
- },
882
- {
883
- name: "not",
884
- category: "comparison",
885
- compatibility: ["browser", "nodejs"],
886
- fn: not
887
- },
888
- {
889
- name: "or",
890
- category: "comparison",
891
- compatibility: ["browser", "nodejs"],
892
- fn: or
893
- },
894
- {
895
- name: "unlessEq",
896
- category: "comparison",
897
- compatibility: ["browser", "nodejs"],
898
- fn: unlessEq
899
- },
900
- {
901
- name: "unlessGt",
902
- category: "comparison",
903
- compatibility: ["browser", "nodejs"],
904
- fn: unlessGt
905
- },
906
- {
907
- name: "unlessLt",
908
- category: "comparison",
909
- compatibility: ["browser", "nodejs"],
910
- fn: unlessLt
911
- },
912
- {
913
- name: "unlessGteq",
914
- category: "comparison",
915
- compatibility: ["browser", "nodejs"],
916
- fn: unlessGteq
917
- },
918
- {
919
- name: "unlessLteq",
920
- category: "comparison",
921
- compatibility: ["browser", "nodejs"],
922
- fn: unlessLteq
923
- }
924
- ];
925
-
926
- // src/helpers/date.ts
927
- import { parseDate } from "chrono-node";
928
- import dayjs from "dayjs";
929
- import isBetween from "dayjs/plugin/isBetween.js";
930
- import relativeTime from "dayjs/plugin/relativeTime.js";
931
- import timezone from "dayjs/plugin/timezone.js";
932
- import utc from "dayjs/plugin/utc.js";
933
- dayjs.extend(relativeTime);
934
- dayjs.extend(isBetween);
935
- dayjs.extend(utc);
936
- dayjs.extend(timezone);
937
- var parseDateInput = (input) => {
938
- if (!input) {
939
- return dayjs();
940
- }
941
- if (typeof input === "string") {
942
- const parsed = parseDate(input);
943
- if (parsed) {
944
- return dayjs(parsed);
945
- }
946
- return dayjs(input);
947
- }
948
- return dayjs(input);
949
- };
950
- var year = () => (/* @__PURE__ */ new Date()).getFullYear().toString();
951
- var convertFormatString = (format2) => {
952
- return format2.replace(/yyyy/g, "YYYY").replace(/yy/g, "YY").replace(/dd/g, "DD").replace(/mm/g, "MM").replace(/hh/g, "HH");
953
- };
954
- var date = (humanReadableDate, formatString) => {
955
- const defaultFormat = "YYYY-MM-DD";
956
- const format2 = formatString || defaultFormat;
957
- const parsedDate = parseDateInput(humanReadableDate);
958
- if (!parsedDate.isValid()) {
959
- throw new Error(`Unable to parse date: ${humanReadableDate}`);
960
- }
961
- const convertedFormat = convertFormatString(format2);
962
- return parsedDate.format(convertedFormat);
963
- };
964
- var timestamp = () => {
965
- return Date.now().toString();
966
- };
967
- var now = (formatString) => {
968
- const defaultFormat = "YYYY-MM-DD HH:mm:ss";
969
- const format2 = formatString || defaultFormat;
970
- const convertedFormat = convertFormatString(format2);
971
- return dayjs().format(convertedFormat);
972
- };
973
- var fromNow = (dateInput) => {
974
- const parsed = parseDateInput(dateInput);
975
- if (!parsed.isValid()) {
976
- throw new Error(`Unable to parse date: ${dateInput}`);
977
- }
978
- return parsed.fromNow();
979
- };
980
- var toNow = (dateInput) => {
981
- const parsed = parseDateInput(dateInput);
982
- if (!parsed.isValid()) {
983
- throw new Error(`Unable to parse date: ${dateInput}`);
984
- }
985
- return parsed.toNow();
986
- };
987
- var ago = (dateInput) => {
988
- return fromNow(dateInput);
989
- };
990
- var dateAdd = (dateInput, amount, unit) => {
991
- const parsed = parseDateInput(dateInput);
992
- if (!parsed.isValid()) {
993
- throw new Error(`Unable to parse date: ${dateInput}`);
994
- }
995
- return parsed.add(amount, unit).format("YYYY-MM-DD HH:mm:ss");
996
- };
997
- var dateSubtract = (dateInput, amount, unit) => {
998
- const parsed = parseDateInput(dateInput);
999
- if (!parsed.isValid()) {
1000
- throw new Error(`Unable to parse date: ${dateInput}`);
1001
- }
1002
- return parsed.subtract(amount, unit).format("YYYY-MM-DD HH:mm:ss");
1003
- };
1004
- var startOf = (dateInput, unit) => {
1005
- const parsed = parseDateInput(dateInput);
1006
- if (!parsed.isValid()) {
1007
- throw new Error(`Unable to parse date: ${dateInput}`);
1008
- }
1009
- return parsed.startOf(unit).format("YYYY-MM-DD HH:mm:ss");
1010
- };
1011
- var endOf = (dateInput, unit) => {
1012
- const parsed = parseDateInput(dateInput);
1013
- if (!parsed.isValid()) {
1014
- throw new Error(`Unable to parse date: ${dateInput}`);
1015
- }
1016
- return parsed.endOf(unit).format("YYYY-MM-DD HH:mm:ss");
1017
- };
1018
- var isBefore = (date1, date2) => {
1019
- const parsed1 = parseDateInput(date1);
1020
- const parsed2 = parseDateInput(date2);
1021
- if (!parsed1.isValid() || !parsed2.isValid()) {
1022
- throw new Error(`Unable to parse dates: ${date1}, ${date2}`);
1023
- }
1024
- return parsed1.isBefore(parsed2);
1025
- };
1026
- var isAfter = (date1, date2) => {
1027
- const parsed1 = parseDateInput(date1);
1028
- const parsed2 = parseDateInput(date2);
1029
- if (!parsed1.isValid() || !parsed2.isValid()) {
1030
- throw new Error(`Unable to parse dates: ${date1}, ${date2}`);
1031
- }
1032
- return parsed1.isAfter(parsed2);
1033
- };
1034
- var isSame = (date1, date2, unit) => {
1035
- const parsed1 = parseDateInput(date1);
1036
- const parsed2 = parseDateInput(date2);
1037
- if (!parsed1.isValid() || !parsed2.isValid()) {
1038
- throw new Error(`Unable to parse dates: ${date1}, ${date2}`);
1039
- }
1040
- return parsed1.isSame(parsed2, unit);
1041
- };
1042
- var isBetweenDates = (dateInput, startDate, endDate) => {
1043
- const parsed = parseDateInput(dateInput);
1044
- const parsedStart = parseDateInput(startDate);
1045
- const parsedEnd = parseDateInput(endDate);
1046
- if (!parsed.isValid() || !parsedStart.isValid() || !parsedEnd.isValid()) {
1047
- throw new Error(
1048
- `Unable to parse dates: ${dateInput}, ${startDate}, ${endDate}`
1049
- );
1050
- }
1051
- return parsed.isBetween(parsedStart, parsedEnd, null, "[]");
1052
- };
1053
- var diff = (date1, date2, unit) => {
1054
- const parsed1 = parseDateInput(date1);
1055
- const parsed2 = parseDateInput(date2);
1056
- if (!parsed1.isValid() || !parsed2.isValid()) {
1057
- throw new Error(`Unable to parse dates: ${date1}, ${date2}`);
1058
- }
1059
- return parsed1.diff(parsed2, unit);
1060
- };
1061
- var toISOString = (dateInput) => {
1062
- const parsed = parseDateInput(dateInput);
1063
- if (!parsed.isValid()) {
1064
- throw new Error(`Unable to parse date: ${dateInput}`);
1065
- }
1066
- return parsed.toISOString();
1067
- };
1068
- var dateTimezone = (dateInput, timezoneStr, formatString) => {
1069
- const defaultFormat = "YYYY-MM-DD HH:mm:ss";
1070
- const format2 = formatString || defaultFormat;
1071
- const convertedFormat = convertFormatString(format2);
1072
- const parsed = parseDateInput(dateInput);
1073
- if (!parsed.isValid()) {
1074
- throw new Error(`Unable to parse date: ${dateInput}`);
1075
- }
1076
- return parsed.tz(timezoneStr).format(convertedFormat);
1077
- };
1078
- var dateLocale = (dateInput, locale, formatString) => {
1079
- const defaultFormat = "YYYY-MM-DD HH:mm:ss";
1080
- const format2 = formatString || defaultFormat;
1081
- const convertedFormat = convertFormatString(format2);
1082
- const parsed = parseDateInput(dateInput);
1083
- if (!parsed.isValid()) {
1084
- throw new Error(`Unable to parse date: ${dateInput}`);
1085
- }
1086
- return parsed.locale(locale).format(convertedFormat);
1087
- };
1088
- var helpers5 = [
1089
- {
1090
- name: "year",
1091
- category: "date",
1092
- compatibility: ["browser", "nodejs"],
1093
- fn: year
1094
- },
1095
- {
1096
- name: "date",
1097
- category: "date",
1098
- compatibility: ["browser", "nodejs"],
1099
- fn: date
1100
- },
1101
- {
1102
- /* Adding this in for legacy support */
1103
- name: "moment",
1104
- category: "date",
1105
- compatibility: ["browser", "nodejs"],
1106
- fn: date
1107
- },
1108
- {
1109
- name: "timestamp",
1110
- category: "date",
1111
- compatibility: ["browser", "nodejs"],
1112
- fn: timestamp
1113
- },
1114
- {
1115
- name: "now",
1116
- category: "date",
1117
- compatibility: ["browser", "nodejs"],
1118
- fn: now
1119
- },
1120
- {
1121
- name: "fromNow",
1122
- category: "date",
1123
- compatibility: ["browser", "nodejs"],
1124
- fn: fromNow
1125
- },
1126
- {
1127
- name: "toNow",
1128
- category: "date",
1129
- compatibility: ["browser", "nodejs"],
1130
- fn: toNow
1131
- },
1132
- {
1133
- name: "ago",
1134
- category: "date",
1135
- compatibility: ["browser", "nodejs"],
1136
- fn: ago
1137
- },
1138
- {
1139
- name: "dateAdd",
1140
- category: "date",
1141
- compatibility: ["browser", "nodejs"],
1142
- fn: dateAdd
1143
- },
1144
- {
1145
- name: "dateSubtract",
1146
- category: "date",
1147
- compatibility: ["browser", "nodejs"],
1148
- fn: dateSubtract
1149
- },
1150
- {
1151
- name: "startOf",
1152
- category: "date",
1153
- compatibility: ["browser", "nodejs"],
1154
- fn: startOf
1155
- },
1156
- {
1157
- name: "endOf",
1158
- category: "date",
1159
- compatibility: ["browser", "nodejs"],
1160
- fn: endOf
1161
- },
1162
- {
1163
- name: "isBefore",
1164
- category: "date",
1165
- compatibility: ["browser", "nodejs"],
1166
- fn: isBefore
1167
- },
1168
- {
1169
- name: "isAfter",
1170
- category: "date",
1171
- compatibility: ["browser", "nodejs"],
1172
- fn: isAfter
1173
- },
1174
- {
1175
- name: "isSame",
1176
- category: "date",
1177
- compatibility: ["browser", "nodejs"],
1178
- fn: isSame
1179
- },
1180
- {
1181
- name: "isBetween",
1182
- category: "date",
1183
- compatibility: ["browser", "nodejs"],
1184
- fn: isBetweenDates
1185
- },
1186
- {
1187
- name: "diff",
1188
- category: "date",
1189
- compatibility: ["browser", "nodejs"],
1190
- fn: diff
1191
- },
1192
- {
1193
- name: "toISOString",
1194
- category: "date",
1195
- compatibility: ["browser", "nodejs"],
1196
- fn: toISOString
1197
- },
1198
- {
1199
- name: "dateTimezone",
1200
- category: "date",
1201
- compatibility: ["browser", "nodejs"],
1202
- fn: dateTimezone
1203
- },
1204
- {
1205
- name: "dateLocale",
1206
- category: "date",
1207
- compatibility: ["browser", "nodejs"],
1208
- fn: dateLocale
1209
- }
1210
- ];
1211
-
1212
- // src/helpers/fs.ts
1213
- import fs2 from "fs";
1214
- import path2 from "path";
1215
- import isGlob from "is-glob";
1216
- import micromatch from "micromatch";
1217
- var fileSize = (value, precision) => {
1218
- if (value == null) return "0 B";
1219
- const number = typeof value === "number" ? value : value.length ?? 0;
1220
- if (!number) return "0 B";
1221
- const precisionNumber = typeof precision === "number" ? precision : 2;
1222
- const abbr = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
1223
- const factor = 10 ** precisionNumber;
1224
- let i = abbr.length - 1;
1225
- do {
1226
- const size = 10 ** (i * 3);
1227
- if (size <= number + 1) {
1228
- const num = Math.round(number * factor / size) / factor;
1229
- return `${num} ${abbr[i]}`;
1230
- }
1231
- } while (--i >= 0);
1232
- return `${number} B`;
1233
- };
1234
- var read = (filepath) => {
1235
- return fs2.readFileSync(filepath, "utf8");
1236
- };
1237
- var isOptions = (value) => {
1238
- return Boolean(
1239
- value && typeof value === "object" && "hash" in value
1240
- );
1241
- };
1242
- var readdir = (dir, filter2) => {
1243
- const files = fs2.readdirSync(dir).map((fp) => path2.join(dir, fp));
1244
- const filterArg = isOptions(filter2) ? void 0 : filter2;
1245
- if (typeof filterArg === "function") {
1246
- return filterArg(files);
1247
- }
1248
- if (filterArg instanceof RegExp) {
1249
- return files.filter((fp) => filterArg.test(fp));
1250
- }
1251
- if (typeof filterArg === "string") {
1252
- if (isGlob(filterArg)) {
1253
- return micromatch(files, filterArg);
1254
- }
1255
- if (filterArg === "isFile" || filterArg === "isDirectory") {
1256
- return files.filter((fp) => {
1257
- const stat = fs2.statSync(fp);
1258
- return filterArg === "isFile" ? stat.isFile() : stat.isDirectory();
1259
- });
1260
- }
1261
- }
1262
- return files;
1263
- };
1264
- var helpers6 = [
1265
- {
1266
- name: "fileSize",
1267
- category: "fs",
1268
- compatibility: ["nodejs"],
1269
- fn: fileSize
1270
- },
1271
- {
1272
- name: "read",
1273
- category: "fs",
1274
- compatibility: ["nodejs"],
1275
- fn: read
1276
- },
1277
- {
1278
- name: "readdir",
1279
- category: "fs",
1280
- compatibility: ["nodejs"],
1281
- fn: readdir
1282
- }
1283
- ];
1284
-
1285
- // src/helpers/html.ts
1286
- import path3 from "path";
1287
- import tag2 from "html-tag";
1288
- import striptags from "striptags";
1289
- var parseAttributes = (hash = {}) => Object.keys(hash).map((key) => `${key}="${String(hash[key]).replace(/^['"]|["']$/g, "")}"`).join(" ");
1290
- var attr = (options2) => {
1291
- const val = parseAttributes(options2?.hash ?? {});
1292
- return val.trim() ? ` ${val}` : "";
1293
- };
1294
- var css = function(list, options2) {
1295
- if (arguments.length < 2) {
1296
- options2 = list;
1297
- list = [];
1298
- }
1299
- let styles = arrayify(list ?? []);
1300
- let assets = "";
1301
- if (this && this.options) {
1302
- assets = this.options.assets || "";
1303
- }
1304
- if (options2?.hash?.href) {
1305
- styles = arrayify(options2.hash.href);
1306
- }
1307
- return styles.map((item) => {
1308
- const ext = path3.extname(item);
1309
- let fp = item;
1310
- if (!/(^\/\/)|(:\/\/)/.test(item)) {
1311
- fp = path3.posix.join(assets, item);
1312
- }
1313
- if (ext === ".less") {
1314
- return `<link type="text/css" rel="stylesheet/less" href="${fp}">`;
1315
- }
1316
- return `<link type="text/css" rel="stylesheet" href="${fp}">`;
1317
- }).join("\n");
1318
- };
1319
- var js = (context) => {
1320
- if (context && typeof context === "object" && !Array.isArray(context)) {
1321
- const attrStr = parseAttributes(context.hash ?? {});
1322
- return `<script${attrStr ? ` ${attrStr}` : ""}></script>`;
1323
- }
1324
- if (typeof context === "string") {
1325
- return `<script src="${context}"></script>`;
1326
- }
1327
- const items = arrayify(context);
1328
- return items.map(
1329
- (fp) => path3.extname(fp) === ".coffee" ? tag2("script", { type: "text/coffeescript", src: fp }) : tag2("script", { src: fp })
1330
- ).join("\n");
1331
- };
1332
- var sanitize = (str) => {
1333
- if (typeof str !== "string") return "";
1334
- return striptags(str).trim();
1335
- };
1336
- var ul = (context, options2) => {
1337
- const attrs = parseAttributes(options2.hash ?? {});
1338
- const items = context.map(
1339
- (item) => typeof item === "string" ? item : options2.fn(item)
1340
- );
1341
- const open = attrs ? `<ul ${attrs}>` : "<ul>";
1342
- return `${open}${items.map((i) => `<li>${i}</li>`).join("\n")}</ul>`;
1343
- };
1344
- var ol = (context, options2) => {
1345
- const attrs = parseAttributes(options2.hash ?? {});
1346
- const items = context.map(
1347
- (item) => typeof item === "string" ? item : options2.fn(item)
1348
- );
1349
- const open = attrs ? `<ol ${attrs}>` : "<ol>";
1350
- return `${open}${items.map((i) => `<li>${i}</li>`).join("\n")}</ol>`;
1351
- };
1352
- var thumbnailImage = (context) => {
1353
- let figure = "";
1354
- let image = "";
1355
- const link = context.full || false;
1356
- const imageAttributes = {
1357
- alt: context.alt,
1358
- src: context.thumbnail,
1359
- width: context.size.width,
1360
- height: context.size.height
1361
- };
1362
- const figureAttributes = { id: `image-${context.id}` };
1363
- const linkAttributes = { href: link, rel: "thumbnail" };
1364
- if (context.classes) {
1365
- if (context.classes.image) {
1366
- imageAttributes.class = context.classes.image.join(" ");
1367
- }
1368
- if (context.classes.figure) {
1369
- figureAttributes.class = context.classes.figure.join(" ");
1370
- }
1371
- if (context.classes.link) {
1372
- linkAttributes.class = context.classes.link.join(" ");
1373
- }
1374
- }
1375
- figure += `<figure ${parseAttributes(figureAttributes)}>
1376
- `;
1377
- image += `<img ${parseAttributes(imageAttributes)}>
1378
- `;
1379
- if (link) {
1380
- figure += `<a ${parseAttributes(linkAttributes)}>
1381
- ${image}</a>
1382
- `;
1383
- } else {
1384
- figure += image;
1385
- }
1386
- if (context.caption) {
1387
- figure += `<figcaption>${context.caption}</figcaption>
1388
- `;
1389
- }
1390
- figure += "</figure>";
1391
- return figure;
1392
- };
1393
- var helpers7 = [
1394
- {
1395
- name: "attr",
1396
- category: "html",
1397
- compatibility: ["browser", "nodejs"],
1398
- fn: attr
1399
- },
1400
- {
1401
- name: "css",
1402
- category: "html",
1403
- compatibility: ["nodejs"],
1404
- fn: css
1405
- },
1406
- {
1407
- name: "js",
1408
- category: "html",
1409
- compatibility: ["nodejs"],
1410
- fn: js
1411
- },
1412
- {
1413
- name: "sanitize",
1414
- category: "html",
1415
- compatibility: ["browser", "nodejs"],
1416
- fn: sanitize
1417
- },
1418
- {
1419
- name: "ul",
1420
- category: "html",
1421
- compatibility: ["browser", "nodejs"],
1422
- fn: ul
1423
- },
1424
- {
1425
- name: "ol",
1426
- category: "html",
1427
- compatibility: ["browser", "nodejs"],
1428
- fn: ol
1429
- },
1430
- {
1431
- name: "thumbnailImage",
1432
- category: "html",
1433
- compatibility: ["browser", "nodejs"],
1434
- fn: thumbnailImage
1435
- }
1436
- ];
1437
-
1438
- // src/utils.ts
1439
- var get = (object, path6) => {
1440
- if (!object || typeof object !== "object") return void 0;
1441
- const keys = Array.isArray(path6) ? path6 : path6.split(".");
1442
- let result = object;
1443
- for (const key of keys) {
1444
- if (result == null || typeof result !== "object") return void 0;
1445
- result = result[key];
1446
- }
1447
- return result;
1448
- };
1449
- var getObject = (object, path6) => {
1450
- if (!object || typeof object !== "object") return void 0;
1451
- const keys = Array.isArray(path6) ? path6 : path6.split(".");
1452
- if (keys.length === 0) return void 0;
1453
- let current = object;
1454
- for (let i = 0; i < keys.length - 1; i++) {
1455
- if (current == null || typeof current !== "object") return void 0;
1456
- current = current[keys[i]];
1457
- }
1458
- const finalKey = keys[keys.length - 1];
1459
- if (current == null || typeof current !== "object" || !(finalKey in current)) {
1460
- return void 0;
1461
- }
1462
- return { [finalKey]: current[finalKey] };
1463
- };
1464
- var options = (thisArg, locals, opts) => {
1465
- const result = {};
1466
- if (thisArg && typeof thisArg === "object" && thisArg.options) {
1467
- Object.assign(result, thisArg.options);
1468
- }
1469
- if (locals && typeof locals === "object") {
1470
- if ("hash" in locals) {
1471
- Object.assign(result, locals.hash);
1472
- } else {
1473
- Object.assign(result, locals);
1474
- }
1475
- }
1476
- if (opts && typeof opts === "object") {
1477
- if ("hash" in opts) {
1478
- Object.assign(result, opts.hash);
1479
- } else {
1480
- Object.assign(result, opts);
1481
- }
1482
- }
1483
- return result;
1484
- };
1485
-
1486
- // src/helpers/i18n.ts
1487
- var i18n = function(prop, locals, options2) {
1488
- if (locals && typeof locals === "object" && "hash" in locals && options2 === void 0) {
1489
- options2 = locals;
1490
- locals = {};
1491
- }
1492
- if (typeof prop !== "string") {
1493
- throw new Error('{{i18n}} helper expected "key" to be a string');
1494
- }
1495
- const context = {
1496
- ...this,
1497
- ...locals,
1498
- ...options2?.hash ?? {}
1499
- };
1500
- const lang = context.language || context.lang;
1501
- if (typeof lang !== "string") {
1502
- throw new TypeError('{{i18n}} helper expected "language" to be a string');
1503
- }
1504
- const cache = context[lang];
1505
- if (typeof cache === "undefined") {
1506
- throw new Error(`{{i18n}} helper cannot find language "${lang}"`);
1507
- }
1508
- const result = get(cache, prop);
1509
- if (typeof result === "undefined") {
1510
- throw new Error(
1511
- '{{i18n}} helper cannot find property "' + String(prop) + '" for language "' + lang + '"'
1512
- );
1513
- }
1514
- return String(result);
1515
- };
1516
- var helpers8 = [
1517
- {
1518
- name: "i18n",
1519
- category: "i18n",
1520
- compatibility: ["browser", "nodejs"],
1521
- fn: i18n
1522
- }
1523
- ];
1524
-
1525
- // src/helpers/inflection.ts
1526
- var inflect = (count, singular, plural, includeCount) => {
1527
- const word = count > 1 || count === 0 ? plural : singular;
1528
- return includeCount ? `${count} ${word}` : word;
1529
- };
1530
- var ordinalize = (value) => {
1531
- const num = Math.abs(Math.round(Number(value)));
1532
- const str = String(value);
1533
- const res = num % 100;
1534
- if ([11, 12, 13].includes(res)) {
1535
- return `${str}th`;
1536
- }
1537
- switch (num % 10) {
1538
- case 1:
1539
- return `${str}st`;
1540
- case 2:
1541
- return `${str}nd`;
1542
- case 3:
1543
- return `${str}rd`;
1544
- default:
1545
- return `${str}th`;
1546
- }
1547
- };
1548
- var helpers9 = [
1549
- {
1550
- name: "inflect",
1551
- category: "inflection",
1552
- compatibility: ["browser", "nodejs"],
1553
- fn: inflect
1554
- },
1555
- {
1556
- name: "ordinalize",
1557
- category: "inflection",
1558
- compatibility: ["browser", "nodejs"],
1559
- fn: ordinalize
1560
- }
1561
- ];
1562
-
1563
- // src/helpers/logging.ts
1564
- var colors = {
1565
- green: (str) => `\x1B[32m${str}\x1B[0m`,
1566
- cyan: (str) => `\x1B[36m${str}\x1B[0m`,
1567
- yellow: (str) => `\x1B[33m${str}\x1B[0m`,
1568
- red: (str) => `\x1B[31m${str}\x1B[0m`,
1569
- bold: (str) => `\x1B[1m${str}\x1B[0m`
1570
- };
1571
- function cleanArgs(args) {
1572
- const last2 = args[args.length - 1];
1573
- if (args.length > 1 && typeof last2 === "object" && last2 !== null && "hash" in last2) {
1574
- return args.slice(0, -1);
1575
- }
1576
- return args;
1577
- }
1578
- function log(...args) {
1579
- const cleanedArgs = cleanArgs(args);
1580
- console.log(...cleanedArgs);
1581
- return "";
1582
- }
1583
- function ok(...args) {
1584
- const cleanedArgs = cleanArgs(args);
1585
- const message = cleanedArgs.join(" ");
1586
- console.log(colors.green(`\u2713 ${message}`));
1587
- return "";
1588
- }
1589
- function success(...args) {
1590
- const cleanedArgs = cleanArgs(args);
1591
- const message = cleanedArgs.map((arg) => String(arg)).join(" ");
1592
- console.log(colors.green(message));
1593
- return "";
1594
- }
1595
- function info(...args) {
1596
- const cleanedArgs = cleanArgs(args);
1597
- const message = cleanedArgs.map((arg) => String(arg)).join(" ");
1598
- console.log(colors.cyan(message));
1599
- return "";
1600
- }
1601
- function warning(...args) {
1602
- const cleanedArgs = cleanArgs(args);
1603
- const message = cleanedArgs.map((arg) => String(arg)).join(" ");
1604
- console.error(colors.yellow(message));
1605
- return "";
1606
- }
1607
- var warn = warning;
1608
- function error(...args) {
1609
- const cleanedArgs = cleanArgs(args);
1610
- const message = cleanedArgs.map((arg) => String(arg)).join(" ");
1611
- console.error(colors.red(message));
1612
- return "";
1613
- }
1614
- var danger = error;
1615
- function bold(...args) {
1616
- const cleanedArgs = cleanArgs(args);
1617
- const message = cleanedArgs.map((arg) => String(arg)).join(" ");
1618
- console.error(colors.bold(message));
1619
- return "";
1620
- }
1621
- function _debug(...args) {
1622
- const separator = "\u2500".repeat(50);
1623
- console.error(colors.cyan(separator));
1624
- if (args.length > 0) {
1625
- const cleanedArgs = cleanArgs(args);
1626
- console.error(colors.cyan("VALUE:"), cleanedArgs[0]);
1627
- }
1628
- if (this && Object.keys(this).length > 0) {
1629
- console.error(colors.cyan("CONTEXT:"), this);
1630
- }
1631
- console.error(colors.cyan(separator));
1632
- return "";
1633
- }
1634
- function _inspect(context, options2) {
1635
- const val = JSON.stringify(context, null, 2);
1636
- const type = options2?.hash?.type || "html";
1637
- return switchOutput(type, val);
1638
- }
1639
- function switchOutput(type, json) {
1640
- if (type[0] === ".") {
1641
- type = type.slice(1);
1642
- }
1643
- switch (type) {
1644
- case "md":
1645
- return `
1646
- \`\`\`json
1647
- ${json}
1648
- \`\`\`
1649
- `;
1650
- case "html":
1651
- return `<div class="highlight highlight-json">
1652
- <pre><code>
1653
- ${json}</code></pre></div>`;
1654
- default:
1655
- return json;
1656
- }
1657
- }
1658
- var helpers10 = [
1659
- {
1660
- name: "log",
1661
- category: "logging",
1662
- compatibility: ["nodejs"],
1663
- fn: log
1664
- },
1665
- {
1666
- name: "ok",
1667
- category: "logging",
1668
- compatibility: ["nodejs"],
1669
- fn: ok
1670
- },
1671
- {
1672
- name: "success",
1673
- category: "logging",
1674
- compatibility: ["nodejs"],
1675
- fn: success
1676
- },
1677
- {
1678
- name: "info",
1679
- category: "logging",
1680
- compatibility: ["nodejs"],
1681
- fn: info
1682
- },
1683
- {
1684
- name: "warning",
1685
- category: "logging",
1686
- compatibility: ["nodejs"],
1687
- fn: warning
1688
- },
1689
- {
1690
- name: "warn",
1691
- category: "logging",
1692
- compatibility: ["nodejs"],
1693
- fn: warn
1694
- },
1695
- {
1696
- name: "error",
1697
- category: "logging",
1698
- compatibility: ["nodejs"],
1699
- fn: error
1700
- },
1701
- {
1702
- name: "danger",
1703
- category: "logging",
1704
- compatibility: ["nodejs"],
1705
- fn: danger
1706
- },
1707
- {
1708
- name: "bold",
1709
- category: "logging",
1710
- compatibility: ["nodejs"],
1711
- fn: bold
1712
- },
1713
- {
1714
- name: "_debug",
1715
- category: "logging",
1716
- compatibility: ["nodejs"],
1717
- fn: _debug
1718
- },
1719
- {
1720
- name: "_inspect",
1721
- category: "logging",
1722
- compatibility: ["nodejs"],
1723
- fn: _inspect
1724
- }
1725
- ];
1726
-
1727
- // src/helpers/match.ts
1728
- import micromatch2 from "micromatch";
1729
- var match = (files, patterns, options2) => {
1730
- const pats = typeof patterns === "string" ? patterns.split(/, */) : patterns;
1731
- return micromatch2(files, pats, options2);
1732
- };
1733
- var isMatch = (filepath, pattern, options2) => {
1734
- return micromatch2.isMatch(filepath, pattern, options2);
1735
- };
1736
- var mm = (...args) => {
1737
- console.log("the {{mm}} helper is depcrecated and will be removed");
1738
- console.log("in handlebars-helpers v1.0.0, please use the {{match}}");
1739
- console.log("helper instead.");
1740
- return match(...args);
1741
- };
1742
- var helpers11 = [
1743
- {
1744
- name: "match",
1745
- category: "match",
1746
- compatibility: ["browser", "nodejs"],
1747
- fn: match
1748
- },
1749
- {
1750
- name: "isMatch",
1751
- category: "match",
1752
- compatibility: ["browser", "nodejs"],
1753
- fn: isMatch
1754
- },
1755
- {
1756
- name: "mm",
1757
- category: "match",
1758
- compatibility: ["browser", "nodejs"],
1759
- fn: mm
1760
- }
1761
- ];
1762
-
1763
- // src/helpers/math.ts
1764
- var isNumeric = (value) => typeof value === "number" && !Number.isNaN(value) || typeof value === "string" && value.trim() !== "" && !Number.isNaN(Number(value));
1765
- var toNumber = (value, message = "expected a number") => {
1766
- if (isNumeric(value)) {
1767
- return Number(value);
1768
- }
1769
- throw new TypeError(message);
1770
- };
1771
- var abs = (value) => {
1772
- const num = toNumber(value);
1773
- return Math.abs(num);
1774
- };
1775
- var add = (a, b) => {
1776
- if (isNumeric(a) && isNumeric(b)) {
1777
- return Number(a) + Number(b);
1778
- }
1779
- return "";
1780
- };
1781
- var avg = (...values) => {
1782
- const flat = values.flat().map((n) => Number(n));
1783
- return sum(flat) / flat.length;
1784
- };
1785
- var ceil = (value) => {
1786
- const num = toNumber(value);
1787
- return Math.ceil(num);
1788
- };
1789
- var divide = (a, b) => {
1790
- const numA = toNumber(a, "expected the first argument to be a number");
1791
- const numB = toNumber(b, "expected the second argument to be a number");
1792
- return numA / numB;
1793
- };
1794
- var floor = (value) => {
1795
- const num = toNumber(value);
1796
- return Math.floor(num);
1797
- };
1798
- var minus = (a, b) => {
1799
- const numA = toNumber(a, "expected the first argument to be a number");
1800
- const numB = toNumber(b, "expected the second argument to be a number");
1801
- return numA - numB;
1802
- };
1803
- var modulo = (a, b) => {
1804
- const numA = toNumber(a, "expected the first argument to be a number");
1805
- const numB = toNumber(b, "expected the second argument to be a number");
1806
- return numA % numB;
1807
- };
1808
- var multiply = (a, b) => {
1809
- const numA = toNumber(a, "expected the first argument to be a number");
1810
- const numB = toNumber(b, "expected the second argument to be a number");
1811
- return numA * numB;
1812
- };
1813
- var plus = (a, b) => {
1814
- const numA = toNumber(a, "expected the first argument to be a number");
1815
- const numB = toNumber(b, "expected the second argument to be a number");
1816
- return numA + numB;
1817
- };
1818
- var random = (min, max) => {
1819
- const minNum = toNumber(min, "expected minimum to be a number");
1820
- const maxNum = toNumber(max, "expected maximum to be a number");
1821
- return minNum + Math.floor(Math.random() * (maxNum - minNum + 1));
1822
- };
1823
- var remainder = (a, b) => a % b;
1824
- var round = (value) => {
1825
- const num = toNumber(value);
1826
- return Math.round(num);
1827
- };
1828
- var subtract = (a, b) => {
1829
- const numA = toNumber(a, "expected the first argument to be a number");
1830
- const numB = toNumber(b, "expected the second argument to be a number");
1831
- return numA - numB;
1832
- };
1833
- var sum = (...values) => {
1834
- const flat = values.flat();
1835
- let total = 0;
1836
- for (const value of flat) {
1837
- if (isNumeric(value)) {
1838
- total += Number(value);
1839
- }
1840
- }
1841
- return total;
1842
- };
1843
- var times = (a, b) => multiply(a, b);
1844
- var helpers12 = [
1845
- {
1846
- name: "abs",
1847
- category: "math",
1848
- compatibility: ["browser", "nodejs"],
1849
- fn: abs
1850
- },
1851
- {
1852
- name: "add",
1853
- category: "math",
1854
- compatibility: ["browser", "nodejs"],
1855
- fn: add
1856
- },
1857
- {
1858
- name: "avg",
1859
- category: "math",
1860
- compatibility: ["browser", "nodejs"],
1861
- fn: avg
1862
- },
1863
- {
1864
- name: "ceil",
1865
- category: "math",
1866
- compatibility: ["browser", "nodejs"],
1867
- fn: ceil
1868
- },
1869
- {
1870
- name: "divide",
1871
- category: "math",
1872
- compatibility: ["browser", "nodejs"],
1873
- fn: divide
1874
- },
1875
- {
1876
- name: "floor",
1877
- category: "math",
1878
- compatibility: ["browser", "nodejs"],
1879
- fn: floor
1880
- },
1881
- {
1882
- name: "minus",
1883
- category: "math",
1884
- compatibility: ["browser", "nodejs"],
1885
- fn: minus
1886
- },
1887
- {
1888
- name: "modulo",
1889
- category: "math",
1890
- compatibility: ["browser", "nodejs"],
1891
- fn: modulo
1892
- },
1893
- {
1894
- name: "multiply",
1895
- category: "math",
1896
- compatibility: ["browser", "nodejs"],
1897
- fn: multiply
1898
- },
1899
- {
1900
- name: "plus",
1901
- category: "math",
1902
- compatibility: ["browser", "nodejs"],
1903
- fn: plus
1904
- },
1905
- {
1906
- name: "random",
1907
- category: "math",
1908
- compatibility: ["browser", "nodejs"],
1909
- fn: random
1910
- },
1911
- {
1912
- name: "remainder",
1913
- category: "math",
1914
- compatibility: ["browser", "nodejs"],
1915
- fn: remainder
1916
- },
1917
- {
1918
- name: "round",
1919
- category: "math",
1920
- compatibility: ["browser", "nodejs"],
1921
- fn: round
1922
- },
1923
- {
1924
- name: "subtract",
1925
- category: "math",
1926
- compatibility: ["browser", "nodejs"],
1927
- fn: subtract
1928
- },
1929
- {
1930
- name: "sum",
1931
- category: "math",
1932
- compatibility: ["browser", "nodejs"],
1933
- fn: sum
1934
- },
1935
- {
1936
- name: "times",
1937
- category: "math",
1938
- compatibility: ["browser", "nodejs"],
1939
- fn: times
1940
- }
1941
- ];
1942
-
1943
- // src/helpers/md.ts
1944
- import fs3 from "fs";
1945
- import path4 from "path";
1946
- import process2 from "process";
1947
- import ent from "ent";
1948
- import Handlebars from "handlebars";
1949
- import { Remarkable } from "remarkable";
1950
- var renderMarkdown = function(input, options2) {
1951
- if (typeof input === "object" && input && "fn" in input && typeof input.fn === "function") {
1952
- options2 = input;
1953
- input = input.fn(this);
1954
- } else if (typeof input !== "string") {
1955
- input = "";
1956
- }
1957
- const options_ = { cwd: process2.cwd(), ...options2 };
1958
- const md = new Remarkable({
1959
- breaks: true,
1960
- html: true,
1961
- langPrefix: "lang-",
1962
- typographer: false,
1963
- xhtmlOut: false
1964
- });
1965
- let string_ = input;
1966
- if (string_ && string_.length > 0) {
1967
- const filepath = path4.resolve(options_.cwd, string_);
1968
- if (fs3.existsSync(filepath) && fs3.statSync(filepath).isFile()) {
1969
- string_ = fs3.readFileSync(filepath, "utf8");
1970
- }
1971
- }
1972
- return new Handlebars.SafeString(ent.decode(md.render(string_)));
1973
- };
1974
- var helpers13 = [
1975
- {
1976
- name: "md",
1977
- category: "markdown",
1978
- compatibility: ["nodejs"],
1979
- fn: renderMarkdown
1980
- },
1981
- {
1982
- name: "markdown",
1983
- category: "markdown",
1984
- compatibility: ["nodejs"],
1985
- fn: renderMarkdown
1986
- }
1987
- ];
1988
-
1989
- // src/helpers/misc.ts
1990
- import Handlebars2 from "handlebars";
1991
- import kindOf from "kind-of";
1992
- function frame(context, options2) {
1993
- if (typeof context === "object" && context !== null && "hash" in context) {
1994
- options2 = context;
1995
- context = options2.data;
1996
- }
1997
- const data = Handlebars2.createFrame(context || {});
1998
- if (typeof options2 !== "object" || options2 === null) {
1999
- options2 = {};
2000
- }
2001
- if (options2.hash && typeof options2.hash === "object") {
2002
- Object.assign(data, options2.hash);
2003
- }
2004
- return options2.fn(this, { data });
2005
- }
2006
- function option(prop, locals, opts) {
2007
- return get(options(this, locals, opts), prop);
2008
- }
2009
- function noop(options2) {
2010
- return options2.fn(this);
2011
- }
2012
- var typeOf = kindOf;
2013
- function withHash(options2) {
2014
- if (options2.hash && Object.keys(options2.hash).length) {
2015
- return options2.fn(options2.hash);
2016
- }
2017
- return options2.inverse(this);
2018
- }
2019
- var helpers14 = [
2020
- {
2021
- name: "frame",
2022
- category: "misc",
2023
- compatibility: ["browser", "nodejs"],
2024
- fn: frame
2025
- },
2026
- {
2027
- name: "option",
2028
- category: "misc",
2029
- compatibility: ["browser", "nodejs"],
2030
- fn: option
2031
- },
2032
- {
2033
- name: "noop",
2034
- category: "misc",
2035
- compatibility: ["browser", "nodejs"],
2036
- fn: noop
2037
- },
2038
- {
2039
- name: "typeOf",
2040
- category: "misc",
2041
- compatibility: ["browser", "nodejs"],
2042
- fn: typeOf
2043
- },
2044
- {
2045
- name: "withHash",
2046
- category: "misc",
2047
- compatibility: ["browser", "nodejs"],
2048
- fn: withHash
2049
- }
2050
- ];
2051
-
2052
- // src/helpers/number.ts
2053
- var isNumeric2 = (value) => typeof value === "number" && !Number.isNaN(value);
2054
- var bytes = (value, precision) => {
2055
- if (value == null) return "0 B";
2056
- let num;
2057
- if (typeof value === "string") {
2058
- num = value.length;
2059
- if (!num) return "0 B";
2060
- } else if (isNumeric2(value)) {
2061
- num = Number(value);
2062
- } else if (typeof value.length === "number") {
2063
- num = value.length;
2064
- if (!num) return "0 B";
2065
- } else {
2066
- return "0 B";
2067
- }
2068
- const prec = typeof precision === "number" && !Number.isNaN(precision) ? precision : 2;
2069
- const abbr = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
2070
- const factor = 10 ** prec;
2071
- for (let i = abbr.length - 1; i >= 0; i--) {
2072
- const size = 10 ** (i * 3);
2073
- if (size <= num + 1) {
2074
- const val = Math.round(num * factor / size) / factor;
2075
- return `${val} ${abbr[i]}`;
2076
- }
2077
- }
2078
- return `${num}`;
2079
- };
2080
- var addCommas = (num) => num.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
2081
- var phoneNumber = (num) => {
2082
- const str = num.toString();
2083
- return `(${str.substr(0, 3)}) ${str.substr(3, 3)}-${str.substr(6, 4)}`;
2084
- };
2085
- var toAbbr = (value, precision) => {
2086
- const num = isNumeric2(value) ? Number(value) : 0;
2087
- const prec = typeof precision === "number" && !Number.isNaN(precision) ? precision : 2;
2088
- const factor = 10 ** prec;
2089
- const abbr = ["k", "m", "b", "t", "q"];
2090
- for (let i = abbr.length - 1; i >= 0; i--) {
2091
- const size = 10 ** ((i + 1) * 3);
2092
- if (size <= num + 1) {
2093
- const val = Math.round(num * factor / size) / factor;
2094
- return `${val}${abbr[i]}`;
2095
- }
2096
- }
2097
- return `${num}`;
2098
- };
2099
- var toExponential = (value, digits) => {
2100
- const num = isNumeric2(value) ? Number(value) : 0;
2101
- const d = typeof digits === "number" && !Number.isNaN(digits) ? digits : 0;
2102
- return Number(num).toExponential(d);
2103
- };
2104
- var toFixed = (value, digits) => {
2105
- const num = isNumeric2(value) ? Number(value) : 0;
2106
- const d = typeof digits === "number" && !Number.isNaN(digits) ? digits : 0;
2107
- return Number(num).toFixed(d);
2108
- };
2109
- var toFloat = (value) => parseFloat(String(value));
2110
- var toInt = (value) => parseInt(String(value), 10);
2111
- var toPrecision = (value, precision) => {
2112
- const num = isNumeric2(value) ? Number(value) : 0;
2113
- const prec = typeof precision === "number" && !Number.isNaN(precision) ? precision : 1;
2114
- return Number(num).toPrecision(prec);
2115
- };
2116
- var helpers15 = [
2117
- {
2118
- name: "bytes",
2119
- category: "number",
2120
- compatibility: ["browser", "nodejs"],
2121
- fn: bytes
2122
- },
2123
- {
2124
- name: "addCommas",
2125
- category: "number",
2126
- compatibility: ["browser", "nodejs"],
2127
- fn: addCommas
2128
- },
2129
- {
2130
- name: "phoneNumber",
2131
- category: "number",
2132
- compatibility: ["browser", "nodejs"],
2133
- fn: phoneNumber
2134
- },
2135
- {
2136
- name: "toAbbr",
2137
- category: "number",
2138
- compatibility: ["browser", "nodejs"],
2139
- fn: toAbbr
2140
- },
2141
- {
2142
- name: "toExponential",
2143
- category: "number",
2144
- compatibility: ["browser", "nodejs"],
2145
- fn: toExponential
2146
- },
2147
- {
2148
- name: "toFixed",
2149
- category: "number",
2150
- compatibility: ["browser", "nodejs"],
2151
- fn: toFixed
2152
- },
2153
- {
2154
- name: "toFloat",
2155
- category: "number",
2156
- compatibility: ["browser", "nodejs"],
2157
- fn: toFloat
2158
- },
2159
- {
2160
- name: "toInt",
2161
- category: "number",
2162
- compatibility: ["browser", "nodejs"],
2163
- fn: toInt
2164
- },
2165
- {
2166
- name: "toPrecision",
2167
- category: "number",
2168
- compatibility: ["browser", "nodejs"],
2169
- fn: toPrecision
2170
- }
2171
- ];
2172
-
2173
- // src/helpers/object.ts
2174
- var isOptions2 = (value) => {
2175
- return Boolean(value && typeof value === "object" && "hash" in value);
2176
- };
2177
- var createFrame = (options2, hash) => ({
2178
- ...options2?.data || {},
2179
- ...hash
2180
- });
2181
- var extend = (...objects) => {
2182
- const args = [...objects];
2183
- if (args.length && isOptions2(args[args.length - 1])) {
2184
- const opts = args.pop();
2185
- args.push(opts.hash);
2186
- }
2187
- const result = {};
2188
- for (const obj of args) {
2189
- if (obj && typeof obj === "object" && !Array.isArray(obj)) {
2190
- Object.assign(result, obj);
2191
- }
2192
- }
2193
- return result;
2194
- };
2195
- var forIn = (obj, options2) => {
2196
- if (!isOptions2(options2)) {
2197
- return options2?.inverse?.(obj) ?? "";
2198
- }
2199
- const data = createFrame(options2, options2.hash || {});
2200
- let result = "";
2201
- for (const key in obj) {
2202
- data.key = key;
2203
- result += options2.fn(obj[key], { data });
2204
- }
2205
- return result;
2206
- };
2207
- var forOwn = (obj, options2) => {
2208
- if (!isOptions2(options2)) {
2209
- return options2?.inverse?.(obj) ?? "";
2210
- }
2211
- const data = createFrame(options2, options2.hash || {});
2212
- let result = "";
2213
- for (const key in obj) {
2214
- if (Object.hasOwn(obj, key)) {
2215
- data.key = key;
2216
- result += options2.fn(obj[key], { data });
2217
- }
2218
- }
2219
- return result;
2220
- };
2221
- var toPath = (...prop) => {
2222
- const parts = [];
2223
- for (const p of prop) {
2224
- if (typeof p === "string" || typeof p === "number") {
2225
- parts.push(p);
2226
- }
2227
- }
2228
- return parts.join(".");
2229
- };
2230
- var getHelper = (prop, context, options2) => {
2231
- const val = get(context, prop);
2232
- if (options2 && typeof options2.fn === "function") {
2233
- return val ? options2.fn(val) : options2.inverse?.(context);
2234
- }
2235
- return val;
2236
- };
2237
- var getObjectHelper = (prop, context) => {
2238
- return getObject(context, prop);
2239
- };
2240
- var hasOwn = (context, key) => {
2241
- return Object.hasOwn(context, key);
2242
- };
2243
- var isObject = (value) => {
2244
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
2245
- };
2246
- var JSONparse = (str) => {
2247
- return JSON.parse(str);
2248
- };
2249
- var JSONstringify = (obj, indent) => {
2250
- const ind = typeof indent === "number" ? indent : 0;
2251
- return JSON.stringify(obj, null, ind);
2252
- };
2253
- var merge = (context, ...objects) => {
2254
- const args = [context, ...objects];
2255
- if (args.length && isOptions2(args[args.length - 1])) {
2256
- const opts = args.pop();
2257
- args.push(opts.hash);
2258
- }
2259
- return Object.assign(...args);
2260
- };
2261
- var parseJSON = JSONparse;
2262
- var stringify = JSONstringify;
2263
- var pick = (props, context, options2) => {
2264
- const keys = arrayify(props);
2265
- let result = {};
2266
- for (const key of keys) {
2267
- result = Object.assign({}, result, getObject(context, key));
2268
- }
2269
- if (options2 && typeof options2.fn === "function") {
2270
- if (Object.keys(result).length) {
2271
- return options2.fn(result);
2272
- }
2273
- return options2.inverse?.(context);
2274
- }
2275
- return result;
2276
- };
2277
- var helpers16 = [
2278
- {
2279
- name: "extend",
2280
- category: "object",
2281
- compatibility: ["browser", "nodejs"],
2282
- fn: extend
2283
- },
2284
- {
2285
- name: "forIn",
2286
- category: "object",
2287
- compatibility: ["browser", "nodejs"],
2288
- fn: forIn
2289
- },
2290
- {
2291
- name: "forOwn",
2292
- category: "object",
2293
- compatibility: ["browser", "nodejs"],
2294
- fn: forOwn
2295
- },
2296
- {
2297
- name: "toPath",
2298
- category: "object",
2299
- compatibility: ["browser", "nodejs"],
2300
- fn: toPath
2301
- },
2302
- {
2303
- name: "get",
2304
- category: "object",
2305
- compatibility: ["browser", "nodejs"],
2306
- fn: getHelper
2307
- },
2308
- {
2309
- name: "getObject",
2310
- category: "object",
2311
- compatibility: ["browser", "nodejs"],
2312
- fn: getObjectHelper
2313
- },
2314
- {
2315
- name: "hasOwn",
2316
- category: "object",
2317
- compatibility: ["browser", "nodejs"],
2318
- fn: hasOwn
2319
- },
2320
- {
2321
- name: "isObject",
2322
- category: "object",
2323
- compatibility: ["browser", "nodejs"],
2324
- fn: isObject
2325
- },
2326
- {
2327
- name: "JSONparse",
2328
- category: "object",
2329
- compatibility: ["browser", "nodejs"],
2330
- fn: JSONparse
2331
- },
2332
- {
2333
- name: "JSONstringify",
2334
- category: "object",
2335
- compatibility: ["browser", "nodejs"],
2336
- fn: JSONstringify
2337
- },
2338
- {
2339
- name: "merge",
2340
- category: "object",
2341
- compatibility: ["browser", "nodejs"],
2342
- fn: merge
2343
- },
2344
- {
2345
- name: "parseJSON",
2346
- category: "object",
2347
- compatibility: ["browser", "nodejs"],
2348
- fn: parseJSON
2349
- },
2350
- {
2351
- name: "pick",
2352
- category: "object",
2353
- compatibility: ["browser", "nodejs"],
2354
- fn: pick
2355
- },
2356
- {
2357
- name: "stringify",
2358
- category: "object",
2359
- compatibility: ["browser", "nodejs"],
2360
- fn: stringify
2361
- }
2362
- ];
2363
-
2364
- // src/helpers/path.ts
2365
- import path5 from "path";
2366
- var expectedType = (variableName, expectedType2, variableValue) => {
2367
- const actualType = Object.prototype.toString.call(variableValue).slice(8, -1).toLowerCase();
2368
- return `Expected ${variableName} to be of type ${expectedType2}, but got ${actualType}`;
2369
- };
2370
- var assertString = (name, value) => {
2371
- if (typeof value !== "string") {
2372
- throw new TypeError(expectedType(name, "string", value));
2373
- }
2374
- return value;
2375
- };
2376
- var absolute = function(filepath, options2) {
2377
- const fp = assertString("filepath", filepath);
2378
- const cwd = options2?.data?.root?.cwd ?? this?.cwd ?? process.cwd();
2379
- return path5.resolve(cwd, fp);
2380
- };
2381
- var dirname = (filepath) => {
2382
- const fp = assertString("filepath", filepath);
2383
- return path5.dirname(fp);
2384
- };
2385
- var relative = (a, b) => {
2386
- const from = assertString("first path", a);
2387
- const to = assertString("second path", b);
2388
- return path5.relative(path5.dirname(from), to);
2389
- };
2390
- var basename = (filepath) => {
2391
- const fp = assertString("filepath", filepath);
2392
- return path5.basename(fp);
2393
- };
2394
- var stem = (filepath) => {
2395
- const fp = assertString("filepath", filepath);
2396
- return path5.basename(fp, path5.extname(fp));
2397
- };
2398
- var extname = (filepath) => {
2399
- const fp = assertString("filepath", filepath);
2400
- return path5.extname(fp);
2401
- };
2402
- var resolveFn = function(filepath, ...paths) {
2403
- let options2;
2404
- const last2 = paths[paths.length - 1];
2405
- if (typeof last2 === "object" && last2 && "data" in last2) {
2406
- options2 = paths.pop();
2407
- }
2408
- const cwd = options2?.data?.root?.cwd ?? this?.cwd ?? process.cwd();
2409
- const all2 = [
2410
- cwd,
2411
- assertString("filepath", filepath),
2412
- ...paths.map((p, i) => assertString(`path${i}`, p))
2413
- ];
2414
- return path5.resolve(...all2);
2415
- };
2416
- var segments = (filepath, a, b) => {
2417
- const fp = assertString("filepath", filepath);
2418
- const start = Number(a);
2419
- const end = Number(b);
2420
- const segmentsArr = fp.split(/[\\/]+/);
2421
- return segmentsArr.slice(start, end).join("/");
2422
- };
2423
- var helpers17 = [
2424
- {
2425
- name: "absolute",
2426
- category: "path",
2427
- compatibility: ["nodejs"],
2428
- fn: absolute
2429
- },
2430
- {
2431
- name: "dirname",
2432
- category: "path",
2433
- compatibility: ["nodejs"],
2434
- fn: dirname
2435
- },
2436
- {
2437
- name: "relative",
2438
- category: "path",
2439
- compatibility: ["nodejs"],
2440
- fn: relative
2441
- },
2442
- {
2443
- name: "basename",
2444
- category: "path",
2445
- compatibility: ["nodejs"],
2446
- fn: basename
2447
- },
2448
- {
2449
- name: "stem",
2450
- category: "path",
2451
- compatibility: ["nodejs"],
2452
- fn: stem
2453
- },
2454
- {
2455
- name: "extname",
2456
- category: "path",
2457
- compatibility: ["nodejs"],
2458
- fn: extname
2459
- },
2460
- {
2461
- name: "resolve",
2462
- category: "path",
2463
- compatibility: ["nodejs"],
2464
- fn: resolveFn
2465
- },
2466
- {
2467
- name: "segments",
2468
- category: "path",
2469
- compatibility: ["nodejs"],
2470
- fn: segments
2471
- }
2472
- ];
2473
-
2474
- // src/helpers/regex.ts
2475
- var toRegex = (str, locals, opts) => {
2476
- const mergedOpts = options({}, locals, opts);
2477
- return new RegExp(str, mergedOpts.flags);
2478
- };
2479
- var test = (str, regex) => {
2480
- if (typeof str !== "string") {
2481
- return false;
2482
- }
2483
- if (!(regex instanceof RegExp)) {
2484
- throw new TypeError("expected a regular expression");
2485
- }
2486
- return regex.test(str);
2487
- };
2488
- var helpers18 = [
2489
- {
2490
- name: "toRegex",
2491
- category: "regex",
2492
- compatibility: ["browser", "nodejs"],
2493
- fn: toRegex
2494
- },
2495
- {
2496
- name: "test",
2497
- category: "regex",
2498
- compatibility: ["browser", "nodejs"],
2499
- fn: test
2500
- }
2501
- ];
2502
-
2503
- // src/helpers/string.ts
2504
- var chop = (str) => str.trim().replace(/^[-_.\W\s]+|[-_.\W\s]+$/g, "");
2505
- var changecase = (str, fn) => {
2506
- if (str.length === 1) return str.toLowerCase();
2507
- const res = chop(str).toLowerCase();
2508
- return res.replace(/[-_.\W\s]+(\w|$)/g, (_, ch) => fn(ch));
2509
- };
2510
- var append = (str, suffix) => {
2511
- if (typeof str === "string" && typeof suffix === "string") {
2512
- return str + suffix;
2513
- }
2514
- return str;
2515
- };
2516
- var camelcase = (str) => typeof str === "string" ? changecase(str, (ch) => ch.toUpperCase()) : "";
2517
- var capitalize = (str) => {
2518
- if (typeof str !== "string" || str.length === 0) return "";
2519
- return str.charAt(0).toUpperCase() + str.slice(1);
2520
- };
2521
- var capitalizeAll = (str) => {
2522
- if (typeof str !== "string") return "";
2523
- return str.replace(/\w\S*/g, (word) => capitalize(word));
2524
- };
2525
- var center = (str, spaces) => {
2526
- if (typeof str !== "string") return "";
2527
- let space = "";
2528
- for (let i = 0; i < spaces; i++) {
2529
- space += "&nbsp;";
2530
- }
2531
- return space + str + space;
2532
- };
2533
- var chopStr = (str) => typeof str === "string" ? chop(str) : "";
2534
- var dashcase = (str) => typeof str === "string" ? changecase(str, (ch) => `-${ch}`) : "";
2535
- var dotcase = (str) => typeof str === "string" ? changecase(str, (ch) => `.${ch}`) : "";
2536
- var truncate = (str, limit, suffix) => {
2537
- if (typeof str === "string") {
2538
- if (typeof suffix !== "string") {
2539
- suffix = "";
2540
- }
2541
- if (str.length > limit) {
2542
- return str.slice(0, limit - suffix.length) + suffix;
2543
- }
2544
- return str;
2545
- }
2546
- return "";
2547
- };
2548
- var ellipsis = (str, limit) => {
2549
- if (typeof str === "string") {
2550
- if (str.length <= limit) {
2551
- return str;
2552
- }
2553
- return `${truncate(str, limit)}\u2026`;
2554
- }
2555
- return "";
2556
- };
2557
- var hyphenate = (str) => typeof str === "string" ? str.split(" ").join("-") : "";
2558
- var isString = (value) => typeof value === "string";
2559
- var lowercase = (str) => {
2560
- if (typeof str === "object" && str !== null && "fn" in str && typeof str.fn === "function") {
2561
- return String(str.fn()).toLowerCase();
2562
- }
2563
- if (typeof str !== "string") return "";
2564
- return str.toLowerCase();
2565
- };
2566
- var downcase = (str) => lowercase(str);
2567
- var occurrences = (str, substring) => {
2568
- if (typeof str !== "string") return "";
2569
- const len = substring.length;
2570
- let pos = str.indexOf(substring, 0);
2571
- let n = 0;
2572
- while (pos > -1) {
2573
- n++;
2574
- pos = str.indexOf(substring, pos + len);
2575
- }
2576
- return n;
2577
- };
2578
- var pascalcase = (str) => {
2579
- if (typeof str !== "string") return "";
2580
- const res = changecase(str, (ch) => ch.toUpperCase());
2581
- return res.charAt(0).toUpperCase() + res.slice(1);
2582
- };
2583
- var pathcase = (str) => typeof str === "string" ? changecase(str, (ch) => `/${ch}`) : "";
2584
- var plusify = (str, ch) => {
2585
- if (typeof str !== "string") return "";
2586
- if (typeof ch !== "string") ch = " ";
2587
- return str.split(ch).join("+");
2588
- };
2589
- var prepend = (str, prefix) => {
2590
- return typeof str === "string" && typeof prefix === "string" ? prefix + str : str;
2591
- };
2592
- var remove = (str, ch) => {
2593
- if (typeof str !== "string") return "";
2594
- if (typeof ch !== "string") return str;
2595
- return str.split(ch).join("");
2596
- };
2597
- var removeFirst = (str, ch) => {
2598
- if (typeof str !== "string") return "";
2599
- if (typeof ch !== "string") return str;
2600
- return str.replace(ch, "");
2601
- };
2602
- var replace = (str, a, b) => {
2603
- if (typeof str !== "string") return "";
2604
- if (typeof a !== "string") return str;
2605
- if (typeof b !== "string") b = "";
2606
- return str.split(a).join(b);
2607
- };
2608
- var replaceFirst = (str, a, b) => {
2609
- if (typeof str !== "string") return "";
2610
- if (typeof a !== "string") return str;
2611
- if (typeof b !== "string") b = "";
2612
- return str.replace(a, b);
2613
- };
2614
- var reverse2 = (str) => typeof str === "string" ? str.split("").reverse().join("") : "";
2615
- var sentence = (str) => {
2616
- if (typeof str !== "string") return "";
2617
- return str.replace(
2618
- /((?:\S[^.?!]*)[.?!]*)/g,
2619
- (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase()
2620
- );
2621
- };
2622
- var snakecase = (str) => typeof str === "string" ? changecase(str, (ch) => `_${ch}`) : "";
2623
- var trim = (str) => typeof str === "string" ? str.trim() : "";
2624
- var trimLeft = (str) => typeof str === "string" ? str.replace(/^\s+/, "") : "";
2625
- var trimRight = (str) => typeof str === "string" ? str.replace(/\s+$/, "") : "";
2626
- var truncateWords = (str, count, suffix) => {
2627
- if (typeof str === "string" && typeof count === "number" && Number.isFinite(count)) {
2628
- if (typeof suffix !== "string") {
2629
- suffix = "...";
2630
- }
2631
- const num = Math.trunc(count);
2632
- let arr = str.split(" ");
2633
- if (num < arr.length) {
2634
- arr = arr.slice(0, num);
2635
- }
2636
- const val = arr.join(" ").trim();
2637
- return val + suffix;
2638
- }
2639
- return "";
2640
- };
2641
- var truncateWordsAlias = truncateWords;
2642
- var uppercase = (str) => {
2643
- if (typeof str === "object" && str !== null && "fn" in str && typeof str.fn === "function") {
2644
- return String(str.fn()).toUpperCase();
2645
- }
2646
- if (typeof str !== "string") return "";
2647
- return str.toUpperCase();
2648
- };
2649
- var upcase = (str) => uppercase(str);
2650
- var split = (str, character) => {
2651
- if (typeof str !== "string") return "";
2652
- if (typeof character !== "string") character = "";
2653
- return str.split(character);
2654
- };
2655
- var startsWith = (prefix, testString, _options) => {
2656
- if (typeof prefix !== "string" || typeof testString !== "string") {
2657
- return false;
2658
- }
2659
- return testString.startsWith(prefix);
2660
- };
2661
- var titleize = (str) => {
2662
- if (typeof str !== "string") return "";
2663
- return str.replace(/\w\S*/g, (word) => {
2664
- return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
2665
- });
2666
- };
2667
- var raw = (options2) => {
2668
- if (options2 && typeof options2.fn === "function") {
2669
- return options2.fn();
2670
- }
2671
- return "";
2672
- };
2673
- var helpers19 = [
2674
- {
2675
- name: "append",
2676
- category: "string",
2677
- compatibility: ["browser", "nodejs"],
2678
- fn: append
2679
- },
2680
- {
2681
- name: "camelcase",
2682
- category: "string",
2683
- compatibility: ["browser", "nodejs"],
2684
- fn: camelcase
2685
- },
2686
- {
2687
- name: "capitalize",
2688
- category: "string",
2689
- compatibility: ["browser", "nodejs"],
2690
- fn: capitalize
2691
- },
2692
- {
2693
- name: "capitalizeAll",
2694
- category: "string",
2695
- compatibility: ["browser", "nodejs"],
2696
- fn: capitalizeAll
2697
- },
2698
- {
2699
- name: "center",
2700
- category: "string",
2701
- compatibility: ["browser", "nodejs"],
2702
- fn: center
2703
- },
2704
- {
2705
- name: "chop",
2706
- category: "string",
2707
- compatibility: ["browser", "nodejs"],
2708
- fn: chopStr
2709
- },
2710
- {
2711
- name: "dashcase",
2712
- category: "string",
2713
- compatibility: ["browser", "nodejs"],
2714
- fn: dashcase
2715
- },
2716
- {
2717
- name: "dotcase",
2718
- category: "string",
2719
- compatibility: ["browser", "nodejs"],
2720
- fn: dotcase
2721
- },
2722
- {
2723
- name: "ellipsis",
2724
- category: "string",
2725
- compatibility: ["browser", "nodejs"],
2726
- fn: ellipsis
2727
- },
2728
- {
2729
- name: "hyphenate",
2730
- category: "string",
2731
- compatibility: ["browser", "nodejs"],
2732
- fn: hyphenate
2733
- },
2734
- {
2735
- name: "isString",
2736
- category: "string",
2737
- compatibility: ["browser", "nodejs"],
2738
- fn: isString
2739
- },
2740
- {
2741
- name: "lowercase",
2742
- category: "string",
2743
- compatibility: ["browser", "nodejs"],
2744
- fn: lowercase
2745
- },
2746
- {
2747
- name: "downcase",
2748
- category: "string",
2749
- compatibility: ["browser", "nodejs"],
2750
- fn: downcase
2751
- },
2752
- {
2753
- name: "occurrences",
2754
- category: "string",
2755
- compatibility: ["browser", "nodejs"],
2756
- fn: occurrences
2757
- },
2758
- {
2759
- name: "pascalcase",
2760
- category: "string",
2761
- compatibility: ["browser", "nodejs"],
2762
- fn: pascalcase
2763
- },
2764
- {
2765
- name: "pathcase",
2766
- category: "string",
2767
- compatibility: ["browser", "nodejs"],
2768
- fn: pathcase
2769
- },
2770
- {
2771
- name: "plusify",
2772
- category: "string",
2773
- compatibility: ["browser", "nodejs"],
2774
- fn: plusify
2775
- },
2776
- {
2777
- name: "prepend",
2778
- category: "string",
2779
- compatibility: ["browser", "nodejs"],
2780
- fn: prepend
2781
- },
2782
- {
2783
- name: "remove",
2784
- category: "string",
2785
- compatibility: ["browser", "nodejs"],
2786
- fn: remove
2787
- },
2788
- {
2789
- name: "removeFirst",
2790
- category: "string",
2791
- compatibility: ["browser", "nodejs"],
2792
- fn: removeFirst
2793
- },
2794
- {
2795
- name: "replace",
2796
- category: "string",
2797
- compatibility: ["browser", "nodejs"],
2798
- fn: replace
2799
- },
2800
- {
2801
- name: "replaceFirst",
2802
- category: "string",
2803
- compatibility: ["browser", "nodejs"],
2804
- fn: replaceFirst
2805
- },
2806
- {
2807
- name: "reverse",
2808
- category: "string",
2809
- compatibility: ["browser", "nodejs"],
2810
- fn: reverse2
2811
- },
2812
- {
2813
- name: "sentence",
2814
- category: "string",
2815
- compatibility: ["browser", "nodejs"],
2816
- fn: sentence
2817
- },
2818
- {
2819
- name: "snakecase",
2820
- category: "string",
2821
- compatibility: ["browser", "nodejs"],
2822
- fn: snakecase
2823
- },
2824
- {
2825
- name: "trim",
2826
- category: "string",
2827
- compatibility: ["browser", "nodejs"],
2828
- fn: trim
2829
- },
2830
- {
2831
- name: "trimLeft",
2832
- category: "string",
2833
- compatibility: ["browser", "nodejs"],
2834
- fn: trimLeft
2835
- },
2836
- {
2837
- name: "trimRight",
2838
- category: "string",
2839
- compatibility: ["browser", "nodejs"],
2840
- fn: trimRight
2841
- },
2842
- {
2843
- name: "truncate",
2844
- category: "string",
2845
- compatibility: ["browser", "nodejs"],
2846
- fn: truncate
2847
- },
2848
- {
2849
- name: "truncateWords",
2850
- category: "string",
2851
- compatibility: ["browser", "nodejs"],
2852
- fn: truncateWordsAlias
2853
- },
2854
- {
2855
- name: "uppercase",
2856
- category: "string",
2857
- compatibility: ["browser", "nodejs"],
2858
- fn: uppercase
2859
- },
2860
- {
2861
- name: "upcase",
2862
- category: "string",
2863
- compatibility: ["browser", "nodejs"],
2864
- fn: upcase
2865
- },
2866
- {
2867
- name: "split",
2868
- category: "string",
2869
- compatibility: ["browser", "nodejs"],
2870
- fn: split
2871
- },
2872
- {
2873
- name: "startsWith",
2874
- category: "string",
2875
- compatibility: ["browser", "nodejs"],
2876
- fn: startsWith
2877
- },
2878
- {
2879
- name: "titleize",
2880
- category: "string",
2881
- compatibility: ["browser", "nodejs"],
2882
- fn: titleize
2883
- },
2884
- {
2885
- name: "raw",
2886
- category: "string",
2887
- compatibility: ["browser", "nodejs"],
2888
- fn: raw
2889
- }
2890
- ];
2891
-
2892
- // src/helpers/url.ts
2893
- import { escape as qsEscape } from "querystring";
2894
- import { format, parse, resolve } from "url";
2895
- var all = ["browser", "nodejs"];
2896
- var encodeUri = (str) => {
2897
- if (typeof str === "string") {
2898
- return encodeURIComponent(str);
2899
- }
2900
- };
2901
- var escapeFn = (str) => {
2902
- if (typeof str === "string") {
2903
- return qsEscape(str);
2904
- }
2905
- };
2906
- var decodeUri = (str) => {
2907
- if (typeof str === "string") {
2908
- return decodeURIComponent(str);
2909
- }
2910
- };
2911
- function urlEncode(...args) {
2912
- return encodeUri.apply(this, args);
2913
- }
2914
- function urlDecode(...args) {
2915
- return decodeUri.apply(this, args);
2916
- }
2917
- var urlResolve = (base, href) => resolve(String(base), String(href));
2918
- var urlParse = (str) => parse(String(str));
2919
- var stripQuerystring = (str) => {
2920
- if (typeof str === "string") {
2921
- return str.split("?")[0];
2922
- }
2923
- };
2924
- var stripProtocol = (str) => {
2925
- if (typeof str === "string") {
2926
- const parsed = parse(str);
2927
- parsed.protocol = "";
2928
- return format(parsed);
2929
- }
2930
- };
2931
- var helpers20 = [
2932
- {
2933
- name: "encodeURI",
2934
- category: "url",
2935
- compatibility: all,
2936
- fn: encodeUri
2937
- },
2938
- {
2939
- name: "escape",
2940
- category: "url",
2941
- compatibility: ["nodejs"],
2942
- fn: escapeFn
2943
- },
2944
- {
2945
- name: "decodeURI",
2946
- category: "url",
2947
- compatibility: all,
2948
- fn: decodeUri
2949
- },
2950
- {
2951
- name: "url_encode",
2952
- category: "url",
2953
- compatibility: all,
2954
- fn: urlEncode
2955
- },
2956
- {
2957
- name: "url_decode",
2958
- category: "url",
2959
- compatibility: all,
2960
- fn: urlDecode
2961
- },
2962
- {
2963
- name: "urlResolve",
2964
- category: "url",
2965
- compatibility: ["nodejs"],
2966
- fn: urlResolve
2967
- },
2968
- {
2969
- name: "urlParse",
2970
- category: "url",
2971
- compatibility: ["nodejs"],
2972
- fn: urlParse
2973
- },
2974
- {
2975
- name: "stripQuerystring",
2976
- category: "url",
2977
- compatibility: all,
2978
- fn: stripQuerystring
2979
- },
2980
- {
2981
- name: "stripProtocol",
2982
- category: "url",
2983
- compatibility: ["nodejs"],
2984
- fn: stripProtocol
2985
- }
2986
- ];
2987
-
2988
- // src/helper-registry.ts
2989
- var HelperRegistry = class {
2990
- _helpers = [];
2991
- constructor() {
2992
- this.init();
2993
- }
2994
- /**
2995
- * Get all registered helpers.
2996
- * @returns {Helper[]} The array of registered helpers.
2997
- */
2998
- get helpers() {
2999
- return this._helpers;
3000
- }
3001
- /**
3002
- * Initialize the helper registry. This is performed during the construction of the registry such as new HelperRegistry().
3003
- */
3004
- init() {
3005
- this.registerHelpers(helpers);
3006
- this.registerHelpers(helpers3);
3007
- this.registerHelpers(helpers5);
3008
- this.registerHelpers(helpers6);
3009
- this.registerHelpers(helpers2);
3010
- this.registerHelpers(helpers13);
3011
- this.registerHelpers(helpers7);
3012
- this.registerHelpers(helpers4);
3013
- this.registerHelpers(helpers8);
3014
- this.registerHelpers(helpers9);
3015
- this.registerHelpers(helpers10);
3016
- this.registerHelpers(helpers11);
3017
- this.registerHelpers(helpers12);
3018
- this.registerHelpers(helpers14);
3019
- this.registerHelpers(helpers15);
3020
- this.registerHelpers(helpers17);
3021
- this.registerHelpers(helpers18);
3022
- this.registerHelpers(helpers19);
3023
- this.registerHelpers(helpers20);
3024
- this.registerHelpers(helpers16);
3025
- }
3026
- /**
3027
- * Register a helper.
3028
- * @param {Helper} helper The helper to register.
3029
- * @returns True if the helper was registered, false otherwise.
3030
- */
3031
- register(helper) {
3032
- const result = false;
3033
- if (!this.has(helper.name)) {
3034
- this._helpers.push(helper);
3035
- }
3036
- return result;
3037
- }
3038
- /**
3039
- * Register multiple helpers.
3040
- * @param {Helper[]} helpers The array of helpers to register.
3041
- */
3042
- registerHelpers(helpers22) {
3043
- for (const helper of helpers22) {
3044
- this.register(helper);
3045
- }
3046
- }
3047
- /**
3048
- * Check if a helper is registered.
3049
- * @param name The name of the helper.
3050
- * @returns True if the helper is registered, false otherwise.
3051
- */
3052
- has(name) {
3053
- return this._helpers.some((helper) => helper.name === name);
3054
- }
3055
- /**
3056
- * Filter helpers by the given criteria.
3057
- * @param filter The filter criteria.
3058
- * @returns The filtered helpers.
3059
- */
3060
- filter(filter2) {
3061
- let result = this._helpers;
3062
- if (filter2.names) {
3063
- result = result.filter((helper) => filter2.names?.includes(helper.name));
3064
- }
3065
- if (filter2.categories) {
3066
- result = result.filter(
3067
- (helper) => filter2.categories?.includes(helper.category)
3068
- );
3069
- }
3070
- if (filter2.compatibility) {
3071
- result = result.filter(
3072
- (helper) => helper.compatibility?.some((c) => filter2.compatibility?.includes(c))
3073
- );
3074
- }
3075
- return result;
3076
- }
3077
- /**
3078
- * Load Handlebars helpers.
3079
- * @param {Handlebars} handlebars The Handlebars instance.
3080
- * @returns {void}
3081
- */
3082
- load(handlebars2, filters) {
3083
- let helpers22 = this._helpers;
3084
- if (filters) {
3085
- helpers22 = this.filter(filters);
3086
- }
3087
- for (const helper of helpers22) {
3088
- handlebars2.registerHelper(helper.name, helper.fn);
3089
- }
3090
- }
3091
- /**
3092
- * Swap Handlebars helpers. This is used when you want to swap out legacy helpers for fumanchu helpers.
3093
- * @param handlebars The Handlebars instance.
3094
- * @returns {void}
3095
- */
3096
- swap(handlebars2) {
3097
- for (const helper of this._helpers) {
3098
- handlebars2.unregisterHelper(helper.name);
3099
- handlebars2.registerHelper(helper.name, helper.fn);
3100
- }
3101
- }
3102
- };
3103
-
3104
- // src/index.ts
3105
- var Handlebars3 = HandlebarsLib;
3106
- var handlebars = HandlebarsLib.create();
3107
- function helpers21(options2) {
3108
- const registry = new HelperRegistry();
3109
- registry.load(options2.handlebars ?? options2.hbs);
3110
- }
3111
- async function createHandlebars() {
3112
- const registry = new HelperRegistry();
3113
- const handlebars2 = HandlebarsLib.create();
3114
- if (Object.keys(HandlebarsLib.partials).length > 0) {
3115
- handlebars2.registerPartial(HandlebarsLib.partials);
3116
- }
3117
- registry.load(handlebars2);
3118
- if (process.env.NODE_ENV === "development") {
3119
- console.warn(
3120
- "createHandlebars will be deprecated in future versions, use `fumanchu` instead."
3121
- );
3122
- }
3123
- return handlebars2;
3124
- }
3125
- function fumanchu(options2) {
3126
- const registry = new HelperRegistry();
3127
- let handlebars2 = HandlebarsLib.create();
3128
- if (options2?.handlebars) {
3129
- handlebars2 = options2.handlebars;
3130
- } else if (Object.keys(HandlebarsLib.partials).length > 0) {
3131
- handlebars2.registerPartial(HandlebarsLib.partials);
3132
- }
3133
- registry.load(handlebars2);
3134
- if (options2?.caching) {
3135
- let cache;
3136
- if (options2.caching instanceof CacheableMemory) {
3137
- cache = options2.caching;
3138
- } else if (typeof options2.caching === "object") {
3139
- cache = new CacheableMemory({
3140
- useClone: false,
3141
- ...options2.caching
3142
- });
3143
- } else {
3144
- cache = new CacheableMemory({ useClone: false });
3145
- }
3146
- const originalCompile = handlebars2.compile.bind(handlebars2);
3147
- handlebars2.compile = (input, compileOptions) => {
3148
- const key = compileOptions ? input + JSON.stringify(compileOptions) : String(input);
3149
- const cached = cache.get(key);
3150
- if (cached) {
3151
- return cached;
3152
- }
3153
- const compiled = originalCompile(input, compileOptions);
3154
- cache.set(key, compiled);
3155
- return compiled;
3156
- };
3157
- }
3158
- return handlebars2;
3159
- }
3160
- export {
3161
- CacheableMemory,
3162
- Handlebars3 as Handlebars,
3163
- HelperRegistry,
3164
- createHandlebars,
3165
- fumanchu,
3166
- handlebars,
3167
- helpers21 as helpers
3168
- };
3169
- /* v8 ignore next -- @preserve */
3170
- /* c8 ignore next -- @preserve */