@jaredwray/fumanchu 3.1.2 → 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.
@@ -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,30 +1,64 @@
1
1
  import * as HandlebarsLib from 'handlebars';
2
+ import HandlebarsLib__default from 'handlebars';
2
3
 
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
4
  type Helper = {
13
5
  name: string;
14
6
  category: string;
15
- compatibility?: HelperRegistryCompatibility;
16
- fn: ((...arguments_: any[]) => 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[];
17
14
  };
18
15
  declare class HelperRegistry {
19
16
  private readonly _helpers;
20
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
+ */
21
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
+ */
22
32
  register(helper: Helper): boolean;
33
+ /**
34
+ * Register multiple helpers.
35
+ * @param {Helper[]} helpers The array of helpers to register.
36
+ */
23
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
+ */
24
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
+ */
25
49
  filter(filter: HelperFilter): Helper[];
26
- loadHandlebars(handlebars: any): void;
27
- swapHelpers(handlebars: any): void;
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;
28
62
  }
29
63
 
30
64
  /**
@@ -40,13 +74,19 @@ declare const handlebars: typeof HandlebarsLib;
40
74
  /**
41
75
  * Fumanchu Handlebars helpers
42
76
  */
43
- declare const helpers: {
44
- (groups: any, options: any): any;
45
- utils: any;
77
+ type HelpersOptions = {
78
+ handlebars?: typeof HandlebarsLib;
79
+ hbs?: typeof HandlebarsLib;
46
80
  };
81
+ /**
82
+ * Register Handlebars helpers
83
+ * @param {HelpersOptions} options - Options for Fumanchu helpers
84
+ */
85
+ declare function helpers(options: HelpersOptions): void;
47
86
  /**
48
87
  * Create a new Handlebars instance with Fumanchu helpers
49
88
  * @returns {Promise<Handlebars>}
89
+ * @deprecated Will be deprecated in future versions, use `fumanchu()` instead.
50
90
  */
51
91
  declare function createHandlebars(): Promise<typeof HandlebarsLib>;
52
92
  /**
@@ -66,16 +106,14 @@ type FumanchuCachingOptions = {
66
106
  };
67
107
  type FumanchuOptions = {
68
108
  handlebars?: typeof HandlebarsLib;
69
- helpers?: Record<string, Function>;
70
- name?: string | string[];
71
- include?: HelperFilter[];
72
- exclude?: HelperFilter[];
109
+ filter?: HelperFilter;
73
110
  caching?: boolean | FumanchuCachingOptions;
74
111
  };
75
112
  /**
76
113
  * Will return a Handlebars instance with Fumanchu helpers (experimental)
114
+ * @param {FumanchuOptions} [options] - Options for Fumanchu
77
115
  * @returns {Handlebars} Handlebars instance with helpers
78
116
  */
79
117
  declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
80
118
 
81
- 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 };