@jaredwray/fumanchu 2.1.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -16
- package/dist/index.d.ts +64 -0
- package/dist/index.js +2135 -0
- package/package.json +87 -68
- package/site/logo.svg +19 -0
- package/helpers.js +0 -61
- package/index.d.ts +0 -4
- package/index.js +0 -8
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
# fumanchu
|
|
@@ -12,63 +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
|
+
- **(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 })`
|
|
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
|
-
|
|
97
|
+
helpers({ handlebars: handlebars });
|
|
64
98
|
const template = handlebars.compile('{{#if (eq foo "bar")}}<p>Foo is bar</p>{{/if}}');
|
|
65
99
|
const html = template({foo: 'bar'});
|
|
66
|
-
console.log(html);
|
|
100
|
+
console.log(html); // <p>Foo is bar</p>
|
|
67
101
|
```
|
|
68
102
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
## Helpers
|
|
103
|
+
# Helpers
|
|
72
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.
|
|
73
105
|
|
|
74
106
|
## Categories
|
|
@@ -96,7 +128,7 @@ Currently **189 helpers** in **20 categories**:
|
|
|
96
128
|
* **[string](#string)** ([code](lib/string.js) | [unit tests](test/string.js))
|
|
97
129
|
* **[url](#url)** ([code](lib/url.js) | [unit tests](test/url.js))
|
|
98
130
|
|
|
99
|
-
|
|
131
|
+
# All helpers
|
|
100
132
|
|
|
101
133
|
### [array helpers](#array)
|
|
102
134
|
|
|
@@ -3066,6 +3098,8 @@ Generate a random number
|
|
|
3066
3098
|
## How to Contribute
|
|
3067
3099
|
clone the repository locally and run 'npm i' in the root. Now that you've set up your workspace, you're ready to contribute changes to the `fumanchu` repository you can refer to the [CONTRIBUTING](CONTRIBUTING.md) guide. If you have any questions please feel free to ask by creating an issue and label it `question`.
|
|
3068
3100
|
|
|
3101
|
+
To test the legacy helpers, you can run `npm run test:legacy` to run the tests. If you want to test the new helpers, you can run `npm run test`.
|
|
3102
|
+
|
|
3069
3103
|
## License and Copyright
|
|
3070
3104
|
[MIT](LICENSE) and codebase after 2023 will be copyright of Jared Wray.
|
|
3071
3105
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import * as HandlebarsLib from 'handlebars';
|
|
2
|
+
|
|
3
|
+
declare enum HelperRegistryCompatibility {
|
|
4
|
+
NODEJS = "nodejs",
|
|
5
|
+
BROWSER = "browser"
|
|
6
|
+
}
|
|
7
|
+
type HelperFilter = {
|
|
8
|
+
name?: string;
|
|
9
|
+
category?: string;
|
|
10
|
+
compatibility?: HelperRegistryCompatibility;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Handlebars library not initiated with helpers
|
|
15
|
+
* @type {Handlebars}
|
|
16
|
+
*/
|
|
17
|
+
declare const Handlebars: typeof HandlebarsLib;
|
|
18
|
+
/**
|
|
19
|
+
* Fumanchu Handlebars instance not initiated with helpers
|
|
20
|
+
* @type {Handlebars}
|
|
21
|
+
*/
|
|
22
|
+
declare const handlebars: typeof HandlebarsLib;
|
|
23
|
+
/**
|
|
24
|
+
* Fumanchu Handlebars helpers
|
|
25
|
+
*/
|
|
26
|
+
declare const helpers: {
|
|
27
|
+
(groups: any, options: any): any;
|
|
28
|
+
utils: any;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Create a new Handlebars instance with Fumanchu helpers
|
|
32
|
+
* @returns {Promise<Handlebars>}
|
|
33
|
+
*/
|
|
34
|
+
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
|
|
35
|
+
/**
|
|
36
|
+
* @typedef {Object} FumanchuCachingOptions
|
|
37
|
+
* @property {number|string} [ttl] - Time to Live - If you set a number it is miliseconds, if you set a string it is a human-readable
|
|
38
|
+
* format such as `1s` for 1 second or `1h` for 1 hour. Setting undefined means that it will use the default time-to-live. If both are
|
|
39
|
+
* undefined then it will not have a time-to-live.
|
|
40
|
+
* @property {boolean} [useClone] - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
41
|
+
* @property {number} [lruSize] - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
42
|
+
* @property {number} [checkInterval] - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
43
|
+
*/
|
|
44
|
+
type FumanchuCachingOptions = {
|
|
45
|
+
ttl?: number | string;
|
|
46
|
+
useClone?: boolean;
|
|
47
|
+
lruSize?: number;
|
|
48
|
+
checkInterval?: number;
|
|
49
|
+
};
|
|
50
|
+
type FumanchuOptions = {
|
|
51
|
+
handlebars?: typeof HandlebarsLib;
|
|
52
|
+
helpers?: Record<string, Function>;
|
|
53
|
+
name?: string | string[];
|
|
54
|
+
include?: HelperFilter[];
|
|
55
|
+
exclude?: HelperFilter[];
|
|
56
|
+
caching?: boolean | FumanchuCachingOptions;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Will return a Handlebars instance with Fumanchu helpers (experimental)
|
|
60
|
+
* @returns {Handlebars} Handlebars instance with helpers
|
|
61
|
+
*/
|
|
62
|
+
declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
|
|
63
|
+
|
|
64
|
+
export { type FumanchuCachingOptions, type FumanchuOptions, Handlebars, createHandlebars, fumanchu, handlebars, helpers };
|