@jaredwray/fumanchu 4.5.1 → 4.6.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 +57 -1
- package/dist/index.cjs +2854 -3123
- package/dist/index.d.cts +65 -77
- package/dist/index.d.mts +106 -0
- package/dist/index.mjs +2868 -0
- package/package.json +34 -19
- package/dist/index.d.ts +0 -118
- package/dist/index.js +0 -3142
package/README.md
CHANGED
|
@@ -7,7 +7,8 @@ Handlebars + Helpers Together
|
|
|
7
7
|
[](https://github.com/jaredwray/fumanchu/actions/workflows/tests.yaml)
|
|
8
8
|
[](https://codecov.io/gh/jaredwray/fumanchu)
|
|
9
9
|
[](https://npmjs.com/package/@jaredwray/fumanchu)
|
|
10
|
-
[
|
|
11
|
+
](https://github.com/jaredwray/fumanchu/blob/main/LICENSE)
|
|
11
12
|
[](https://npmjs.com/package/@jaredwray/fumanchu)
|
|
12
13
|
|
|
13
14
|
[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. More than 160 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. Currently **189 helpers** in **20 categories**! 🎉
|
|
@@ -39,6 +40,7 @@ Handlebars + Helpers Together
|
|
|
39
40
|
* [string](https://fumanchu.org/docs/string/)
|
|
40
41
|
* [url](https://fumanchu.org/docs/url/)
|
|
41
42
|
* [utils](https://fumanchu.org/docs/utils/)
|
|
43
|
+
* [Caching](#caching)
|
|
42
44
|
* [How to Contribute](#how-to-contribute)
|
|
43
45
|
* [License and Copyright](#license-and-copyright)
|
|
44
46
|
|
|
@@ -112,6 +114,60 @@ registry.load(hbs, { names: ['if']}); // Load the helpers into Handlebars
|
|
|
112
114
|
|
|
113
115
|
In addition, we have made the helper functions have a compatibility such as `HelperRegistryCompatibility.NODEJS` or `HelperRegistryCompatibility.BROWSER`. This will allow you to filter out based on your environment!
|
|
114
116
|
|
|
117
|
+
# Caching
|
|
118
|
+
|
|
119
|
+
When caching is enabled, Fumanchu wraps the Handlebars `compile()` method to cache compiled template functions using [@cacheable/memory](https://github.com/jaredwray/cacheable/tree/main/packages/memory). If you compile the same template string multiple times, the cached version is returned instead of recompiling. The returned Handlebars instance is fully compatible -- caching is transparent to your existing code.
|
|
120
|
+
|
|
121
|
+
The `caching` option accepts three types:
|
|
122
|
+
- `boolean` -- `true` enables caching with defaults, `false` disables it
|
|
123
|
+
- `CacheableMemory` -- a pre-configured instance from `@cacheable/memory`
|
|
124
|
+
- `CacheableMemoryOptions` -- an options object passed to `CacheableMemory` (supports `ttl`, `lruSize`, `checkInterval`, etc.)
|
|
125
|
+
|
|
126
|
+
Here is an quick benchmark showing the performance advantage:
|
|
127
|
+
|
|
128
|
+
| name | summary | ops/sec | time/op | margin | samples |
|
|
129
|
+
|------------------------------------|:---------:|----------:|----------:|:--------:|----------:|
|
|
130
|
+
| compile+render cached (v4.6.0) | 🥇 | 45K | 39µs | ±0.32% | 25K |
|
|
131
|
+
| compile+render no-cache (v4.6.0) | -83% | 8K | 166µs | ±0.62% | 10K |
|
|
132
|
+
|
|
133
|
+
## Enable caching with default settings
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
import { fumanchu } from '@jaredwray/fumanchu';
|
|
137
|
+
const handlebars = fumanchu({ caching: true });
|
|
138
|
+
|
|
139
|
+
const template = handlebars.compile('Hello {{name}}!');
|
|
140
|
+
template({ name: 'World' }); // compiles and caches
|
|
141
|
+
|
|
142
|
+
const template2 = handlebars.compile('Hello {{name}}!');
|
|
143
|
+
// returns the cached compiled function -- no recompilation
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Pass caching options
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
import { fumanchu } from '@jaredwray/fumanchu';
|
|
150
|
+
const handlebars = fumanchu({
|
|
151
|
+
caching: {
|
|
152
|
+
ttl: '1h', // Time-to-live in ms or human-readable string like '1h'
|
|
153
|
+
lruSize: 500, // LRU cache size limit (0 = unlimited)
|
|
154
|
+
checkInterval: 0, // Interval to check for expired items in ms (0 = disabled)
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Pass a pre-configured `CacheableMemory` instance
|
|
160
|
+
|
|
161
|
+
This is useful if you want to share a cache across multiple Fumanchu instances or manage the cache lifecycle yourself:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { fumanchu, CacheableMemory } from '@jaredwray/fumanchu';
|
|
165
|
+
const cache = new CacheableMemory({ ttl: '1h', lruSize: 1000, useClone: false });
|
|
166
|
+
|
|
167
|
+
const hbs1 = fumanchu({ caching: cache });
|
|
168
|
+
const hbs2 = fumanchu({ caching: cache }); // shares the same cache as hbs1
|
|
169
|
+
```
|
|
170
|
+
|
|
115
171
|
## How to Contribute
|
|
116
172
|
Clone the repository locally 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`.
|
|
117
173
|
|