express-sweet 1.0.32 → 1.0.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-sweet",
3
- "version": "1.0.32",
3
+ "version": "1.0.33",
4
4
  "description": "Express framework extension.",
5
5
  "main": "dist/build.common.js",
6
6
  "module": "dist/build.esm.js",
@@ -180,7 +180,7 @@ export default class Model extends sequelize.Model {
180
180
  * await transaction.commit();
181
181
  *
182
182
  * // Check the update result.
183
- * // Output: New title of book: When Im Gone
183
+ * // results in: New title of book: When Im Gone
184
184
  * await book.reload();
185
185
  * console.log(`New title of book: ${book.title}`);
186
186
  * } catch (err) {
@@ -2,7 +2,8 @@
2
2
  * Determine whether or not two values are equal (===).
3
3
  *
4
4
  * @example
5
- * {{eq '3' 3}} => false
5
+ * {{!-- results in: false --}}
6
+ * {{eq '3' 3}}
6
7
  *
7
8
  * {{#if (eqw foo 'bar')}}
8
9
  * Hello
@@ -17,11 +18,12 @@ export declare function eq(value1: any, value2: any): boolean;
17
18
  * Determine whether or not two values are equal (==) i.e weak checking.
18
19
  *
19
20
  * @example
20
- * {{eqw '3' 3}} => true
21
+ * {{!-- results in: true --}}
22
+ * {{eqw '3' 3}}
21
23
  *
22
24
  * {{#if (eqw foo 'bar')}}
23
25
  * Hello
24
- * {{/if}}
26
+ * {/if}}
25
27
  *
26
28
  * @param {any} value1 First value to be compared with second.
27
29
  * @param {any} value2 Second value to be compared with first.
@@ -32,7 +34,8 @@ export declare function eqw(value1: any, value2: any): boolean;
32
34
  * Determine whether or not two values are not equal (!==).
33
35
  *
34
36
  * @example
35
- * {{neq 4 3}} => true
37
+ * {{!-- results in: true --}}
38
+ * {{neq 4 3}}
36
39
  *
37
40
  * {{#if (neq foo 'bar')}}
38
41
  * Hello
@@ -47,7 +50,8 @@ export declare function neq(value1: any, value2: any): boolean;
47
50
  * Determine whether or not two values are not equal (!=) weak checking.
48
51
  *
49
52
  * @example
50
- * {{neqw '3' 3}} => false
53
+ * {{!-- results in: false --}}
54
+ * {{neqw '3' 3}}
51
55
  *
52
56
  * {{#if (neqw foo 'bar')}}
53
57
  * Hello
@@ -62,7 +66,8 @@ export declare function neqw(value1: any, value2: any): boolean;
62
66
  * Check for less than condition (a < b).
63
67
  *
64
68
  * @example
65
- * {{lt 2 3}} => true
69
+ * {{!-- results in: true --}}
70
+ * {{lt 2 3}}
66
71
  *
67
72
  * {{#if (lt 2 5)}}
68
73
  * Hello
@@ -77,7 +82,8 @@ export declare function lt(value1: any, value2: any): boolean;
77
82
  * Check for less than or equals condition (a <= b).
78
83
  *
79
84
  * @example
80
- * {{lte 2 3}} => true
85
+ * {{!-- results in: true --}}
86
+ * {{lte 2 3}}
81
87
  *
82
88
  * {{#if (lte 2 5)}}
83
89
  * Hello
@@ -92,7 +98,8 @@ export declare function lte(value1: any, value2: any): boolean;
92
98
  * Check for greater than condition (a > b).
93
99
  *
94
100
  * @example
95
- * {{gt 2 3}} => false
101
+ * {{!-- results in: false --}}
102
+ * {{gt 2 3}}
96
103
  *
97
104
  * {{#if (gt 5 6)}}
98
105
  * Hello
@@ -107,7 +114,8 @@ export declare function gt(value1: any, value2: any): boolean;
107
114
  * Check for greater than or equals condition (a >= b).
108
115
  *
109
116
  * @example
110
- * {{gte 3 3}} => true
117
+ * {{!-- results in: true --}}
118
+ * {{gte 3 3}}
111
119
  *
112
120
  * {{#if (gte 10 2)}}
113
121
  * Hello
@@ -122,8 +130,11 @@ export declare function gte(value1: any, value2: any): boolean;
122
130
  * Logical NOT of any expression.
123
131
  *
124
132
  * @example
125
- * {{not true}} => false
126
- * {{not false}} => true
133
+ * {{!-- results in: false --}}
134
+ * {{not true}}
135
+ *
136
+ * {{!-- results in: true --}}
137
+ * {{not false}}
127
138
  *
128
139
  * {{#if (not (eq foo 'bar'))}}
129
140
  * Hello
@@ -137,14 +148,24 @@ export declare function not(expression: any): boolean;
137
148
  * Helper to imitate the ternary '?:' conditional operator.
138
149
  *
139
150
  * @example
140
- * {{ifx true 'Foo' 'Bar'}} => Foo
141
- * {{ifx false 'Foo' 'Bar'}} => Foo
142
- * {{ifx (eq value 1) 5 6}} => 6 // return (value === 1) ? 5 : 6
143
- * {{ifx (not (eq value 1)) 5 6}} => 6 // return (value !== 1) ? 5 : 6
151
+ * {{!-- results in: foo --}}
152
+ * {{ifx true 'foo' 'bar'}}
153
+ *
154
+ * {{!-- results in: bar --}}
155
+ * {{ifx false 'foo' 'bar'}}
156
+ *
157
+ * {{!-- results in: 6 --}}
158
+ * {{ifx (eq value 1) 5 6}}
159
+ *
160
+ * {{!-- results in: 6 --}}
161
+ * {{ifx (not (eq value 1)) 5 6}}
144
162
  *
145
163
  * {{!-- The third parameter is optional, and by default it will be blank string ('') --}}
146
- * {{ifx true 'active'}} => 'active'
147
- * {{ifx false 'active'}} => ''
164
+ * {{!-- results in: active --}}
165
+ * {{ifx true 'active'}}
166
+ *
167
+ * {{!-- results in: '' --}}
168
+ * {{ifx false 'active'}}
148
169
  *
149
170
  * @param {boolean} condition Satisfying condition for getting first value. Either true of false.
150
171
  * @param {any} value1 First value to be displayed as result..
@@ -158,23 +179,21 @@ export declare function ifx(condition: boolean, value1: any, value2: any): any;
158
179
  * If the value is a string, the leading and trailing spaces are trimmed and then checked.
159
180
  *
160
181
  * @example
161
- * // If the value is an array.
162
- * let value = [5, 6];
163
- * {{empty value}} => false
182
+ * {{!-- results in: false --}}
183
+ * {{empty [5, 6]}}
164
184
  *
165
- * {{#if (empty value)}}
185
+ * {{#if (empty 'foo')}}
166
186
  * Hello
167
187
  * {{/if}}
168
188
  *
169
- * // If the value is a string.
170
- * let value = 'Hello';
171
- * {{empty value}} => false
189
+ * {{!-- results in: false --}}
190
+ * {{empty 'Hello'}}
172
191
  *
173
- * let value = '';
174
- * {{empty value}} => true
192
+ * {{!-- results in: true --}}
193
+ * {{empty ''}}
175
194
  *
176
- * let value = ' ';
177
- * {{empty value}} => true
195
+ * {{!-- results in: true --}}
196
+ * {{empty ' '}}
178
197
  *
179
198
  * @param {any} value Character strings, arrays, objects, etc. to be checked.
180
199
  * @returns {boolean} Returns true if the value is empty, false otherwise.
@@ -186,23 +205,21 @@ export declare function empty(value: any): boolean;
186
205
  * If the value is a string, the leading and trailing spaces are trimmed and then checked.
187
206
  *
188
207
  * @example
189
- * // If the value is an array.
190
- * let value = [5, 6];
191
- * {{notEmpty value}} => true
208
+ * {{!-- results in: true --}}
209
+ * {{notEmpty [5, 6]}}
192
210
  *
193
- * {{#if (notEmpty value)}}
211
+ * {{#if (notEmpty 'foo')}}
194
212
  * Hello
195
213
  * {{/if}}
196
214
  *
197
- * // If the value is a string.
198
- * let value = 'Hello';
199
- * {{notEmpty value}} => true
215
+ * {{!-- results in: true --}}
216
+ * {{notEmpty 'Hello'}}
200
217
  *
201
- * let value = '';
202
- * {{notEmpty value}} => false
218
+ * {{!-- results in: false --}}
219
+ * {{notEmpty ''}}
203
220
  *
204
- * let value = ' ';
205
- * {{notEmpty value}} => false
221
+ * {{!-- results in: false --}}
222
+ * {{notEmpty ' '}}
206
223
  *
207
224
  * @param {any} value Character strings, arrays, objects, etc. to be checked.
208
225
  * @returns {boolean} Returns true if the value is not empty, false otherwise.
@@ -212,8 +229,8 @@ export declare function notEmpty(value: any): boolean;
212
229
  * Determine the length of an array.
213
230
  *
214
231
  * @example
215
- * let items = [5, 6];
216
- * {{count items}} => 2
232
+ * {{!-- results in: 2 --}}
233
+ * {{count [5, 6]}}
217
234
  *
218
235
  * @param {any[]} items Array whose elements to be counted.
219
236
  * @returns {number|false} Returns the length of the array if the value is an array, false if the value is not an array.
@@ -223,16 +240,16 @@ export declare function count(items: any[]): number | false;
223
240
  * Returns the boolean AND of two or more parameters passed i.e it is true iff all the parameters are true.
224
241
  *
225
242
  * @example
226
- * let value1 = value2 = true;
227
- * {{and value1 value2}} => true
243
+ * {{!-- results in: true --}}
244
+ * {{and true true}}
228
245
  *
229
- * let value1 = false, value2 = true;
230
- * {{and value1 value2}} => false
246
+ * {{!-- results in: false --}}
247
+ * {{and false true}}
231
248
  *
232
249
  * {{#if (and value1 value2)}}
233
- * // do something
250
+ * {{!-- do something --}}
234
251
  * {{else}}
235
- * // do something else
252
+ * {{!-- do something else --}}
236
253
  * {{/if}}
237
254
  *
238
255
  * @param {...any} params Any number of boolean parameters.
@@ -243,16 +260,16 @@ export declare function and(...params: any[]): boolean;
243
260
  * Returns the boolean OR of two or more parameters passed i.e it is true if any of the parameters is true.
244
261
  *
245
262
  * @example
246
- * let value1 = true, value2 = false;
247
- * {{or value1 value2}} => true
263
+ * {{!-- results in: true --}}
264
+ * {{or true false}}
248
265
  *
249
- * let value = value2 = false;
250
- * {{or value1 value2}} => false
266
+ * {{!-- results in: false --}}
267
+ * {{or false false}}
251
268
  *
252
269
  * {{#if (or value1 value2)}}
253
- * // do something
270
+ * {{!-- do something --}}
254
271
  * {{else}}
255
- * // do something else
272
+ * {{!-- do something else --}}
256
273
  * {{/if}}
257
274
  *
258
275
  * @param {...any} params Any number of boolean parameters.
@@ -264,11 +281,11 @@ export declare function or(...params: any[]): boolean;
264
281
  * Works quite similar to the SQL's "COALESCE()" function, but unlike this checks for the first non-false parameter.
265
282
  *
266
283
  * @example
267
- * let fullName = 'Foo Bar', nickName = 'foob';
268
- * {{coalesce fullName nickName 'Unknown'}} => 'Foo Bar'
284
+ * {{!-- results in: foo bar --}}
285
+ * {{coalesce 'foo bar' 'foob' 'unknown'}}
269
286
  *
270
- * let fullName = '', nickName = 'foob';
271
- * {{coalesce fullName nickName 'Unknown'}} => 'foob'
287
+ * {{!-- results in: foob --}}
288
+ * {{coalesce '' 'foob' 'unknown'}}
272
289
  *
273
290
  * @param {...any} params Any number of parameters.
274
291
  * @returns {any} Returns the first non-false element of the parameter.
@@ -278,21 +295,23 @@ export declare function coalesce(...params: any[]): any;
278
295
  * Returns boolean if the array contains the element strictly or non-strictly.
279
296
  *
280
297
  * @example
281
- * let items = [1, 2, 3];
282
- * let value = 2;
298
+ * {{!-- results in: true --}}
299
+ * {{includes [1, 2, 3] 2}}
300
+ *
301
+ * {{!-- results in: false --}}
302
+ * {{includes [1, 2, 3] '2'}}
283
303
  *
284
- * {{includes items value}} => true
304
+ * {{!-- results in: false --}}
305
+ * {{includes [1, 2, 3] '2' true}}
285
306
  *
286
- * let value = '2'
287
- * {{includes items value}} => false
288
- * {{includes items value true}} => false
289
- * {{includes items value false}} => true
307
+ * {{!-- results in: true --}}
308
+ * {{includes [1, 2, 3] '2' false}}
290
309
  *
291
- * {{#if (includes items value)}}
310
+ * {{#if (includes [1, 2, 3] '2')}}
292
311
  * {{!-- Do something --}}
293
312
  * {{/if}}
294
313
  *
295
- * {{ifx (includes items value) 'Yes' 'No'}}
314
+ * {{ifx (includes [1, 2, 3] '2') 'yes' 'no'}}
296
315
  *
297
316
  * @param {any[]} items The array.
298
317
  * @param {any} value The value to be checked for existence in the array.
@@ -300,3 +319,33 @@ export declare function coalesce(...params: any[]): any;
300
319
  * @returns {boolean} Returns true if the array contains the specified value, false otherwise.
301
320
  */
302
321
  export declare function includes(items: any[], value: any, strict?: boolean): boolean;
322
+ /**
323
+ * Returns true if the given str matches the given regex.
324
+ *
325
+ * @example
326
+ * {{!-- results in: true --}}
327
+ * {{regexMatch 'foobar' 'foo'}}
328
+ *
329
+ * {{!-- results in: false --}}
330
+ * {{regexMatch 'bar' 'foo'}}
331
+ *
332
+ * {{!-- results in: false --}}
333
+ * {{regexMatch 'foobar' '^foo$'}}
334
+ *
335
+ * {{!-- results in: true --}}
336
+ * {{regexMatch 'Visit Here' 'here' 'i'}}
337
+ *
338
+ * {{!-- results in: false --}}
339
+ * {{regexMatch 'Visit Here' 'here'}}
340
+ *
341
+ * {{!-- results in: Match --}}
342
+ * {{#if (regexMatch 'foobar' 'foo')}}
343
+ * Match
344
+ * {{/if}}
345
+ *
346
+ * @param {string} val The string against which to match the regular expression.
347
+ * @param {string} pattern The text of the regular expression.
348
+ * @param {string} flags? Regular expression flags, such as global and case-insensitive searches. The default is none (undefined).
349
+ * @returns {boolean} true if there is a match between the regular expression and the string str. Otherwise, false.
350
+ */
351
+ export declare function regexMatch(val: string, pattern: string, flags?: string): boolean;
@@ -2,9 +2,14 @@
2
2
  * Use moment to format the date.
3
3
  *
4
4
  * @example
5
- * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z"}} => 2021/10/24
6
- * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'jp'}} => 2021/10/24
7
- * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'es'}} => 2021/10/24
5
+ * {{!-- results in: 2021/10/24 --}}
6
+ * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z"}}
7
+ *
8
+ * {{!-- results in: 2021/10/24 --}}
9
+ * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'jp'}}
10
+ *
11
+ * {{!-- results in: 2021/10/24 --}}
12
+ * {{formatDate 'YYYY/MM/DD' "2021-10-24T02:13:06.610Z" 'es'}}
8
13
  *
9
14
  * @param {string} format A format string based on moment.
10
15
  * @param {string} date Date string to format.
@@ -2,7 +2,8 @@
2
2
  * Returns the Assets path containing the file update time parameter.
3
3
  *
4
4
  * @example
5
- * {{cacheBusting '/assets/style.css' '//example.com'}} => example.com/assets/style.css?1620526340463
5
+ * {{!-- results in: example.com/assets/style.css?1620526340463 --}}
6
+ * {{cacheBusting '/assets/style.css' '//example.com'}}
6
7
  *
7
8
  * @param {string} filePath Paths of Assets files such as CSS and JS in public directories.
8
9
  * @param {string} baseUrl Application Origin URL. The default is none (undefined).
@@ -2,10 +2,12 @@
2
2
  * Returns the language-sensitive representation of a number as a string.
3
3
  *
4
4
  * @example
5
- * {{number2locale 123456.789}} => 123,456.789
5
+ * {{!-- results in: 123,456.789 --}}
6
+ * {{number2locale 123456.789}}
6
7
  *
7
8
  * {{!-- German uses comma as decimal separator and period for thousands. --}}
8
- * {{number2locale 123456.789 'de-DE'}} => 123.456,789
9
+ * {{!-- results in: 123.456,789 --}}
10
+ * {{number2locale 123456.789 'de-DE'}}
9
11
  *
10
12
  * @param {number|string} val Target number or numeric string.
11
13
  * @param {string|undefined} locales A string with a BCP 47 language tag, or an array of such strings.
@@ -4,9 +4,9 @@
4
4
  * @example
5
5
  * {{jsonStringify value}}
6
6
  *
7
- * @param {any} value The value to convert to a JSON string.
8
- * @param {number} indent The number of space characters to use as whitespace.
9
- * @return {string} A JSON string representing the given value, or undefined.
7
+ * @param {any} value The value to convert to a JSON string.
8
+ * @param {number} indent The number of space characters to use as whitespace.
9
+ * @return {string} A JSON string representing the given value, or undefined.
10
10
  */
11
11
  export declare function jsonStringify(value: any, indent?: number | string): string | undefined;
12
12
  /**
@@ -15,7 +15,7 @@ export declare function jsonStringify(value: any, indent?: number | string): str
15
15
  * @example
16
16
  * {{jsonParse value}}
17
17
  *
18
- * @param {any} value Object to stringify.
19
- * @return {any} JavaScript value or object described by a string.
18
+ * @param {any} value Object to stringify.
19
+ * @return {any} JavaScript value or object described by a string.
20
20
  */
21
21
  export declare function jsonParse(value: any): any;
@@ -14,16 +14,13 @@ export declare function replace(value: string, find: string, replace: string): s
14
14
  * Split `string` by the given `character`.
15
15
  *
16
16
  * @example
17
- * {{!-- Basic usage. --}}
18
- * {{split "a,b,c" ","}} => ['a', 'b', 'c']
17
+ * {{!-- results in: ['a', 'b', 'c'] --}}
18
+ * {{split "a,b,c" ","}}
19
19
  *
20
- * {{!-- Use with EACH. --}}
20
+ * {{!-- results in: <div>a</div><div>b</div><div>c</div> --}}
21
21
  * {{#each (split list ',')}}
22
- * {{this}}<br>
22
+ * <div>{{this}}</div>
23
23
  * {{/each}}
24
- * => a<br>
25
- * b<br>
26
- * c<br>
27
24
  *
28
25
  * @param {string} value String.
29
26
  * @param {string} separator A character that delimits the substrings in this string. Default is a comma.
@@ -34,10 +31,17 @@ export declare function split(value: string, separator: string): string[];
34
31
  * Convert bytes to just the right units(KB, MB, GB, TB, PB, EB, ZB, YB).
35
32
  *
36
33
  * @example
37
- * {{formatBytes 1024}} => 1 KB
38
- * {{formatBytes 1234 2}} => 1.21 KB
39
- * {{formatBytes 1234 3}} => 1.205 KB
40
- * {{formatBytes 0}} => 0 Bytes
34
+ * {{!-- results in: 1 KB --}}
35
+ * {{formatBytes 1024}}
36
+ *
37
+ * {{!-- results in: 1.21 KB --}}
38
+ * {{formatBytes 1234 2}}
39
+ *
40
+ * {{!-- results in: 1.205 KB --}}
41
+ * {{formatBytes 1234 3}}
42
+ *
43
+ * {{!-- results in: 0 Bytes --}}
44
+ * {{formatBytes 0}}
41
45
  *
42
46
  * @param {number} bytes Bytes.
43
47
  * @param {number} decimals Number of decimal places to display. Default is 0.
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Set environment variables.
3
- *
4
3
  * Read the environment variable file in options.path and set it in "process.env".
5
4
  */
6
5
  export default class {
@@ -2,7 +2,6 @@ import express from 'express';
2
2
  /**
3
3
  * Set local variables.
4
4
  * It can be accessed in all views as {{var}} or {{{var}}}.
5
- *
6
5
  * Below is a description of the variables.
7
6
  * baseUrl: The base URL for this application.
8
7
  */