@jaredwray/fumanchu 2.0.0 → 3.0.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/README.md +47 -16
- package/dist/index.d.ts +26 -0
- package/dist/index.js +2073 -0
- package/package.json +14 -20
- package/helpers.js +0 -61
- package/index.d.ts +0 -4
- package/index.js +0 -8
- package/index.mjs +0 -16
- package/lib/array.js +0 -822
- package/lib/code.js +0 -80
- package/lib/collection.js +0 -67
- package/lib/comparison.js +0 -604
- package/lib/date.js +0 -24
- package/lib/fs.js +0 -75
- package/lib/html.js +0 -218
- package/lib/i18n.js +0 -48
- package/lib/index.js +0 -24
- package/lib/inflection.js +0 -78
- package/lib/logging.js +0 -8
- package/lib/markdown.js +0 -99
- package/lib/match.js +0 -61
- package/lib/math.js +0 -285
- package/lib/md.js +0 -119
- package/lib/misc.js +0 -77
- package/lib/number.js +0 -204
- package/lib/object.js +0 -290
- package/lib/path.js +0 -181
- package/lib/regex.js +0 -50
- package/lib/string.js +0 -769
- package/lib/url.js +0 -132
- package/lib/utils/falsey.js +0 -46
- package/lib/utils/html.js +0 -82
- package/lib/utils/index.js +0 -91
- package/lib/utils/utils.js +0 -42
package/README.md
CHANGED
|
@@ -12,64 +12,95 @@ Handlebars + Helpers Together
|
|
|
12
12
|
|
|
13
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 in your nodejs as it is a drop in replacement when using handlebars directly.
|
|
14
14
|
|
|
15
|
-
|
|
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
|
+
- **(In Progress)** Migrate to Typescript with full typing support
|
|
18
|
+
- **(In Progress)** Replace module dependencies that are no longer supported with supported ones
|
|
19
|
+
- Migration to ESM and CJS support using cross compatible code
|
|
20
|
+
- Migration to `vitest` as a testing framework
|
|
21
|
+
- Migration to `xo` as a linting framework
|
|
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 })`
|
|
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 })` 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.
|
|
35
|
+
|
|
36
|
+
# Table of Contents
|
|
16
37
|
* [Using in Nodejs](#using-in-nodejs)
|
|
17
38
|
* [Just using Handlebar Helpers](#using-handlebars-helpers)
|
|
18
39
|
* [Helpers](#helpers)
|
|
19
40
|
* [How to Contribute](#how-to-contribute)
|
|
20
41
|
* [License and Copyright](#license-and-copyright)
|
|
21
42
|
|
|
22
|
-
|
|
43
|
+
|
|
44
|
+
# Usage Nodejs
|
|
23
45
|
|
|
24
46
|
```bash
|
|
25
47
|
npm install @jaredwray/fumanchu --save
|
|
26
48
|
```
|
|
27
49
|
|
|
28
50
|
```javascript
|
|
29
|
-
var handlebars = require('@jaredwray/fumanchu');
|
|
51
|
+
var {handlebars, helpers} = require('@jaredwray/fumanchu');
|
|
52
|
+
helpers({ handlebars: handlebars });
|
|
30
53
|
var template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
31
54
|
var html = template({foo: 'bar'});
|
|
32
55
|
console.log(html);
|
|
33
56
|
```
|
|
34
57
|
|
|
35
|
-
If using it with es6 you can access `handlebars`
|
|
58
|
+
If using it with es6 you can access `handlebars` and `helpers`:
|
|
36
59
|
|
|
37
60
|
```javascript
|
|
38
|
-
import handlebars from '@jaredwray/fumanchu';
|
|
61
|
+
import {handlebars, helpers} from '@jaredwray/fumanchu';
|
|
62
|
+
helpers({ handlebars: handlebars });
|
|
39
63
|
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
40
64
|
const html = template({foo: 'bar'});
|
|
41
65
|
console.log(html);
|
|
42
66
|
```
|
|
43
67
|
|
|
68
|
+
If you want to just get an instance of handlebars via `createHandlebars` you can do the following **(it is async)**:
|
|
69
|
+
|
|
70
|
+
```javascript
|
|
71
|
+
import {createHandlebars} from '@jaredwray/fumanchu';
|
|
72
|
+
const handlebars = await createHandlebars(); //this will return a handlebars instance with all helpers
|
|
73
|
+
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
74
|
+
const html = template({foo: 'bar'});
|
|
75
|
+
console.log(html); // <p>Foo is bar</p>
|
|
76
|
+
```
|
|
77
|
+
|
|
44
78
|
It's just that easy! No need to add Handlebars to your project, it's already included.
|
|
45
79
|
|
|
46
|
-
|
|
80
|
+
# Using Handlebars Helpers
|
|
47
81
|
|
|
48
82
|
If you only want to use handlebar helpers you can easily do that by doing the following:
|
|
49
83
|
|
|
50
84
|
```javascript
|
|
51
|
-
var helpers = require('@jaredwray/fumanchu')
|
|
85
|
+
var {helpers} = require('@jaredwray/fumanchu');
|
|
52
86
|
var handlebars = require('handlebars');
|
|
53
87
|
helpers({ handlebars: handlebars });
|
|
54
88
|
var fn = handlebars.compile('{{add value 5}}');
|
|
55
|
-
console.log(fn);
|
|
89
|
+
console.log(fn); // 10
|
|
56
90
|
```
|
|
57
91
|
|
|
58
92
|
If using it with es6 you can access `helpers` via destructuring:
|
|
59
93
|
|
|
60
94
|
```javascript
|
|
61
|
-
import
|
|
95
|
+
import {helpers} from '@jaredwray/fumanchu';
|
|
62
96
|
import handlebars from 'handlebars';
|
|
63
|
-
|
|
64
|
-
handlebarHelpers({ handlebars: handlebars });
|
|
97
|
+
helpers({ handlebars: handlebars });
|
|
65
98
|
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
66
99
|
const html = template({foo: 'bar'});
|
|
67
|
-
console.log(html);
|
|
100
|
+
console.log(html); // <p>Foo is bar</p>
|
|
68
101
|
```
|
|
69
102
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
## Helpers
|
|
103
|
+
# Helpers
|
|
73
104
|
More than 180 Handlebars helpers in ~20 categories. Helpers can be used with Assemble, Generate, Verb, Ghost, gulp-handlebars, grunt-handlebars, consolidate, or any node.js/Handlebars project.
|
|
74
105
|
|
|
75
106
|
## Categories
|
|
@@ -97,7 +128,7 @@ Currently **189 helpers** in **20 categories**:
|
|
|
97
128
|
* **[string](#string)** ([code](lib/string.js) | [unit tests](test/string.js))
|
|
98
129
|
* **[url](#url)** ([code](lib/url.js) | [unit tests](test/url.js))
|
|
99
130
|
|
|
100
|
-
|
|
131
|
+
# All helpers
|
|
101
132
|
|
|
102
133
|
### [array helpers](#array)
|
|
103
134
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as HandlebarsLib from 'handlebars';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handlebars library not initiated with helpers
|
|
5
|
+
* @type {Handlebars}
|
|
6
|
+
*/
|
|
7
|
+
declare const Handlebars: typeof HandlebarsLib;
|
|
8
|
+
/**
|
|
9
|
+
* Fumanchu Handlebars instance not initiated with helpers
|
|
10
|
+
* @type {Handlebars}
|
|
11
|
+
*/
|
|
12
|
+
declare const handlebars: typeof HandlebarsLib;
|
|
13
|
+
/**
|
|
14
|
+
* Fumanchu Handlebars helpers
|
|
15
|
+
*/
|
|
16
|
+
declare const helpers: {
|
|
17
|
+
(groups: any, options: any): any;
|
|
18
|
+
utils: any;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Create a new Handlebars instance with Fumanchu helpers
|
|
22
|
+
* @returns {Promise<Handlebars>}
|
|
23
|
+
*/
|
|
24
|
+
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
|
|
25
|
+
|
|
26
|
+
export { Handlebars, createHandlebars, handlebars, helpers };
|