express-sweet 4.0.0 → 5.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/CHANGELOG.md +209 -397
- package/LICENSE +1 -1
- package/README.md +210 -1174
- package/dist/build.cjs +32 -73
- package/dist/build.mjs +32 -73
- package/package.json +45 -61
- package/screenshots/avatar.png +0 -0
- package/screenshots/edit-profile.png +0 -0
- package/screenshots/hero-banner.png +0 -0
- package/screenshots/home.png +0 -0
- package/screenshots/mount-flow.mmd +11 -0
- package/screenshots/mount-flow.png +0 -0
- package/screenshots/new-person.png +0 -0
- package/screenshots/people.png +0 -0
- package/screenshots/sign-in.png +0 -0
- package/types/database/DatabaseManager.d.ts +15 -10
- package/types/database/Model.d.ts +29 -43
- package/types/database/index.d.ts +0 -1
- package/types/database/loadModels.d.ts +7 -13
- package/types/helpers/array.d.ts +21 -0
- package/types/helpers/comparison.d.ts +217 -0
- package/types/helpers/date.d.ts +20 -0
- package/types/helpers/html.d.ts +35 -0
- package/types/{handlebars_helpers → helpers}/index.d.ts +0 -2
- package/types/helpers/layouts.d.ts +29 -0
- package/types/helpers/math.d.ts +85 -0
- package/types/helpers/number.d.ts +19 -0
- package/types/helpers/object.d.ts +28 -0
- package/types/helpers/string.d.ts +45 -0
- package/types/index.d.ts +6 -9
- package/types/middleware/auth.d.ts +186 -0
- package/types/middleware/cors.d.ts +19 -0
- package/types/middleware/env.d.ts +24 -0
- package/types/middleware/error.d.ts +26 -0
- package/types/middleware/globals.d.ts +13 -0
- package/types/{middlewares → middleware}/index.d.ts +12 -13
- package/types/middleware/locals.d.ts +33 -0
- package/types/middleware/parser.d.ts +30 -0
- package/types/middleware/router.d.ts +31 -0
- package/types/middleware/views.d.ts +37 -0
- package/types/mount.d.ts +1 -2
- package/types/{interfaces → types}/AppConfig.d.ts +11 -19
- package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
- package/types/{interfaces → types}/DatabaseConfig.d.ts +0 -1
- package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
- package/types/{interfaces → types}/UploadConfig.d.ts +0 -1
- package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
- package/types/{interfaces → types}/index.d.ts +1 -2
- package/types/utils/index.d.ts +0 -1
- package/types/utils/loadAppConfig.d.ts +1 -1
- package/types/utils/loadAuthenticationConfig.d.ts +1 -1
- package/types/utils/loadLoggingConfig.d.ts +1 -1
- package/types/utils/loadUploadConfig.d.ts +1 -1
- package/types/utils/loadViewConfig.d.ts +1 -1
- package/configuration_sample/cjs/authentication.js +0 -138
- package/configuration_sample/cjs/config.js +0 -92
- package/configuration_sample/cjs/database.js +0 -121
- package/configuration_sample/cjs/logging.js +0 -41
- package/configuration_sample/cjs/upload.js +0 -91
- package/configuration_sample/cjs/view.js +0 -54
- package/configuration_sample/esm/authentication.js +0 -136
- package/configuration_sample/esm/config.js +0 -92
- package/configuration_sample/esm/database.js +0 -121
- package/configuration_sample/esm/logging.js +0 -41
- package/configuration_sample/esm/upload.js +0 -91
- package/configuration_sample/esm/view.js +0 -54
- package/screencaps/belongs-to-many.png +0 -0
- package/screencaps/belongs-to.png +0 -0
- package/screencaps/demonstration.webp +0 -0
- package/screencaps/has-many.png +0 -0
- package/screencaps/has-one.png +0 -0
- package/types/handlebars_helpers/array.d.ts +0 -22
- package/types/handlebars_helpers/comparison.d.ts +0 -222
- package/types/handlebars_helpers/date.d.ts +0 -19
- package/types/handlebars_helpers/html.d.ts +0 -31
- package/types/handlebars_helpers/layouts.d.ts +0 -25
- package/types/handlebars_helpers/math.d.ts +0 -74
- package/types/handlebars_helpers/number.d.ts +0 -18
- package/types/handlebars_helpers/object.d.ts +0 -21
- package/types/handlebars_helpers/string.d.ts +0 -45
- package/types/middlewares/corsPolicy.d.ts +0 -28
- package/types/middlewares/envLoader.d.ts +0 -34
- package/types/middlewares/errorHandler.d.ts +0 -32
- package/types/middlewares/globalVars.d.ts +0 -25
- package/types/middlewares/localVars.d.ts +0 -44
- package/types/middlewares/passportAuth.d.ts +0 -15
- package/types/middlewares/requestParser.d.ts +0 -27
- package/types/middlewares/routeMapper.d.ts +0 -54
- package/types/middlewares/viewEngine.d.ts +0 -49
- package/types/services/Authentication.d.ts +0 -95
- package/types/services/index.d.ts +0 -33
- package/types/types/global.d.ts +0 -38
- package/types/utils/Types.d.ts +0 -29
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks strict equality (`===`) between two values.
|
|
3
|
+
* @param {any} value1 The first value.
|
|
4
|
+
* @param {any} value2 The second value.
|
|
5
|
+
* @returns {boolean} `true` if both value and type are identical, `false` otherwise.
|
|
6
|
+
* @example
|
|
7
|
+
* ```handlebars
|
|
8
|
+
* {{eq status 'active'}}
|
|
9
|
+
* {{#if (eq role 'admin')}}...{{/if}}
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const eq: (value1: any, value2: any) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Checks loose equality (`==`) between two values (type coercion applied).
|
|
15
|
+
* @param {any} value1 The first value.
|
|
16
|
+
* @param {any} value2 The second value.
|
|
17
|
+
* @returns {boolean} `true` if the values are loosely equal, `false` otherwise.
|
|
18
|
+
* @example
|
|
19
|
+
* ```handlebars
|
|
20
|
+
* {{eqw val1 val2}}
|
|
21
|
+
* {{#if (eqw id '123')}}...{{/if}}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare const eqw: (value1: any, value2: any) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Checks strict inequality (`!==`) between two values.
|
|
27
|
+
* @param {any} value1 The first value.
|
|
28
|
+
* @param {any} value2 The second value.
|
|
29
|
+
* @returns {boolean} `true` if the values differ in value or type, `false` otherwise.
|
|
30
|
+
* @example
|
|
31
|
+
* ```handlebars
|
|
32
|
+
* {{neq val1 val2}}
|
|
33
|
+
* {{#if (neq status 'inactive')}}...{{/if}}
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const neq: (value1: any, value2: any) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Checks loose inequality (`!=`) between two values (type coercion applied).
|
|
39
|
+
* @param {any} value1 The first value.
|
|
40
|
+
* @param {any} value2 The second value.
|
|
41
|
+
* @returns {boolean} `true` if the values are loosely unequal, `false` otherwise.
|
|
42
|
+
* @example
|
|
43
|
+
* ```handlebars
|
|
44
|
+
* {{neqw val1 val2}}
|
|
45
|
+
* {{#if (neqw val1 val2)}}...{{/if}}
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare const neqw: (value1: any, value2: any) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if the first value is less than the second (`a < b`).
|
|
51
|
+
* @param {any} value1 The first value.
|
|
52
|
+
* @param {any} value2 The second value.
|
|
53
|
+
* @returns {boolean} `true` if `value1 < value2`, `false` otherwise.
|
|
54
|
+
* @example
|
|
55
|
+
* ```handlebars
|
|
56
|
+
* {{lt age 18}}
|
|
57
|
+
* {{#if (lt count max)}}...{{/if}}
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare const lt: (value1: any, value2: any) => boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Checks if the first value is less than or equal to the second (`a <= b`).
|
|
63
|
+
* @param {any} value1 The first value.
|
|
64
|
+
* @param {any} value2 The second value.
|
|
65
|
+
* @returns {boolean} `true` if `value1 <= value2`, `false` otherwise.
|
|
66
|
+
* @example
|
|
67
|
+
* ```handlebars
|
|
68
|
+
* {{lte age 18}}
|
|
69
|
+
* {{#if (lte count max)}}...{{/if}}
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare const lte: (value1: any, value2: any) => boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if the first value is greater than the second (`a > b`).
|
|
75
|
+
* @param {any} value1 The first value.
|
|
76
|
+
* @param {any} value2 The second value.
|
|
77
|
+
* @returns {boolean} `true` if `value1 > value2`, `false` otherwise.
|
|
78
|
+
* @example
|
|
79
|
+
* ```handlebars
|
|
80
|
+
* {{gt score 100}}
|
|
81
|
+
* {{#if (gt count 0)}}...{{/if}}
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare const gt: (value1: any, value2: any) => boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the first value is greater than or equal to the second (`a >= b`).
|
|
87
|
+
* @param {any} value1 The first value.
|
|
88
|
+
* @param {any} value2 The second value.
|
|
89
|
+
* @returns {boolean} `true` if `value1 >= value2`, `false` otherwise.
|
|
90
|
+
* @example
|
|
91
|
+
* ```handlebars
|
|
92
|
+
* {{gte score 100}}
|
|
93
|
+
* {{#if (gte count min)}}...{{/if}}
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare const gte: (value1: any, value2: any) => boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Returns the logical NOT of the given expression.
|
|
99
|
+
* @param {any} expression The expression to negate.
|
|
100
|
+
* @returns {boolean} The negated boolean value.
|
|
101
|
+
* @example
|
|
102
|
+
* ```handlebars
|
|
103
|
+
* {{not isDisabled}}
|
|
104
|
+
* {{#if (not (eq status 'closed'))}}...{{/if}}
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare const not: (expression: any) => boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Ternary conditional operator (`condition ? value1 : value2`).
|
|
110
|
+
* @param {boolean} condition The condition to evaluate.
|
|
111
|
+
* @param {any} value1 Value returned when condition is truthy.
|
|
112
|
+
* @param {any} value2 Value returned when condition is falsy. Defaults to `''` if omitted.
|
|
113
|
+
* @returns {any} `value1` if condition is truthy, `value2` otherwise.
|
|
114
|
+
* @example
|
|
115
|
+
* ```handlebars
|
|
116
|
+
* {{ifx isActive 'Yes' 'No'}}
|
|
117
|
+
* {{ifx (eq role 'admin') 'Administrator' 'User'}}
|
|
118
|
+
* {{ifx hasItems count}}
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare const ifx: (condition: boolean, value1: any, value2: any) => any;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if a value is empty.
|
|
124
|
+
* Strings are trimmed (including full-width spaces) before checking.
|
|
125
|
+
* Empty arrays are treated as empty.
|
|
126
|
+
* @param {any} value The value to check (string, array, object, etc.).
|
|
127
|
+
* @returns {boolean} `true` if the value is empty, falsy, or a whitespace-only string.
|
|
128
|
+
* @example
|
|
129
|
+
* ```handlebars
|
|
130
|
+
* {{empty name}}
|
|
131
|
+
* {{#if (empty items)}}No items found.{{/if}}
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export declare const empty: (value: any) => boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if a value is not empty (inverse of {@link empty}).
|
|
137
|
+
* Strings are trimmed (including full-width spaces) before checking.
|
|
138
|
+
* @param {any} value The value to check (string, array, object, etc.).
|
|
139
|
+
* @returns {boolean} `true` if the value has content, `false` otherwise.
|
|
140
|
+
* @example
|
|
141
|
+
* ```handlebars
|
|
142
|
+
* {{notEmpty name}}
|
|
143
|
+
* {{#if (notEmpty items)}}Found {{count items}} items.{{/if}}
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
export declare const notEmpty: (value: any) => boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Returns the length of an array.
|
|
149
|
+
* @param {any[]} items The array to count.
|
|
150
|
+
* @returns {number|false} The array length, or `false` if the value is not an array.
|
|
151
|
+
* @example
|
|
152
|
+
* ```handlebars
|
|
153
|
+
* {{count items}}
|
|
154
|
+
* {{#if (gt (count items) 0)}}Has items{{/if}}
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare const count: (items: any[]) => number | false;
|
|
158
|
+
/**
|
|
159
|
+
* Returns `true` if all parameters are truthy (logical AND).
|
|
160
|
+
* @param {...any} params Two or more values to evaluate.
|
|
161
|
+
* @returns {boolean} `true` if every parameter is truthy, `false` otherwise.
|
|
162
|
+
* @example
|
|
163
|
+
* ```handlebars
|
|
164
|
+
* {{and isLoggedIn isAdmin}}
|
|
165
|
+
* {{#if (and hasPermission isActive)}}...{{/if}}
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export declare const and: (...params: any[]) => boolean;
|
|
169
|
+
/**
|
|
170
|
+
* Returns `true` if any parameter is truthy (logical OR).
|
|
171
|
+
* @param {...any} params Two or more values to evaluate.
|
|
172
|
+
* @returns {boolean} `true` if at least one parameter is truthy, `false` otherwise.
|
|
173
|
+
* @example
|
|
174
|
+
* ```handlebars
|
|
175
|
+
* {{or isAdmin isModerator}}
|
|
176
|
+
* {{#if (or hasError hasWarning)}}...{{/if}}
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
export declare const or: (...params: any[]) => boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Returns the first truthy value from the parameter list, similar to SQL's `COALESCE()`.
|
|
182
|
+
* If all values are falsy, returns the last parameter.
|
|
183
|
+
* @param {...any} params The values to evaluate.
|
|
184
|
+
* @returns {any} The first truthy value, or the last value if all are falsy.
|
|
185
|
+
* @example
|
|
186
|
+
* ```handlebars
|
|
187
|
+
* {{coalesce nickname username 'Anonymous'}}
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
export declare const coalesce: (...params: any[]) => any;
|
|
191
|
+
/**
|
|
192
|
+
* Checks if an array contains a specific value.
|
|
193
|
+
* @param {any[]} items The array to search.
|
|
194
|
+
* @param {any} value The value to look for.
|
|
195
|
+
* @param {boolean} strict Use strict equality (`===`) when `true`, loose equality (`==`) when `false`. Defaults to `true`.
|
|
196
|
+
* @returns {boolean} `true` if the array contains the value, `false` otherwise.
|
|
197
|
+
* @example
|
|
198
|
+
* ```handlebars
|
|
199
|
+
* {{includes roles 'admin'}}
|
|
200
|
+
* {{#if (includes selectedIds id)}}selected{{/if}}
|
|
201
|
+
* {{ifx (includes statuses status) 'active' 'inactive'}}
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
export declare const includes: (items: any[], value: any, strict?: boolean) => boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Tests a string against a regular expression pattern.
|
|
207
|
+
* @param {string} val The string to test.
|
|
208
|
+
* @param {string} pattern The regular expression pattern.
|
|
209
|
+
* @param {string} flags Optional regex flags (e.g., `'i'` for case-insensitive). Defaults to none.
|
|
210
|
+
* @returns {boolean} `true` if the string matches the pattern, `false` otherwise.
|
|
211
|
+
* @example
|
|
212
|
+
* ```handlebars
|
|
213
|
+
* {{regexMatch email '^[\\w.-]+@[\\w.-]+$'}}
|
|
214
|
+
* {{#if (regexMatch url '^https://' 'i')}}Secure{{/if}}
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export declare const regexMatch: (val: string, pattern: string, flags?: string) => boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a date string using Moment.js format tokens.
|
|
3
|
+
* If no date is provided, the current date/time is used.
|
|
4
|
+
* @param {string} format A Moment.js format string (e.g., `'YYYY-MM-DD'`, `'HH:mm:ss'`).
|
|
5
|
+
* @param {string} date The date string to format (any format parseable by Moment.js).
|
|
6
|
+
* @param {string|string[]} locale A BCP 47 locale string (e.g., `'ja'`, `'en-US'`) or array of locales. Defaults to the system locale.
|
|
7
|
+
* @returns {string} The formatted date string.
|
|
8
|
+
* @example
|
|
9
|
+
* ```handlebars
|
|
10
|
+
* {{!-- results in: 2024/01/15 --}}
|
|
11
|
+
* {{formatDate 'YYYY/MM/DD' createdAt}}
|
|
12
|
+
*
|
|
13
|
+
* {{!-- results in: January 15, 2024 --}}
|
|
14
|
+
* {{formatDate 'MMMM D, YYYY' createdAt 'en'}}
|
|
15
|
+
*
|
|
16
|
+
* {{!-- results in: 2024年1月15日 --}}
|
|
17
|
+
* {{formatDate 'YYYY年M月D日' createdAt 'ja'}}
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare const formatDate: (format: string, date: string, locale: string | string[]) => string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Appends a cache-busting query parameter (file modification timestamp) to an asset path.
|
|
3
|
+
* This forces browsers to re-fetch the file when it changes, preventing stale cache issues.
|
|
4
|
+
* @param {string} filePath Path to an asset file (CSS, JS, images, etc.) relative to the public directory.
|
|
5
|
+
* @param {string} baseUrl Base URL to prepend (e.g., CDN origin). Defaults to none (undefined).
|
|
6
|
+
* @returns {string} The asset path with a timestamp query parameter, or the original path if the file does not exist.
|
|
7
|
+
* @example
|
|
8
|
+
* ```handlebars
|
|
9
|
+
* {{!-- results in: /assets/style.css?1620526340463 --}}
|
|
10
|
+
* {{cacheBusting '/assets/style.css'}}
|
|
11
|
+
*
|
|
12
|
+
* {{!-- results in: //cdn.example.com/assets/style.css?1620526340463 --}}
|
|
13
|
+
* {{cacheBusting '/assets/style.css' '//cdn.example.com'}}
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const cacheBusting: (filePath: string, baseUrl?: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Strips HTML tags from a string, with optional allowlist and replacement string.
|
|
19
|
+
* @param {string} str The HTML string to sanitize.
|
|
20
|
+
* @param {string|string[]} allowedTags Tags to preserve (e.g., `'<strong>'` or `['<strong>', '<em>']`). Defaults to `[]`.
|
|
21
|
+
* @param {string} replacement String to insert in place of removed tags. Defaults to `''`.
|
|
22
|
+
* @returns {string} The sanitized string with HTML tags removed (except allowed ones).
|
|
23
|
+
* @example
|
|
24
|
+
* ```handlebars
|
|
25
|
+
* {{!-- results in: lorem ipsum dolor sit amet --}}
|
|
26
|
+
* {{{stripTags '<p>lorem ipsum <strong>dolor</strong> <em>sit</em> amet</p>'}}}
|
|
27
|
+
*
|
|
28
|
+
* {{!-- results in: lorem ipsum <strong>dolor</strong> sit amet --}}
|
|
29
|
+
* {{{stripTags '<p>lorem ipsum <strong>dolor</strong> <em>sit</em> amet</p>' '<strong>' ''}}}
|
|
30
|
+
*
|
|
31
|
+
* {{!-- results in: *lorem ipsum *dolor* *sit* amet* --}}
|
|
32
|
+
* {{{stripTags '<p>lorem ipsum <strong>dolor</strong> <em>sit</em> amet</p>' [] '*'}}}
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const stripTags: (str: string, allowedTags?: string | string[], replacement?: string) => string;
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* string operations, date formatting, mathematical operations, comparisons, and more.
|
|
6
6
|
* These helpers are automatically registered with the Handlebars engine.
|
|
7
7
|
*
|
|
8
|
-
* @module handlebars_helpers
|
|
9
|
-
* @see {@link https://handlebarsjs.com/guide/ | Handlebars Guide}
|
|
10
8
|
* @example
|
|
11
9
|
* ```handlebars
|
|
12
10
|
* // Using comparison helpers in templates
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declares a block placeholder in a layout template.
|
|
3
|
+
* Renders the content injected by {@link contentFor}, or falls back to the block's default content.
|
|
4
|
+
* Imported from {@link https://github.com/TryGhost/express-hbs|express-hbs}.
|
|
5
|
+
* @param {string} name The name of the block placeholder.
|
|
6
|
+
* @param {Handlebars.HelperOptions} options Handlebars helper options.
|
|
7
|
+
* @returns {string} The concatenated block content, or the default block body if no content was injected.
|
|
8
|
+
* @example
|
|
9
|
+
* ```handlebars
|
|
10
|
+
* {{!-- In layout template: declare a placeholder for page-specific scripts --}}
|
|
11
|
+
* {{{block "pageScripts"}}}
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const block: (this: any, name: string, options: Handlebars.HelperOptions) => any;
|
|
15
|
+
/**
|
|
16
|
+
* Injects content into a named block placeholder declared in a layout template.
|
|
17
|
+
* Multiple calls to `contentFor` with the same name will append content.
|
|
18
|
+
* Imported from {@link https://github.com/TryGhost/express-hbs|express-hbs}.
|
|
19
|
+
* @param {string} name The name of the block to inject content into.
|
|
20
|
+
* @param {Handlebars.HelperOptions} options Handlebars helper options containing the block body.
|
|
21
|
+
* @example
|
|
22
|
+
* ```handlebars
|
|
23
|
+
* {{!-- In page template: inject page-specific scripts into the layout's "pageScripts" block --}}
|
|
24
|
+
* {{#contentFor "pageScripts"}}
|
|
25
|
+
* <script src="/js/page.js"></script>
|
|
26
|
+
* {{/contentFor}}
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare const contentFor: (this: any, name: string, options: any) => void;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the sum of two numbers (`val1 + val2`).
|
|
3
|
+
* String values are automatically converted to numbers.
|
|
4
|
+
* @param {number|string} val1 The first operand.
|
|
5
|
+
* @param {number|string} val2 The second operand.
|
|
6
|
+
* @returns {number} The sum of the two values.
|
|
7
|
+
* @example
|
|
8
|
+
* ```handlebars
|
|
9
|
+
* {{!-- results in: 15 --}}
|
|
10
|
+
* {{add price tax}}
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const add: (val1: number | string, val2: number | string) => number;
|
|
14
|
+
/**
|
|
15
|
+
* Returns the difference of two numbers (`val1 - val2`).
|
|
16
|
+
* String values are automatically converted to numbers.
|
|
17
|
+
* @param {number|string} val1 The minuend.
|
|
18
|
+
* @param {number|string} val2 The subtrahend.
|
|
19
|
+
* @returns {number} The difference of the two values.
|
|
20
|
+
* @example
|
|
21
|
+
* ```handlebars
|
|
22
|
+
* {{!-- results in: 3 --}}
|
|
23
|
+
* {{sub 5 2}}
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const sub: (val1: number | string, val2: number | string) => number;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the product of two numbers (`val1 * val2`).
|
|
29
|
+
* String values are automatically converted to numbers.
|
|
30
|
+
* @param {number|string} val1 The first factor.
|
|
31
|
+
* @param {number|string} val2 The second factor.
|
|
32
|
+
* @returns {number} The product of the two values.
|
|
33
|
+
* @example
|
|
34
|
+
* ```handlebars
|
|
35
|
+
* {{!-- results in: 500 --}}
|
|
36
|
+
* {{multiply quantity unitPrice}}
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare const multiply: (val1: number | string, val2: number | string) => number;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the quotient of two numbers (`val1 / val2`).
|
|
42
|
+
* String values are automatically converted to numbers.
|
|
43
|
+
* @param {number|string} val1 The dividend.
|
|
44
|
+
* @param {number|string} val2 The divisor.
|
|
45
|
+
* @returns {number} The quotient of the two values.
|
|
46
|
+
* @example
|
|
47
|
+
* ```handlebars
|
|
48
|
+
* {{!-- results in: 5 --}}
|
|
49
|
+
* {{divide 10 2}}
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const divide: (val1: number | string, val2: number | string) => number;
|
|
53
|
+
/**
|
|
54
|
+
* Rounds a number up to the nearest integer.
|
|
55
|
+
* @param {number|string} val The number to round up.
|
|
56
|
+
* @returns {number} The smallest integer greater than or equal to the given number.
|
|
57
|
+
* @example
|
|
58
|
+
* ```handlebars
|
|
59
|
+
* {{!-- results in: 6 --}}
|
|
60
|
+
* {{ceil 5.1}}
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const ceil: (val: number | string) => number;
|
|
64
|
+
/**
|
|
65
|
+
* Rounds a number down to the nearest integer.
|
|
66
|
+
* @param {number|string} val The number to round down.
|
|
67
|
+
* @returns {number} The largest integer less than or equal to the given number.
|
|
68
|
+
* @example
|
|
69
|
+
* ```handlebars
|
|
70
|
+
* {{!-- results in: 5 --}}
|
|
71
|
+
* {{floor 5.9}}
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const floor: (val: number | string) => number;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the absolute value of a number.
|
|
77
|
+
* @param {number|string} val The number to compute the absolute value of.
|
|
78
|
+
* @returns {number} The non-negative value.
|
|
79
|
+
* @example
|
|
80
|
+
* ```handlebars
|
|
81
|
+
* {{!-- results in: 5.6 --}}
|
|
82
|
+
* {{abs -5.6}}
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare const abs: (val: number | string) => number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number as a locale-aware string using `Number.prototype.toLocaleString()`.
|
|
3
|
+
* Adds thousands separators and uses locale-specific decimal separators.
|
|
4
|
+
* @param {number|string} val The number or numeric string to format.
|
|
5
|
+
* @param {string} locales A BCP 47 language tag (e.g., `'en-US'`, `'de-DE'`, `'ja-JP'`). Defaults to the runtime's default locale.
|
|
6
|
+
* @returns {string} The locale-formatted number string.
|
|
7
|
+
* @example
|
|
8
|
+
* ```handlebars
|
|
9
|
+
* {{!-- results in: 123,456.789 (en-US) --}}
|
|
10
|
+
* {{number2locale 123456.789}}
|
|
11
|
+
*
|
|
12
|
+
* {{!-- results in: 123.456,789 (de-DE) --}}
|
|
13
|
+
* {{number2locale 123456.789 'de-DE'}}
|
|
14
|
+
*
|
|
15
|
+
* {{!-- results in: 1,000 --}}
|
|
16
|
+
* {{number2locale price 'en-US'}}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const number2locale: (val: number | string, locales?: string) => string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a value to a JSON string using `JSON.stringify`.
|
|
3
|
+
* @param {any} value The value to serialize.
|
|
4
|
+
* @param {number|string} indent Number of spaces (or a string) for indentation. Defaults to `0` (no formatting).
|
|
5
|
+
* @returns {string|undefined} The JSON string, or `undefined` if the value is `undefined`.
|
|
6
|
+
* @example
|
|
7
|
+
* ```handlebars
|
|
8
|
+
* {{!-- Embed data as JSON for JavaScript consumption --}}
|
|
9
|
+
* <script>var config = {{{jsonStringify config}}};</script>
|
|
10
|
+
*
|
|
11
|
+
* {{!-- Pretty-printed JSON (2-space indent) --}}
|
|
12
|
+
* <pre>{{{jsonStringify data 2}}}</pre>
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare const jsonStringify: (value: any, indent?: number | string) => string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a JSON string into a JavaScript value using `JSON.parse`.
|
|
18
|
+
* @param {string} value The JSON string to parse.
|
|
19
|
+
* @returns {any} The parsed JavaScript value or object.
|
|
20
|
+
* @example
|
|
21
|
+
* ```handlebars
|
|
22
|
+
* {{!-- Parse a JSON string stored in a template variable --}}
|
|
23
|
+
* {{#with (jsonParse jsonString)}}
|
|
24
|
+
* <p>{{this.name}}</p>
|
|
25
|
+
* {{/with}}
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const jsonParse: (value: any) => any;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replaces the first occurrence of a substring with a replacement string.
|
|
3
|
+
* Only the first match is replaced (same behavior as `String.prototype.replace` with a string pattern).
|
|
4
|
+
* @param {string} value The original string.
|
|
5
|
+
* @param {string} find The substring to search for.
|
|
6
|
+
* @param {string} replace The replacement string.
|
|
7
|
+
* @returns {string} The string with the first match replaced.
|
|
8
|
+
* @example
|
|
9
|
+
* ```handlebars
|
|
10
|
+
* {{!-- results in: Hello, World! --}}
|
|
11
|
+
* {{replace 'Hello, world!' 'world' 'World'}}
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const replace: (value: string, find: string, replace: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Splits a string into an array by the given separator.
|
|
17
|
+
* @param {string} value The string to split.
|
|
18
|
+
* @param {string} separator The delimiter character or string. Defaults to `','` if not a valid string.
|
|
19
|
+
* @returns {string[]} An array of substrings, or an empty array if the input is not a string.
|
|
20
|
+
* @example
|
|
21
|
+
* ```handlebars
|
|
22
|
+
* {{#each (split "red,green,blue" ",")}}<span>{{this}}</span>{{/each}}
|
|
23
|
+
* {{#each (split tags ',')}}<span class="tag">{{this}}</span>{{/each}}
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const split: (value: string, separator: string) => string[];
|
|
27
|
+
/**
|
|
28
|
+
* Converts a byte count to a human-readable string with the appropriate unit
|
|
29
|
+
* (Bytes, KB, MB, GB, TB, PB, EB, ZB, YB).
|
|
30
|
+
* @param {number} bytes The number of bytes.
|
|
31
|
+
* @param {number} decimals The number of decimal places to display. Defaults to `0`.
|
|
32
|
+
* @returns {string} The formatted string with value and unit (e.g., `"1KB"`, `"0Bytes"`).
|
|
33
|
+
* @example
|
|
34
|
+
* ```handlebars
|
|
35
|
+
* {{!-- results in: 1KB --}}
|
|
36
|
+
* {{formatBytes 1024}}
|
|
37
|
+
*
|
|
38
|
+
* {{!-- results in: 1.21KB --}}
|
|
39
|
+
* {{formatBytes 1234 2}}
|
|
40
|
+
*
|
|
41
|
+
* {{!-- results in: 0Bytes --}}
|
|
42
|
+
* {{formatBytes 0}}
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const formatBytes: (bytes: number, decimals?: number) => string;
|
package/types/index.d.ts
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
* Express Sweet streamlines web development with utilities and enhancements for Express.js applications.
|
|
5
5
|
* It provides database abstraction, authentication, view templating, routing, and various middleware components.
|
|
6
6
|
*
|
|
7
|
-
* @module express-sweet
|
|
8
|
-
* @author Takuya Motoshima
|
|
9
|
-
* @see {@link https://github.com/takuya-motoshima/express-sweet | Express Sweet Repository}
|
|
10
7
|
* @example
|
|
11
8
|
* ```js
|
|
12
9
|
* // Basic usage
|
|
@@ -30,9 +27,9 @@ export { default as mount } from './mount';
|
|
|
30
27
|
*/
|
|
31
28
|
export * as database from './database';
|
|
32
29
|
/**
|
|
33
|
-
*
|
|
30
|
+
* User authentication service
|
|
34
31
|
*/
|
|
35
|
-
export
|
|
32
|
+
export { Authentication } from './middleware/auth';
|
|
36
33
|
/**
|
|
37
34
|
* Utility functions for type checking and configuration loading
|
|
38
35
|
*/
|
|
@@ -40,12 +37,12 @@ export * as utils from './utils';
|
|
|
40
37
|
/**
|
|
41
38
|
* Express middleware components
|
|
42
39
|
*/
|
|
43
|
-
export * as
|
|
40
|
+
export * as middleware from './middleware';
|
|
44
41
|
/**
|
|
45
|
-
* TypeScript
|
|
42
|
+
* TypeScript type definitions for configuration
|
|
46
43
|
*/
|
|
47
|
-
export * as
|
|
44
|
+
export * as types from './types';
|
|
48
45
|
/**
|
|
49
46
|
* Custom Handlebars template helpers
|
|
50
47
|
*/
|
|
51
|
-
export * as
|
|
48
|
+
export * as helpers from './helpers';
|