@jaredwray/fumanchu 3.0.0 → 3.0.2
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 +7 -5
- package/dist/index.d.ts +56 -1
- package/dist/index.js +334 -270
- package/package.json +86 -68
- package/site/logo.svg +19 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
# fumanchu
|
|
@@ -14,11 +14,11 @@ Handlebars + Helpers Together
|
|
|
14
14
|
|
|
15
15
|
We plan to make significant changes over time with this project such as the following:
|
|
16
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
|
|
17
19
|
- **(In Progress)** Migrate to Typescript with full typing support
|
|
18
20
|
- **(In Progress)** Replace module dependencies that are no longer supported with supported ones
|
|
19
21
|
- 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
22
|
- Move to better documentation and examples where it makes sense
|
|
23
23
|
- Add in browser support via CDN (this will remove the nodejs specific helpers)
|
|
24
24
|
|
|
@@ -27,8 +27,8 @@ We plan to make significant changes over time with this project such as the foll
|
|
|
27
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
28
|
|
|
29
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.
|
|
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
32
|
- `Handlebars` - This is the handlebars library itself. It is the same as calling `require('handlebars')`
|
|
33
33
|
|
|
34
34
|
Please see the examples below for how to use the library.
|
|
@@ -3098,6 +3098,8 @@ Generate a random number
|
|
|
3098
3098
|
## How to Contribute
|
|
3099
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`.
|
|
3100
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
|
+
|
|
3101
3103
|
## License and Copyright
|
|
3102
3104
|
[MIT](LICENSE) and codebase after 2023 will be copyright of Jared Wray.
|
|
3103
3105
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import * as HandlebarsLib from 'handlebars';
|
|
2
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
|
+
type Helper = {
|
|
13
|
+
name: string;
|
|
14
|
+
category: string;
|
|
15
|
+
compatibility?: HelperRegistryCompatibility;
|
|
16
|
+
fn: ((...arguments_: any[]) => string);
|
|
17
|
+
};
|
|
18
|
+
declare class HelperRegistry {
|
|
19
|
+
private readonly _helpers;
|
|
20
|
+
constructor();
|
|
21
|
+
init(): void;
|
|
22
|
+
register(helper: Helper): boolean;
|
|
23
|
+
registerHelpers(helpers: Helper[]): void;
|
|
24
|
+
has(name: string): boolean;
|
|
25
|
+
filter(filter: HelperFilter): Helper[];
|
|
26
|
+
loadHandlebars(handlebars: any): void;
|
|
27
|
+
swapHelpers(handlebars: any): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
/**
|
|
4
31
|
* Handlebars library not initiated with helpers
|
|
5
32
|
* @type {Handlebars}
|
|
@@ -22,5 +49,33 @@ declare const helpers: {
|
|
|
22
49
|
* @returns {Promise<Handlebars>}
|
|
23
50
|
*/
|
|
24
51
|
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
|
|
52
|
+
/**
|
|
53
|
+
* @typedef {Object} FumanchuCachingOptions
|
|
54
|
+
* @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
|
|
55
|
+
* 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
|
|
56
|
+
* undefined then it will not have a time-to-live.
|
|
57
|
+
* @property {boolean} [useClone] - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
58
|
+
* @property {number} [lruSize] - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
59
|
+
* @property {number} [checkInterval] - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
60
|
+
*/
|
|
61
|
+
type FumanchuCachingOptions = {
|
|
62
|
+
ttl?: number | string;
|
|
63
|
+
useClone?: boolean;
|
|
64
|
+
lruSize?: number;
|
|
65
|
+
checkInterval?: number;
|
|
66
|
+
};
|
|
67
|
+
type FumanchuOptions = {
|
|
68
|
+
handlebars?: typeof HandlebarsLib;
|
|
69
|
+
helpers?: Record<string, Function>;
|
|
70
|
+
name?: string | string[];
|
|
71
|
+
include?: HelperFilter[];
|
|
72
|
+
exclude?: HelperFilter[];
|
|
73
|
+
caching?: boolean | FumanchuCachingOptions;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Will return a Handlebars instance with Fumanchu helpers (experimental)
|
|
77
|
+
* @returns {Handlebars} Handlebars instance with helpers
|
|
78
|
+
*/
|
|
79
|
+
declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
|
|
25
80
|
|
|
26
|
-
export { Handlebars, createHandlebars, handlebars, helpers };
|
|
81
|
+
export { type FumanchuCachingOptions, type FumanchuOptions, Handlebars, type HelperFilter, HelperRegistry, createHandlebars, fumanchu, handlebars, helpers };
|