@jaredwray/fumanchu 3.1.3 → 4.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 +51 -36
- package/dist/index.cjs +2250 -0
- package/dist/index.d.cts +119 -0
- package/dist/index.d.ts +57 -21
- package/dist/index.js +2110 -2104
- package/package.json +21 -39
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as HandlebarsLib from 'handlebars';
|
|
2
|
+
import HandlebarsLib__default from 'handlebars';
|
|
3
|
+
|
|
4
|
+
type Helper = {
|
|
5
|
+
name: string;
|
|
6
|
+
category: string;
|
|
7
|
+
compatibility?: string[];
|
|
8
|
+
fn: ((...arguments_: any[]) => string) | ((...arguments_: any[]) => number) | ((...arguments_: any[]) => number | string) | ((...arguments_: any[]) => HandlebarsLib__default.SafeString);
|
|
9
|
+
};
|
|
10
|
+
type HelperFilter = {
|
|
11
|
+
names?: string[];
|
|
12
|
+
categories?: string[];
|
|
13
|
+
compatibility?: string[];
|
|
14
|
+
};
|
|
15
|
+
declare class HelperRegistry {
|
|
16
|
+
private readonly _helpers;
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Get all registered helpers.
|
|
20
|
+
* @returns {Helper[]} The array of registered helpers.
|
|
21
|
+
*/
|
|
22
|
+
get helpers(): Helper[];
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the helper registry. This is performed during the construction of the registry such as new HelperRegistry().
|
|
25
|
+
*/
|
|
26
|
+
init(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Register a helper.
|
|
29
|
+
* @param {Helper} helper The helper to register.
|
|
30
|
+
* @returns True if the helper was registered, false otherwise.
|
|
31
|
+
*/
|
|
32
|
+
register(helper: Helper): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Register multiple helpers.
|
|
35
|
+
* @param {Helper[]} helpers The array of helpers to register.
|
|
36
|
+
*/
|
|
37
|
+
registerHelpers(helpers: Helper[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a helper is registered.
|
|
40
|
+
* @param name The name of the helper.
|
|
41
|
+
* @returns True if the helper is registered, false otherwise.
|
|
42
|
+
*/
|
|
43
|
+
has(name: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Filter helpers by the given criteria.
|
|
46
|
+
* @param filter The filter criteria.
|
|
47
|
+
* @returns The filtered helpers.
|
|
48
|
+
*/
|
|
49
|
+
filter(filter: HelperFilter): Helper[];
|
|
50
|
+
/**
|
|
51
|
+
* Load Handlebars helpers.
|
|
52
|
+
* @param {Handlebars} handlebars The Handlebars instance.
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
load(handlebars: any, filters?: HelperFilter): void;
|
|
56
|
+
/**
|
|
57
|
+
* Swap Handlebars helpers. This is used when you want to swap out legacy helpers for fumanchu helpers.
|
|
58
|
+
* @param handlebars The Handlebars instance.
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
swap(handlebars: any): void;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Handlebars library not initiated with helpers
|
|
66
|
+
* @type {Handlebars}
|
|
67
|
+
*/
|
|
68
|
+
declare const Handlebars: typeof HandlebarsLib;
|
|
69
|
+
/**
|
|
70
|
+
* Fumanchu Handlebars instance not initiated with helpers
|
|
71
|
+
* @type {Handlebars}
|
|
72
|
+
*/
|
|
73
|
+
declare const handlebars: typeof HandlebarsLib;
|
|
74
|
+
/**
|
|
75
|
+
* Fumanchu Handlebars helpers
|
|
76
|
+
*/
|
|
77
|
+
type HelpersOptions = {
|
|
78
|
+
handlebars?: typeof HandlebarsLib;
|
|
79
|
+
hbs?: typeof HandlebarsLib;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Register Handlebars helpers
|
|
83
|
+
* @param {HelpersOptions} options - Options for Fumanchu helpers
|
|
84
|
+
*/
|
|
85
|
+
declare function helpers(options: HelpersOptions): void;
|
|
86
|
+
/**
|
|
87
|
+
* Create a new Handlebars instance with Fumanchu helpers
|
|
88
|
+
* @returns {Promise<Handlebars>}
|
|
89
|
+
* @deprecated Will be deprecated in future versions, use `fumanchu()` instead.
|
|
90
|
+
*/
|
|
91
|
+
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
|
|
92
|
+
/**
|
|
93
|
+
* @typedef {Object} FumanchuCachingOptions
|
|
94
|
+
* @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
|
|
95
|
+
* 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
|
|
96
|
+
* undefined then it will not have a time-to-live.
|
|
97
|
+
* @property {boolean} [useClone] - If true, it will clone the value before returning it. If false, it will return the value directly. Default is true.
|
|
98
|
+
* @property {number} [lruSize] - The size of the LRU cache. If set to 0, it will not use LRU cache. Default is 0.
|
|
99
|
+
* @property {number} [checkInterval] - The interval to check for expired items. If set to 0, it will not check for expired items. Default is 0.
|
|
100
|
+
*/
|
|
101
|
+
type FumanchuCachingOptions = {
|
|
102
|
+
ttl?: number | string;
|
|
103
|
+
useClone?: boolean;
|
|
104
|
+
lruSize?: number;
|
|
105
|
+
checkInterval?: number;
|
|
106
|
+
};
|
|
107
|
+
type FumanchuOptions = {
|
|
108
|
+
handlebars?: typeof HandlebarsLib;
|
|
109
|
+
filter?: HelperFilter;
|
|
110
|
+
caching?: boolean | FumanchuCachingOptions;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Will return a Handlebars instance with Fumanchu helpers (experimental)
|
|
114
|
+
* @param {FumanchuOptions} [options] - Options for Fumanchu
|
|
115
|
+
* @returns {Handlebars} Handlebars instance with helpers
|
|
116
|
+
*/
|
|
117
|
+
declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
|
|
118
|
+
|
|
119
|
+
export { type FumanchuCachingOptions, type FumanchuOptions, Handlebars, type HelperFilter, HelperRegistry, type HelpersOptions, createHandlebars, fumanchu, handlebars, helpers };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,31 +1,64 @@
|
|
|
1
1
|
import * as HandlebarsLib from 'handlebars';
|
|
2
2
|
import HandlebarsLib__default from 'handlebars';
|
|
3
3
|
|
|
4
|
-
declare enum HelperRegistryCompatibility {
|
|
5
|
-
NODEJS = "nodejs",
|
|
6
|
-
BROWSER = "browser"
|
|
7
|
-
}
|
|
8
|
-
type HelperFilter = {
|
|
9
|
-
name?: string;
|
|
10
|
-
category?: string;
|
|
11
|
-
compatibility?: HelperRegistryCompatibility;
|
|
12
|
-
};
|
|
13
4
|
type Helper = {
|
|
14
5
|
name: string;
|
|
15
6
|
category: string;
|
|
16
|
-
compatibility?:
|
|
17
|
-
fn: ((...arguments_: any[]) => string) | ((...arguments_: any[]) => HandlebarsLib__default.SafeString);
|
|
7
|
+
compatibility?: string[];
|
|
8
|
+
fn: ((...arguments_: any[]) => string) | ((...arguments_: any[]) => number) | ((...arguments_: any[]) => number | string) | ((...arguments_: any[]) => HandlebarsLib__default.SafeString);
|
|
9
|
+
};
|
|
10
|
+
type HelperFilter = {
|
|
11
|
+
names?: string[];
|
|
12
|
+
categories?: string[];
|
|
13
|
+
compatibility?: string[];
|
|
18
14
|
};
|
|
19
15
|
declare class HelperRegistry {
|
|
20
16
|
private readonly _helpers;
|
|
21
17
|
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Get all registered helpers.
|
|
20
|
+
* @returns {Helper[]} The array of registered helpers.
|
|
21
|
+
*/
|
|
22
|
+
get helpers(): Helper[];
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the helper registry. This is performed during the construction of the registry such as new HelperRegistry().
|
|
25
|
+
*/
|
|
22
26
|
init(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Register a helper.
|
|
29
|
+
* @param {Helper} helper The helper to register.
|
|
30
|
+
* @returns True if the helper was registered, false otherwise.
|
|
31
|
+
*/
|
|
23
32
|
register(helper: Helper): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Register multiple helpers.
|
|
35
|
+
* @param {Helper[]} helpers The array of helpers to register.
|
|
36
|
+
*/
|
|
24
37
|
registerHelpers(helpers: Helper[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a helper is registered.
|
|
40
|
+
* @param name The name of the helper.
|
|
41
|
+
* @returns True if the helper is registered, false otherwise.
|
|
42
|
+
*/
|
|
25
43
|
has(name: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Filter helpers by the given criteria.
|
|
46
|
+
* @param filter The filter criteria.
|
|
47
|
+
* @returns The filtered helpers.
|
|
48
|
+
*/
|
|
26
49
|
filter(filter: HelperFilter): Helper[];
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Load Handlebars helpers.
|
|
52
|
+
* @param {Handlebars} handlebars The Handlebars instance.
|
|
53
|
+
* @returns {void}
|
|
54
|
+
*/
|
|
55
|
+
load(handlebars: any, filters?: HelperFilter): void;
|
|
56
|
+
/**
|
|
57
|
+
* Swap Handlebars helpers. This is used when you want to swap out legacy helpers for fumanchu helpers.
|
|
58
|
+
* @param handlebars The Handlebars instance.
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
swap(handlebars: any): void;
|
|
29
62
|
}
|
|
30
63
|
|
|
31
64
|
/**
|
|
@@ -41,13 +74,19 @@ declare const handlebars: typeof HandlebarsLib;
|
|
|
41
74
|
/**
|
|
42
75
|
* Fumanchu Handlebars helpers
|
|
43
76
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
77
|
+
type HelpersOptions = {
|
|
78
|
+
handlebars?: typeof HandlebarsLib;
|
|
79
|
+
hbs?: typeof HandlebarsLib;
|
|
47
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Register Handlebars helpers
|
|
83
|
+
* @param {HelpersOptions} options - Options for Fumanchu helpers
|
|
84
|
+
*/
|
|
85
|
+
declare function helpers(options: HelpersOptions): void;
|
|
48
86
|
/**
|
|
49
87
|
* Create a new Handlebars instance with Fumanchu helpers
|
|
50
88
|
* @returns {Promise<Handlebars>}
|
|
89
|
+
* @deprecated Will be deprecated in future versions, use `fumanchu()` instead.
|
|
51
90
|
*/
|
|
52
91
|
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
|
|
53
92
|
/**
|
|
@@ -67,10 +106,7 @@ type FumanchuCachingOptions = {
|
|
|
67
106
|
};
|
|
68
107
|
type FumanchuOptions = {
|
|
69
108
|
handlebars?: typeof HandlebarsLib;
|
|
70
|
-
|
|
71
|
-
name?: string | string[];
|
|
72
|
-
include?: HelperFilter[];
|
|
73
|
-
exclude?: HelperFilter[];
|
|
109
|
+
filter?: HelperFilter;
|
|
74
110
|
caching?: boolean | FumanchuCachingOptions;
|
|
75
111
|
};
|
|
76
112
|
/**
|
|
@@ -80,4 +116,4 @@ type FumanchuOptions = {
|
|
|
80
116
|
*/
|
|
81
117
|
declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
|
|
82
118
|
|
|
83
|
-
export { type FumanchuCachingOptions, type FumanchuOptions, Handlebars, type HelperFilter, HelperRegistry, createHandlebars, fumanchu, handlebars, helpers };
|
|
119
|
+
export { type FumanchuCachingOptions, type FumanchuOptions, Handlebars, type HelperFilter, HelperRegistry, type HelpersOptions, createHandlebars, fumanchu, handlebars, helpers };
|