@jaredwray/fumanchu 3.0.2 → 3.0.4
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/README.md +1 -600
- package/dist/index.js +23 -3
- package/package.json +13 -10
package/README.md
CHANGED
|
@@ -10,28 +10,7 @@ Handlebars + Helpers Together
|
|
|
10
10
|
[](https://github.com/jaredwray/fumanchu/blob/master/LICENSE)
|
|
11
11
|
[](https://npmjs.com/package/@jaredwray/fumanchu)
|
|
12
12
|
|
|
13
|
-
[Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use
|
|
14
|
-
|
|
15
|
-
We plan to make significant changes over time with this project such as the following:
|
|
16
|
-
- **(Completed)** Remove all dependencies on `handlebars-helpers` and maintain all helpers in this project
|
|
17
|
-
- **(Completed)** Migration to `vitest` as a testing framework
|
|
18
|
-
- **(Completed)** Migration to `xo` as a linting framework
|
|
19
|
-
- **(In Progress)** Migrate to Typescript with full typing support
|
|
20
|
-
- **(In Progress)** Replace module dependencies that are no longer supported with supported ones
|
|
21
|
-
- Migration to ESM and CJS support using cross compatible code
|
|
22
|
-
- Move to better documentation and examples where it makes sense
|
|
23
|
-
- Add in browser support via CDN (this will remove the nodejs specific helpers)
|
|
24
|
-
|
|
25
|
-
# Breaking Changes from v2 to v3
|
|
26
|
-
|
|
27
|
-
Because of the complexity in the legacy helpers library we have moved to exporting the libraries and a helper function to make it easier to use. Here are the exports:
|
|
28
|
-
|
|
29
|
-
- `handlebars` - This is an instance of handlebars library without any helpers. It is the same as calling `Handlebars.create()`
|
|
30
|
-
- `helpers` - This is a function that takes an object with a `handlebars` key and adds all the helpers to the handlebars instance. This is the same as calling `helpers({ handlebars: handlebars }, { ..options })`
|
|
31
|
-
- `createHandlebars` - This is an async function that returns a handlebars instance with all the helpers added. This is the same as calling `helpers({ handlebars: handlebars }, { ..options })` but async.
|
|
32
|
-
- `Handlebars` - This is the handlebars library itself. It is the same as calling `require('handlebars')`
|
|
33
|
-
|
|
34
|
-
Please see the examples below for how to use the library.
|
|
13
|
+
[Handlebars](https://github.com/handlebars-lang/handlebars.js) + [Handlebars-helpers](https://github.com/helpers/handlebars-helpers) (helpers are now maintained in this project) combined into a single package. Easily use it as a drop in replacement when using handlebars directly.
|
|
35
14
|
|
|
36
15
|
# Table of Contents
|
|
37
16
|
* [Using in Nodejs](#using-in-nodejs)
|
|
@@ -130,39 +109,6 @@ Currently **189 helpers** in **20 categories**:
|
|
|
130
109
|
|
|
131
110
|
# All helpers
|
|
132
111
|
|
|
133
|
-
### [array helpers](#array)
|
|
134
|
-
|
|
135
|
-
Visit the: [code](lib/array.js) | [unit tests](test/array.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+array+helpers))
|
|
136
|
-
|
|
137
|
-
* **[after](#after)** ([code](lib/array.js#L22) | [tests](test/array.js#L13))
|
|
138
|
-
* **[arrayify](#arrayify)** ([code](lib/array.js#L39) | [tests](test/array.js#L29))
|
|
139
|
-
* **[before](#before)** ([code](lib/array.js#L58) | [tests](test/array.js#L36))
|
|
140
|
-
* **[eachIndex](#eachIndex)** ([code](lib/array.js#L77) | [tests](test/array.js#L58))
|
|
141
|
-
* **[filter](#filter)** ([code](lib/array.js#L102) | [tests](test/array.js#L91))
|
|
142
|
-
* **[first](#first)** ([code](lib/array.js#L142) | [tests](test/array.js#L65))
|
|
143
|
-
* **[forEach](#forEach)** ([code](lib/array.js#L184) | [tests](test/array.js#L123))
|
|
144
|
-
* **[inArray](#inArray)** ([code](lib/array.js#L224) | [tests](test/array.js#L160))
|
|
145
|
-
* **[isArray](#isArray)** ([code](lib/array.js#L244) | [tests](test/array.js#L172))
|
|
146
|
-
* **[itemAt](#itemAt)** ([code](lib/array.js#L263) | [tests](test/array.js#L182))
|
|
147
|
-
* **[join](#join)** ([code](lib/array.js#L294) | [tests](test/array.js#L225))
|
|
148
|
-
* **[equalsLength](#equalsLength)** ([code](lib/array.js#L313) | [tests](test/array.js#L494))
|
|
149
|
-
* **[last](#last)** ([code](lib/array.js#L349) | [tests](test/array.js#L240))
|
|
150
|
-
* **[length](#length)** ([code](lib/array.js#L379) | [tests](test/array.js#L254))
|
|
151
|
-
* **[lengthEqual](#lengthEqual)** ([code](lib/array.js#L395) | [tests](test/array.js#L254))
|
|
152
|
-
* **[map](#map)** ([code](lib/array.js#L414) | [tests](test/array.js#L266))
|
|
153
|
-
* **[pluck](#pluck)** ([code](lib/array.js#L445) | [tests](test/array.js#L300))
|
|
154
|
-
* **[reverse](#reverse)** ([code](lib/array.js#L473) | [tests](test/array.js#L506))
|
|
155
|
-
* **[some](#some)** ([code](lib/array.js#L504) | [tests](test/array.js#L308))
|
|
156
|
-
* **[sort](#sort)** ([code](lib/array.js#L532) | [tests](test/array.js#L333))
|
|
157
|
-
* **[sortBy](#sortBy)** ([code](lib/array.js#L557) | [tests](test/array.js#L358))
|
|
158
|
-
* **[withAfter](#withAfter)** ([code](lib/array.js#L588) | [tests](test/array.js#L390))
|
|
159
|
-
* **[withBefore](#withBefore)** ([code](lib/array.js#L618) | [tests](test/array.js#L397))
|
|
160
|
-
* **[withFirst](#withFirst)** ([code](lib/array.js#L648) | [tests](test/array.js#L404))
|
|
161
|
-
* **[withGroup](#withGroup)** ([code](lib/array.js#L692) | [tests](test/array.js#L418))
|
|
162
|
-
* **[withLast](#withLast)** ([code](lib/array.js#L727) | [tests](test/array.js#L428))
|
|
163
|
-
* **[withSort](#withSort)** ([code](lib/array.js#L766) | [tests](test/array.js#L442))
|
|
164
|
-
* **[unique](#unique)** ([code](lib/array.js#L816) | [tests](test/array.js#L483))
|
|
165
|
-
|
|
166
112
|
### [code helpers](#code)
|
|
167
113
|
|
|
168
114
|
Visit the: [code](lib/code.js) | [unit tests](test/code.js) | [issues](https://github.com/jonathas/handlebars-helpers/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+code+helpers))
|
|
@@ -417,552 +363,7 @@ Visit the: [code](lib/url.js) | [unit tests](test/url.js) | [issues](https://git
|
|
|
417
363
|
* **[stripQuerystring](#stripQuerystring)** ([code](lib/url.js#L106) | [tests](test/url.js#L24))
|
|
418
364
|
* **[stripProtocol](#stripProtocol)** ([code](lib/url.js#L126) | [tests](test/url.js#L53))
|
|
419
365
|
|
|
420
|
-
***
|
|
421
|
-
|
|
422
|
-
## array
|
|
423
|
-
|
|
424
|
-
### [{{after}}](lib/array.js#L22)
|
|
425
|
-
|
|
426
|
-
Returns all of the items in an array after the specified index. Opposite of [before](#before).
|
|
427
|
-
|
|
428
|
-
**Params**
|
|
429
|
-
|
|
430
|
-
* `array` **{Array}**: Collection
|
|
431
|
-
* `n` **{Number}**: Starting index (number of items to exclude)
|
|
432
|
-
* `returns` **{Array}**: Array exluding `n` items.
|
|
433
|
-
|
|
434
|
-
**Example**
|
|
435
|
-
|
|
436
|
-
```html
|
|
437
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
438
|
-
{{after array 1}}
|
|
439
|
-
<!-- results in: '["c"]' -->
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
### [{{arrayify}}](lib/array.js#L39)
|
|
443
|
-
|
|
444
|
-
Cast the given `value` to an array.
|
|
445
|
-
|
|
446
|
-
**Params**
|
|
447
|
-
|
|
448
|
-
* `value` **{any}**
|
|
449
|
-
* `returns` **{Array}**
|
|
450
|
-
|
|
451
|
-
**Example**
|
|
452
|
-
|
|
453
|
-
```html
|
|
454
|
-
{{arrayify "foo"}}
|
|
455
|
-
<!-- results in: [ "foo" ] -->
|
|
456
|
-
```
|
|
457
|
-
|
|
458
|
-
### [{{before}}](lib/array.js#L58)
|
|
459
|
-
|
|
460
|
-
Return all of the items in the collection before the specified count. Opposite of [after](#after).
|
|
461
|
-
|
|
462
|
-
**Params**
|
|
463
|
-
|
|
464
|
-
* `array` **{Array}**
|
|
465
|
-
* `n` **{Number}**
|
|
466
|
-
* `returns` **{Array}**: Array excluding items after the given number.
|
|
467
|
-
|
|
468
|
-
**Example**
|
|
469
|
-
|
|
470
|
-
```html
|
|
471
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
472
|
-
{{before array 2}}
|
|
473
|
-
<!-- results in: '["a", "b"]' -->
|
|
474
|
-
```
|
|
475
|
-
|
|
476
|
-
### [{{eachIndex}}](lib/array.js#L77)
|
|
477
|
-
|
|
478
|
-
**Params**
|
|
479
|
-
|
|
480
|
-
* `array` **{Array}**
|
|
481
|
-
* `options` **{Object}**
|
|
482
|
-
* `returns` **{String}**
|
|
483
|
-
|
|
484
|
-
**Example**
|
|
485
|
-
|
|
486
|
-
```html
|
|
487
|
-
<!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
|
|
488
|
-
{{#eachIndex array}}
|
|
489
|
-
{{item}} is {{index}}
|
|
490
|
-
{{/eachIndex}}
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
### [{{filter}}](lib/array.js#L102)
|
|
494
|
-
|
|
495
|
-
Block helper that filters the given array and renders the block for values that evaluate to `true`, otherwise the inverse block is returned.
|
|
496
|
-
|
|
497
|
-
**Params**
|
|
498
|
-
|
|
499
|
-
* `array` **{Array}**
|
|
500
|
-
* `value` **{any}**
|
|
501
|
-
* `options` **{Object}**
|
|
502
|
-
* `returns` **{String}**
|
|
503
|
-
|
|
504
|
-
**Example**
|
|
505
|
-
|
|
506
|
-
```html
|
|
507
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
508
|
-
{{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
|
|
509
|
-
<!-- results in: 'BBB' -->
|
|
510
|
-
```
|
|
511
|
-
|
|
512
|
-
### [{{first}}](lib/array.js#L142)
|
|
513
|
-
|
|
514
|
-
Returns the first item, or first `n` items of an array.
|
|
515
|
-
|
|
516
|
-
**Params**
|
|
517
|
-
|
|
518
|
-
* `array` **{Array}**
|
|
519
|
-
* `n` **{Number}**: Number of items to return, starting at `0`.
|
|
520
|
-
* `returns` **{Array}**
|
|
521
|
-
|
|
522
|
-
**Example**
|
|
523
|
-
|
|
524
|
-
```html
|
|
525
|
-
{{first "['a', 'b', 'c', 'd', 'e']" 2}}
|
|
526
|
-
<!-- results in: '["a", "b"]' -->
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
### [{{forEach}}](lib/array.js#L184)
|
|
530
|
-
|
|
531
|
-
Iterates over each item in an array and exposes the current item in the array as context to the inner block. In addition to the current array item, the helper exposes the following variables to the inner block:
|
|
532
|
-
|
|
533
|
-
* `index`
|
|
534
|
-
* `total`
|
|
535
|
-
* `isFirst`
|
|
536
|
-
* `isLast`
|
|
537
|
-
Also, `@index` is exposed as a private variable, and additional
|
|
538
|
-
private variables may be defined as hash arguments.
|
|
539
|
-
|
|
540
|
-
**Params**
|
|
541
|
-
|
|
542
|
-
* `array` **{Array}**
|
|
543
|
-
* `returns` **{String}**
|
|
544
|
-
|
|
545
|
-
**Example**
|
|
546
|
-
|
|
547
|
-
```html
|
|
548
|
-
<!-- accounts = [
|
|
549
|
-
{'name': 'John', 'email': 'john@example.com'},
|
|
550
|
-
{'name': 'Malcolm', 'email': 'malcolm@example.com'},
|
|
551
|
-
{'name': 'David', 'email': 'david@example.com'}
|
|
552
|
-
] -->
|
|
553
|
-
|
|
554
|
-
{{#forEach accounts}}
|
|
555
|
-
<a href="mailto:{{ email }}" title="Send an email to {{ name }}">
|
|
556
|
-
{{ name }}
|
|
557
|
-
</a>{{#unless isLast}}, {{/unless}}
|
|
558
|
-
{{/forEach}}
|
|
559
|
-
```
|
|
560
|
-
|
|
561
|
-
### [{{inArray}}](lib/array.js#L224)
|
|
562
|
-
|
|
563
|
-
Block helper that renders the block if an array has the given `value`. Optionally specify an inverse block to render when the array does not have the given value.
|
|
564
|
-
|
|
565
|
-
**Params**
|
|
566
|
-
|
|
567
|
-
* `array` **{Array}**
|
|
568
|
-
* `value` **{any}**
|
|
569
|
-
* `options` **{Object}**
|
|
570
|
-
* `returns` **{String}**
|
|
571
|
-
|
|
572
|
-
**Example**
|
|
573
|
-
|
|
574
|
-
```html
|
|
575
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
576
|
-
{{#inArray array "d"}}
|
|
577
|
-
foo
|
|
578
|
-
{{else}}
|
|
579
|
-
bar
|
|
580
|
-
{{/inArray}}
|
|
581
|
-
<!-- results in: 'bar' -->
|
|
582
|
-
```
|
|
583
|
-
|
|
584
|
-
### [{{isArray}}](lib/array.js#L244)
|
|
585
|
-
|
|
586
|
-
Returns true if `value` is an es5 array.
|
|
587
|
-
|
|
588
|
-
**Params**
|
|
589
|
-
|
|
590
|
-
* `value` **{any}**: The value to test.
|
|
591
|
-
* `returns` **{Boolean}**
|
|
592
|
-
|
|
593
|
-
**Example**
|
|
594
|
-
|
|
595
|
-
```html
|
|
596
|
-
{{isArray "abc"}}
|
|
597
|
-
<!-- results in: false -->
|
|
598
|
-
|
|
599
|
-
<!-- array: [1, 2, 3] -->
|
|
600
|
-
{{isArray array}}
|
|
601
|
-
<!-- results in: true -->
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
### [{{itemAt}}](lib/array.js#L263)
|
|
605
|
-
|
|
606
|
-
Returns the item from `array` at index `idx`.
|
|
607
|
-
|
|
608
|
-
**Params**
|
|
609
|
-
|
|
610
|
-
* `array` **{Array}**
|
|
611
|
-
* `idx` **{Number}**
|
|
612
|
-
* `returns` **{any}** `value`
|
|
613
|
-
|
|
614
|
-
**Example**
|
|
615
|
-
|
|
616
|
-
```html
|
|
617
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
618
|
-
{{itemAt array 1}}
|
|
619
|
-
<!-- results in: 'b' -->
|
|
620
|
-
```
|
|
621
|
-
|
|
622
|
-
### [{{join}}](lib/array.js#L294)
|
|
623
|
-
|
|
624
|
-
Join all elements of array into a string, optionally using a given separator.
|
|
625
|
-
|
|
626
|
-
**Params**
|
|
627
|
-
|
|
628
|
-
* `array` **{Array}**
|
|
629
|
-
* `separator` **{String}**: The separator to use. Defaults to `,`.
|
|
630
|
-
* `returns` **{String}**
|
|
631
|
-
|
|
632
|
-
**Example**
|
|
633
|
-
|
|
634
|
-
```html
|
|
635
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
636
|
-
{{join array}}
|
|
637
|
-
<!-- results in: 'a, b, c' -->
|
|
638
|
-
|
|
639
|
-
{{join array '-'}}
|
|
640
|
-
<!-- results in: 'a-b-c' -->
|
|
641
|
-
```
|
|
642
|
-
### [{{equalsLength}}](lib/array.js#L313)
|
|
643
|
-
|
|
644
|
-
Returns true if the the length of the given `value` is equal
|
|
645
|
-
to the given `length`. Can be used as a block or inline helper.
|
|
646
|
-
|
|
647
|
-
**Params**
|
|
648
|
-
|
|
649
|
-
* `value` **{Array|String}**
|
|
650
|
-
* `length` **{Number}**
|
|
651
|
-
* `options` **{Object}**
|
|
652
|
-
* `returns` **{String}**
|
|
653
|
-
|
|
654
|
-
### [{{last}}](lib/array.js#L349)
|
|
655
|
-
|
|
656
|
-
Returns the last item, or last `n` items of an array or string. Opposite of [first](#first).
|
|
657
|
-
|
|
658
|
-
**Params**
|
|
659
|
-
|
|
660
|
-
* `value` **{Array|String}**: Array or string.
|
|
661
|
-
* `n` **{Number}**: Number of items to return from the end of the array.
|
|
662
|
-
* `returns` **{Array}**
|
|
663
|
-
|
|
664
|
-
**Example**
|
|
665
|
-
|
|
666
|
-
```html
|
|
667
|
-
<!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
|
|
668
|
-
|
|
669
|
-
{{last value}}
|
|
670
|
-
<!-- results in: ['e'] -->
|
|
671
|
-
|
|
672
|
-
{{last value 2}}
|
|
673
|
-
<!-- results in: ['d', 'e'] -->
|
|
674
|
-
|
|
675
|
-
{{last value 3}}
|
|
676
|
-
<!-- results in: ['c', 'd', 'e'] -->
|
|
677
|
-
```
|
|
678
|
-
|
|
679
|
-
### [{{length}}](lib/array.js#L379)
|
|
680
|
-
|
|
681
|
-
Returns the length of the given string or array.
|
|
682
366
|
|
|
683
|
-
**Params**
|
|
684
|
-
|
|
685
|
-
* `value` **{Array|Object|String}**
|
|
686
|
-
* `returns` **{Number}**: The length of the value.
|
|
687
|
-
|
|
688
|
-
**Example**
|
|
689
|
-
|
|
690
|
-
```html
|
|
691
|
-
{{length '["a", "b", "c"]'}}
|
|
692
|
-
<!-- results in: 3 -->
|
|
693
|
-
|
|
694
|
-
<!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
|
|
695
|
-
{{length myArray}}
|
|
696
|
-
<!-- results in: 5 -->
|
|
697
|
-
|
|
698
|
-
<!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
|
|
699
|
-
{{length myObject}}
|
|
700
|
-
<!-- results in: 2 -->
|
|
701
|
-
```
|
|
702
|
-
|
|
703
|
-
### [{{lengthEqual}}](lib/array.js#L395)
|
|
704
|
-
|
|
705
|
-
Alias for [equalsLength](#equalsLength)
|
|
706
|
-
|
|
707
|
-
### [{{map}}](lib/array.js#L414)
|
|
708
|
-
|
|
709
|
-
Returns a new array, created by calling `function` on each element of the given `array`. For example,
|
|
710
|
-
|
|
711
|
-
**Params**
|
|
712
|
-
|
|
713
|
-
* `array` **{Array}**
|
|
714
|
-
* `fn` **{Function}**
|
|
715
|
-
* `returns` **{String}**
|
|
716
|
-
|
|
717
|
-
**Example**
|
|
718
|
-
|
|
719
|
-
```html
|
|
720
|
-
<!-- array: ['a', 'b', 'c'], and "double" is a
|
|
721
|
-
fictitious function that duplicates letters -->
|
|
722
|
-
{{map array double}}
|
|
723
|
-
<!-- results in: '["aa", "bb", "cc"]' -->
|
|
724
|
-
```
|
|
725
|
-
|
|
726
|
-
### [{{pluck}}](lib/array.js#L445)
|
|
727
|
-
|
|
728
|
-
Map over the given object or array or objects and create an array of values from the given `prop`. Dot-notation may be used (as a string) to get nested properties.
|
|
729
|
-
|
|
730
|
-
**Params**
|
|
731
|
-
|
|
732
|
-
* `collection` **{Array|Object}**
|
|
733
|
-
* `prop` **{Function}**
|
|
734
|
-
* `returns` **{String}**
|
|
735
|
-
|
|
736
|
-
**Example**
|
|
737
|
-
|
|
738
|
-
```html
|
|
739
|
-
// {{pluck items "data.title"}}
|
|
740
|
-
<!-- results in: '["aa", "bb", "cc"]' -->
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
### [{{reverse}}](lib/array.js#L473)
|
|
744
|
-
|
|
745
|
-
Reverse the elements in an array, or the characters in a string.
|
|
746
|
-
|
|
747
|
-
**Params**
|
|
748
|
-
|
|
749
|
-
* `value` **{Array|String}**
|
|
750
|
-
* `returns` **{Array|String}**: Returns the reversed string or array.
|
|
751
|
-
|
|
752
|
-
**Example**
|
|
753
|
-
|
|
754
|
-
```html
|
|
755
|
-
<!-- value: 'abcd' -->
|
|
756
|
-
{{reverse value}}
|
|
757
|
-
<!-- results in: 'dcba' -->
|
|
758
|
-
<!-- value: ['a', 'b', 'c', 'd'] -->
|
|
759
|
-
{{reverse value}}
|
|
760
|
-
<!-- results in: ['d', 'c', 'b', 'a'] -->
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
### [{{some}}](lib/array.js#L504)
|
|
764
|
-
|
|
765
|
-
Block helper that returns the block if the callback returns true for some value in the given array.
|
|
766
|
-
|
|
767
|
-
**Params**
|
|
768
|
-
|
|
769
|
-
* `array` **{Array}**
|
|
770
|
-
* `iter` **{Function}**: Iteratee
|
|
771
|
-
* **{Options}**: Handlebars provided options object
|
|
772
|
-
* `returns` **{String}**
|
|
773
|
-
|
|
774
|
-
**Example**
|
|
775
|
-
|
|
776
|
-
```html
|
|
777
|
-
<!-- array: [1, 'b', 3] -->
|
|
778
|
-
{{#some array isString}}
|
|
779
|
-
Render me if the array has a string.
|
|
780
|
-
{{else}}
|
|
781
|
-
Render me if it doesn't.
|
|
782
|
-
{{/some}}
|
|
783
|
-
<!-- results in: 'Render me if the array has a string.' -->
|
|
784
|
-
```
|
|
785
|
-
|
|
786
|
-
### [{{sort}}](lib/array.js#L532)
|
|
787
|
-
|
|
788
|
-
Sort the given `array`. If an array of objects is passed, you may optionally pass a `key` to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
|
|
789
|
-
|
|
790
|
-
**Params**
|
|
791
|
-
|
|
792
|
-
* `array` **{Array}**: the array to sort.
|
|
793
|
-
* `key` **{String|Function}**: The object key to sort by, or sorting function.
|
|
794
|
-
|
|
795
|
-
**Example**
|
|
796
|
-
|
|
797
|
-
```html
|
|
798
|
-
<!-- array: ['b', 'a', 'c'] -->
|
|
799
|
-
{{sort array}}
|
|
800
|
-
<!-- results in: '["a", "b", "c"]' -->
|
|
801
|
-
```
|
|
802
|
-
|
|
803
|
-
### [{{sortBy}}](lib/array.js#L557)
|
|
804
|
-
|
|
805
|
-
Sort an `array`. If an array of objects is passed, you may optionally pass a `key` to sort on as the second argument. You may alternatively pass a sorting function as the second argument.
|
|
806
|
-
|
|
807
|
-
**Params**
|
|
808
|
-
|
|
809
|
-
* `array` **{Array}**: the array to sort.
|
|
810
|
-
* `props` **{String|Function}**: One or more properties to sort by, or sorting functions to use.
|
|
811
|
-
|
|
812
|
-
**Example**
|
|
813
|
-
|
|
814
|
-
```html
|
|
815
|
-
<!-- array: [{a: 'zzz'}, {a: 'aaa'}] -->
|
|
816
|
-
{{sortBy array "a"}}
|
|
817
|
-
<!-- results in: '[{"a":"aaa"}, {"a":"zzz"}]' -->
|
|
818
|
-
```
|
|
819
|
-
|
|
820
|
-
### [{{withAfter}}](lib/array.js#L588)
|
|
821
|
-
|
|
822
|
-
Use the items in the array _after_ the specified index as context inside a block. Opposite of [withBefore](#withBefore).
|
|
823
|
-
|
|
824
|
-
**Params**
|
|
825
|
-
|
|
826
|
-
* `array` **{Array}**
|
|
827
|
-
* `idx` **{Number}**
|
|
828
|
-
* `options` **{Object}**
|
|
829
|
-
* `returns` **{Array}**
|
|
830
|
-
|
|
831
|
-
**Example**
|
|
832
|
-
|
|
833
|
-
```html
|
|
834
|
-
<!-- array: ['a', 'b', 'c', 'd', 'e'] -->
|
|
835
|
-
{{#withAfter array 3}}
|
|
836
|
-
{{this}}
|
|
837
|
-
{{/withAfter}}
|
|
838
|
-
<!-- results in: "de" -->
|
|
839
|
-
```
|
|
840
|
-
|
|
841
|
-
### [{{withBefore}}](lib/array.js#L618)
|
|
842
|
-
|
|
843
|
-
Use the items in the array _before_ the specified index as context inside a block. Opposite of [withAfter](#withAfter).
|
|
844
|
-
|
|
845
|
-
**Params**
|
|
846
|
-
|
|
847
|
-
* `array` **{Array}**
|
|
848
|
-
* `idx` **{Number}**
|
|
849
|
-
* `options` **{Object}**
|
|
850
|
-
* `returns` **{Array}**
|
|
851
|
-
|
|
852
|
-
**Example**
|
|
853
|
-
|
|
854
|
-
```html
|
|
855
|
-
<!-- array: ['a', 'b', 'c', 'd', 'e'] -->
|
|
856
|
-
{{#withBefore array 3}}
|
|
857
|
-
{{this}}
|
|
858
|
-
{{/withBefore}}
|
|
859
|
-
<!-- results in: 'ab' -->
|
|
860
|
-
```
|
|
861
|
-
|
|
862
|
-
### [{{withFirst}}](lib/array.js#L648)
|
|
863
|
-
|
|
864
|
-
Use the first item in a collection inside a handlebars block expression. Opposite of [withLast](#withLast).
|
|
865
|
-
|
|
866
|
-
**Params**
|
|
867
|
-
|
|
868
|
-
* `array` **{Array}**
|
|
869
|
-
* `idx` **{Number}**
|
|
870
|
-
* `options` **{Object}**
|
|
871
|
-
* `returns` **{String}**
|
|
872
|
-
|
|
873
|
-
**Example**
|
|
874
|
-
|
|
875
|
-
```html
|
|
876
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
877
|
-
{{#withFirst array}}
|
|
878
|
-
{{this}}
|
|
879
|
-
{{/withFirst}}
|
|
880
|
-
<!-- results in: 'a' -->
|
|
881
|
-
```
|
|
882
|
-
|
|
883
|
-
### [{{withGroup}}](lib/array.js#L692)
|
|
884
|
-
|
|
885
|
-
Block helper that groups array elements by given group `size`.
|
|
886
|
-
|
|
887
|
-
**Params**
|
|
888
|
-
|
|
889
|
-
* `array` **{Array}**: The array to iterate over
|
|
890
|
-
* `size` **{Number}**: The desired length of each array "group"
|
|
891
|
-
* `options` **{Object}**: Handlebars options
|
|
892
|
-
* `returns` **{String}**
|
|
893
|
-
|
|
894
|
-
**Example**
|
|
895
|
-
|
|
896
|
-
```html
|
|
897
|
-
<!-- array: ['a','b','c','d','e','f','g','h'] -->
|
|
898
|
-
{{#withGroup array 4}}
|
|
899
|
-
{{#each this}}
|
|
900
|
-
{{.}}
|
|
901
|
-
{{each}}
|
|
902
|
-
<br>
|
|
903
|
-
{{/withGroup}}
|
|
904
|
-
<!-- results in: -->
|
|
905
|
-
<!-- 'a','b','c','d'<br> -->
|
|
906
|
-
<!-- 'e','f','g','h'<br> -->
|
|
907
|
-
```
|
|
908
|
-
|
|
909
|
-
### [{{withLast}}](lib/array.js#L727)
|
|
910
|
-
|
|
911
|
-
Use the last item or `n` items in an array as context inside a block. Opposite of [withFirst](#withFirst).
|
|
912
|
-
|
|
913
|
-
**Params**
|
|
914
|
-
|
|
915
|
-
* `array` **{Array}**
|
|
916
|
-
* `idx` **{Number}**: The starting index.
|
|
917
|
-
* `options` **{Object}**
|
|
918
|
-
* `returns` **{String}**
|
|
919
|
-
|
|
920
|
-
**Example**
|
|
921
|
-
|
|
922
|
-
```html
|
|
923
|
-
<!-- array: ['a', 'b', 'c'] -->
|
|
924
|
-
{{#withLast array}}
|
|
925
|
-
{{this}}
|
|
926
|
-
{{/withLast}}
|
|
927
|
-
<!-- results in: 'c' -->
|
|
928
|
-
```
|
|
929
|
-
|
|
930
|
-
### [{{withSort}}](lib/array.js#L766)
|
|
931
|
-
|
|
932
|
-
Block helper that sorts a collection and exposes the sorted collection as context inside the block.
|
|
933
|
-
|
|
934
|
-
**Params**
|
|
935
|
-
|
|
936
|
-
* `array` **{Array}**
|
|
937
|
-
* `prop` **{String}**
|
|
938
|
-
* `options` **{Object}**: Specify `reverse="true"` to reverse the array.
|
|
939
|
-
* `returns` **{String}**
|
|
940
|
-
|
|
941
|
-
**Example**
|
|
942
|
-
|
|
943
|
-
```html
|
|
944
|
-
<!-- array: ['b', 'a', 'c'] -->
|
|
945
|
-
{{#withSort array}}{{this}}{{/withSort}}
|
|
946
|
-
<!-- results in: 'abc' -->
|
|
947
|
-
```
|
|
948
|
-
|
|
949
|
-
### [{{unique}}](lib/array.js#L816)
|
|
950
|
-
|
|
951
|
-
Block helper that return an array with all duplicate values removed. Best used along with a [each](#each) helper.
|
|
952
|
-
|
|
953
|
-
**Params**
|
|
954
|
-
|
|
955
|
-
* `array` **{Array}**
|
|
956
|
-
* `options` **{Object}**
|
|
957
|
-
* `returns` **{Array}**
|
|
958
|
-
|
|
959
|
-
**Example**
|
|
960
|
-
|
|
961
|
-
```html
|
|
962
|
-
<!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
|
|
963
|
-
{{#each (unique array)}}{{.}}{{/each}}
|
|
964
|
-
<!-- results in: 'acbe' -->
|
|
965
|
-
```
|
|
966
367
|
|
|
967
368
|
### [{{embed}}](lib/code.js#L23)
|
|
968
369
|
|
package/dist/index.js
CHANGED
|
@@ -2031,8 +2031,8 @@ var require_helpers = __commonJS({
|
|
|
2031
2031
|
});
|
|
2032
2032
|
|
|
2033
2033
|
// src/index.ts
|
|
2034
|
-
var
|
|
2035
|
-
__export(
|
|
2034
|
+
var index_exports = {};
|
|
2035
|
+
__export(index_exports, {
|
|
2036
2036
|
Handlebars: () => Handlebars,
|
|
2037
2037
|
HelperRegistry: () => HelperRegistry,
|
|
2038
2038
|
createHandlebars: () => createHandlebars,
|
|
@@ -2040,16 +2040,36 @@ __export(src_exports, {
|
|
|
2040
2040
|
handlebars: () => handlebars,
|
|
2041
2041
|
helpers: () => helpers2
|
|
2042
2042
|
});
|
|
2043
|
-
module.exports = __toCommonJS(
|
|
2043
|
+
module.exports = __toCommonJS(index_exports);
|
|
2044
2044
|
var HandlebarsLib = __toESM(require("handlebars"));
|
|
2045
2045
|
|
|
2046
2046
|
// src/helpers/date.ts
|
|
2047
|
+
var import_chrono_node = require("chrono-node");
|
|
2048
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
2047
2049
|
var year = () => (/* @__PURE__ */ new Date()).getFullYear().toString();
|
|
2050
|
+
var date = (humanReadableDate, formatString) => {
|
|
2051
|
+
const parsedDate = (0, import_chrono_node.parseDate)(humanReadableDate);
|
|
2052
|
+
if (!parsedDate) {
|
|
2053
|
+
throw new Error(`Unable to parse date: ${humanReadableDate}`);
|
|
2054
|
+
}
|
|
2055
|
+
return (0, import_dayjs.default)(parsedDate).format(formatString);
|
|
2056
|
+
};
|
|
2048
2057
|
var helpers = [
|
|
2049
2058
|
{
|
|
2050
2059
|
name: "year",
|
|
2051
2060
|
category: "date",
|
|
2052
2061
|
fn: year
|
|
2062
|
+
},
|
|
2063
|
+
{
|
|
2064
|
+
name: "date",
|
|
2065
|
+
category: "date",
|
|
2066
|
+
fn: date
|
|
2067
|
+
},
|
|
2068
|
+
{
|
|
2069
|
+
/* Adding this in for legacy support */
|
|
2070
|
+
name: "moment",
|
|
2071
|
+
category: "date",
|
|
2072
|
+
fn: date
|
|
2053
2073
|
}
|
|
2054
2074
|
];
|
|
2055
2075
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaredwray/fumanchu",
|
|
3
3
|
"description": "Handlebars + Helpers = Fumanchu",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.4",
|
|
5
5
|
"homepage": "https://github.com/jaredwray/fumanchu",
|
|
6
6
|
"author": "Jared Wray (me@jaredwray.com)",
|
|
7
7
|
"source": "dist/index.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "xo --fix && vitest run --coverage",
|
|
12
12
|
"test:ci": "xo && vitest run --coverage",
|
|
13
|
+
"test:all": "npm run test && npm run test:legacy",
|
|
13
14
|
"test:legacy": "npm run build && c8 mocha",
|
|
14
15
|
"test:legacy:ci": "npm run build && c8 --reporter=lcov mocha",
|
|
15
16
|
"build": "rimraf ./dist && tsup ./src/index.ts --format cjs --dts --clean",
|
|
@@ -58,10 +59,12 @@
|
|
|
58
59
|
"dependencies": {
|
|
59
60
|
"arr-flatten": "^1.1.0",
|
|
60
61
|
"array-sort": "^1.0.0",
|
|
61
|
-
"cacheable": "^1.8.
|
|
62
|
+
"cacheable": "^1.8.10",
|
|
63
|
+
"chrono-node": "^2.8.0",
|
|
62
64
|
"create-frame": "^1.0.0",
|
|
65
|
+
"dayjs": "^1.11.13",
|
|
63
66
|
"define-property": "^2.0.2",
|
|
64
|
-
"ent": "^2.2.
|
|
67
|
+
"ent": "^2.2.2",
|
|
65
68
|
"extend-shallow": "^3.0.2",
|
|
66
69
|
"for-in": "^1.0.2",
|
|
67
70
|
"for-own": "^1.0.0",
|
|
@@ -73,7 +76,7 @@
|
|
|
73
76
|
"handlebars-utils": "^1.0.6",
|
|
74
77
|
"has-value": "^2.0.2",
|
|
75
78
|
"helper-date": "^1.0.1",
|
|
76
|
-
"highlight.js": "^11.
|
|
79
|
+
"highlight.js": "^11.11.1",
|
|
77
80
|
"html-tag": "^2.0.0",
|
|
78
81
|
"is-even": "^1.0.0",
|
|
79
82
|
"is-glob": "^4.0.3",
|
|
@@ -90,20 +93,20 @@
|
|
|
90
93
|
"year": "^0.2.1"
|
|
91
94
|
},
|
|
92
95
|
"devDependencies": {
|
|
93
|
-
"@vitest/coverage-v8": "^
|
|
94
|
-
"c8": "^10.1.
|
|
96
|
+
"@vitest/coverage-v8": "^3.1.1",
|
|
97
|
+
"c8": "^10.1.3",
|
|
95
98
|
"chai": "^4.3.10",
|
|
96
|
-
"docula": "^0.
|
|
99
|
+
"docula": "^0.11.0",
|
|
97
100
|
"engine-handlebars": "^1.1.0",
|
|
98
101
|
"lodash": "^4.17.21",
|
|
99
102
|
"mocha": "^10.8.2",
|
|
100
103
|
"rimraf": "^6.0.1",
|
|
101
104
|
"template-helpers": "^1.0.1",
|
|
102
105
|
"templates": "^1.2.9",
|
|
103
|
-
"tsup": "^8.
|
|
106
|
+
"tsup": "^8.4.0",
|
|
104
107
|
"typecript": "^0.0.1-security",
|
|
105
|
-
"typescript": "^5.
|
|
106
|
-
"vitest": "^
|
|
108
|
+
"typescript": "^5.8.3",
|
|
109
|
+
"vitest": "^3.1.1",
|
|
107
110
|
"xo": "^0.60.0"
|
|
108
111
|
},
|
|
109
112
|
"xo": {
|