@tsed/cli-core 6.1.13 → 6.1.15
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/lib/esm/services/index.js +0 -2
- package/lib/types/services/index.d.ts +0 -2
- package/package.json +2 -8
- package/lib/esm/services/CliRunScript.js +0 -22
- package/lib/esm/services/Renderer.js +0 -162
- package/lib/esm/utils/hbs/array.js +0 -515
- package/lib/esm/utils/hbs/collection.js +0 -60
- package/lib/esm/utils/hbs/comparison.js +0 -431
- package/lib/esm/utils/hbs/index.js +0 -11
- package/lib/esm/utils/hbs/object.js +0 -236
- package/lib/esm/utils/hbs/switch.js +0 -10
- package/lib/esm/utils/renderer/insertAfter.js +0 -12
- package/lib/esm/utils/renderer/insertImport.js +0 -11
- package/lib/types/services/CliRunScript.d.ts +0 -3
- package/lib/types/services/Renderer.d.ts +0 -44
- package/lib/types/utils/hbs/array.d.ts +0 -1
- package/lib/types/utils/hbs/collection.d.ts +0 -1
- package/lib/types/utils/hbs/comparison.d.ts +0 -1
- package/lib/types/utils/hbs/index.d.ts +0 -1
- package/lib/types/utils/hbs/object.d.ts +0 -1
- package/lib/types/utils/hbs/switch.d.ts +0 -1
- package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
- package/lib/types/utils/renderer/insertImport.d.ts +0 -1
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
import { isNumber } from "@tsed/core";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import util from "handlebars-utils";
|
|
4
|
-
export const helpers = {};
|
|
5
|
-
const contains = (val, obj, start) => {
|
|
6
|
-
if (val == null || obj == null || !isNumber(val.length)) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
return val.indexOf(obj, start) !== -1;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Helper that renders the block if **both** of the given values
|
|
13
|
-
* are truthy. If an inverse block is specified it will be rendered
|
|
14
|
-
* when falsy. Works as a block helper, inline helper or
|
|
15
|
-
* subexpression.
|
|
16
|
-
*
|
|
17
|
-
* ```handlebars
|
|
18
|
-
* <!-- {great: true, magnificent: true} -->
|
|
19
|
-
* {{#and great magnificent}}A{{else}}B{{/and}}
|
|
20
|
-
* <!-- results in: 'A' -->
|
|
21
|
-
* ```
|
|
22
|
-
* @param {any} `a`
|
|
23
|
-
* @param {any} `b`
|
|
24
|
-
* @param {Object} `options` Handlebars provided options object
|
|
25
|
-
* @return {String}
|
|
26
|
-
* @block
|
|
27
|
-
* @api public
|
|
28
|
-
*/
|
|
29
|
-
helpers.and = (...args) => {
|
|
30
|
-
const len = args.length - 1;
|
|
31
|
-
const options = args[len];
|
|
32
|
-
let val = true;
|
|
33
|
-
for (let i = 0; i < len; i++) {
|
|
34
|
-
if (!args[i]) {
|
|
35
|
-
val = false;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return util.value(val, this, options);
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Render a block when a comparison of the first and third
|
|
43
|
-
* arguments returns true. The second argument is
|
|
44
|
-
* the [arithemetic operator][operators] to use. You may also
|
|
45
|
-
* optionally specify an inverse block to render when falsy.
|
|
46
|
-
*
|
|
47
|
-
* @param `a`
|
|
48
|
-
* @param `operator` The operator to use. Operators must be enclosed in quotes: `">"`, `"="`, `"<="`, and so on.
|
|
49
|
-
* @param `b`
|
|
50
|
-
* @param {Object} `options` Handlebars provided options object
|
|
51
|
-
* @return {String} Block, or if specified the inverse block is rendered if falsey.
|
|
52
|
-
* @block
|
|
53
|
-
* @api public
|
|
54
|
-
*/
|
|
55
|
-
helpers.compare = function (a, operator, b, options) {
|
|
56
|
-
/*eslint eqeqeq: 0*/
|
|
57
|
-
if (arguments.length < 4) {
|
|
58
|
-
throw new Error("handlebars Helper {{compare}} expects 4 arguments");
|
|
59
|
-
}
|
|
60
|
-
let result;
|
|
61
|
-
switch (operator) {
|
|
62
|
-
case "==":
|
|
63
|
-
result = a == b;
|
|
64
|
-
break;
|
|
65
|
-
case "===":
|
|
66
|
-
result = a === b;
|
|
67
|
-
break;
|
|
68
|
-
case "!=":
|
|
69
|
-
result = a != b;
|
|
70
|
-
break;
|
|
71
|
-
case "!==":
|
|
72
|
-
result = a !== b;
|
|
73
|
-
break;
|
|
74
|
-
case "<":
|
|
75
|
-
result = a < b;
|
|
76
|
-
break;
|
|
77
|
-
case ">":
|
|
78
|
-
result = a > b;
|
|
79
|
-
break;
|
|
80
|
-
case "<=":
|
|
81
|
-
result = a <= b;
|
|
82
|
-
break;
|
|
83
|
-
case ">=":
|
|
84
|
-
result = a >= b;
|
|
85
|
-
break;
|
|
86
|
-
case "typeof":
|
|
87
|
-
result = typeof a === b;
|
|
88
|
-
break;
|
|
89
|
-
default: {
|
|
90
|
-
throw new Error("helper {{compare}}: invalid operator: `" + operator + "`");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return util.value(result, this, options);
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Block helper that renders the block if `collection` has the
|
|
97
|
-
* given `value`, using strict equality (`===`) for comparison,
|
|
98
|
-
* otherwise the inverse block is rendered (if specified). If a
|
|
99
|
-
* `startIndex` is specified and is negative, it is used as the
|
|
100
|
-
* offset from the end of the collection.
|
|
101
|
-
*
|
|
102
|
-
* ```handlebars
|
|
103
|
-
* <!-- array = ['a', 'b', 'c'] -->
|
|
104
|
-
* {{#contains array "d"}}
|
|
105
|
-
* This will not be rendered.
|
|
106
|
-
* {{else}}
|
|
107
|
-
* This will be rendered.
|
|
108
|
-
* {{/contains}}
|
|
109
|
-
* ```
|
|
110
|
-
* @param {Array|Object|String} `collection` The collection to iterate over.
|
|
111
|
-
* @param {any} `value` The value to check for.
|
|
112
|
-
* @param {Number} `[startIndex=0]` Optionally define the starting index.
|
|
113
|
-
* @param {Object} `options` Handlebars provided options object.
|
|
114
|
-
* @block
|
|
115
|
-
* @api public
|
|
116
|
-
*/
|
|
117
|
-
helpers.contains = function (collection, value, startIndex, options) {
|
|
118
|
-
if (typeof startIndex === "object") {
|
|
119
|
-
options = startIndex;
|
|
120
|
-
startIndex = undefined;
|
|
121
|
-
}
|
|
122
|
-
const val = contains(collection, value, startIndex);
|
|
123
|
-
return util.value(val, this, options);
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Returns the first value that is not undefined, otherwise the "default" value is returned.
|
|
127
|
-
*
|
|
128
|
-
* @param {any} `value`
|
|
129
|
-
* @param {any} `defaultValue`
|
|
130
|
-
* @return {String}
|
|
131
|
-
* @alias .or
|
|
132
|
-
* @api public
|
|
133
|
-
*/
|
|
134
|
-
helpers.default = (...args) => {
|
|
135
|
-
for (let i = 0; i < args.length - 1; i++) {
|
|
136
|
-
if (args[i] != null)
|
|
137
|
-
return args[i];
|
|
138
|
-
}
|
|
139
|
-
return "";
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* Block helper that renders a block if `a` is **equal to** `b`.
|
|
143
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
144
|
-
* You may optionally use the `compare=""` hash argument for the
|
|
145
|
-
* second value.
|
|
146
|
-
*
|
|
147
|
-
* @param {String} `a`
|
|
148
|
-
* @param {String} `b`
|
|
149
|
-
* @param {Object} `options` Handlebars provided options object
|
|
150
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
151
|
-
* @alias is
|
|
152
|
-
* @block
|
|
153
|
-
* @api public
|
|
154
|
-
*/
|
|
155
|
-
helpers.eq = function (a, b, options) {
|
|
156
|
-
if (arguments.length === 2) {
|
|
157
|
-
options = b;
|
|
158
|
-
b = options.hash.compare;
|
|
159
|
-
}
|
|
160
|
-
return util.value(a === b, this, options);
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Block helper that renders a block if `a` is **greater than** `b`.
|
|
164
|
-
*
|
|
165
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
166
|
-
* You may optionally use the `compare=""` hash argument for the
|
|
167
|
-
* second value.
|
|
168
|
-
*
|
|
169
|
-
* @param {String} `a`
|
|
170
|
-
* @param {String} `b`
|
|
171
|
-
* @param {Object} `options` Handlebars provided options object
|
|
172
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
173
|
-
* @block
|
|
174
|
-
* @api public
|
|
175
|
-
*/
|
|
176
|
-
helpers.gt = function (a, b, options) {
|
|
177
|
-
if (arguments.length === 2) {
|
|
178
|
-
options = b;
|
|
179
|
-
b = options.hash.compare;
|
|
180
|
-
}
|
|
181
|
-
return util.value(a > b, this, options);
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* Block helper that renders a block if `a` is **greater than or
|
|
185
|
-
* equal to** `b`.
|
|
186
|
-
*
|
|
187
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
188
|
-
* You may optionally use the `compare=""` hash argument for the
|
|
189
|
-
* second value.
|
|
190
|
-
*
|
|
191
|
-
* @param {String} `a`
|
|
192
|
-
* @param {String} `b`
|
|
193
|
-
* @param {Object} `options` Handlebars provided options object
|
|
194
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
195
|
-
* @block
|
|
196
|
-
* @api public
|
|
197
|
-
*/
|
|
198
|
-
helpers.gte = function (a, b, options) {
|
|
199
|
-
if (arguments.length === 2) {
|
|
200
|
-
options = b;
|
|
201
|
-
b = options.hash.compare;
|
|
202
|
-
}
|
|
203
|
-
return util.value(a >= b, this, options);
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* Block helper that renders a block if `a` is **equal to** `b`.
|
|
207
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
208
|
-
* Similar to [eq](#eq) but does not do strict equality.
|
|
209
|
-
*
|
|
210
|
-
* @param {any} `a`
|
|
211
|
-
* @param {any} `b`
|
|
212
|
-
* @param {Object} `options` Handlebars provided options object
|
|
213
|
-
* @return {String}
|
|
214
|
-
* @block
|
|
215
|
-
* @api public
|
|
216
|
-
*/
|
|
217
|
-
helpers.is = function (a, b, options) {
|
|
218
|
-
if (arguments.length === 2) {
|
|
219
|
-
options = b;
|
|
220
|
-
b = options.hash.compare;
|
|
221
|
-
}
|
|
222
|
-
return util.value(a == b, this, options);
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* Block helper that renders a block if `a` is **not equal to** `b`.
|
|
226
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
227
|
-
* Similar to [unlessEq](#unlesseq) but does not use strict equality for
|
|
228
|
-
* comparisons.
|
|
229
|
-
*
|
|
230
|
-
* @param {String} `a`
|
|
231
|
-
* @param {String} `b`
|
|
232
|
-
* @param {Object} `options` Handlebars provided options object
|
|
233
|
-
* @return {String}
|
|
234
|
-
* @block
|
|
235
|
-
* @api public
|
|
236
|
-
*/
|
|
237
|
-
helpers.isnt = function (a, b, options) {
|
|
238
|
-
if (arguments.length === 2) {
|
|
239
|
-
options = b;
|
|
240
|
-
b = options.hash.compare;
|
|
241
|
-
}
|
|
242
|
-
return util.value(a != b, this, options);
|
|
243
|
-
};
|
|
244
|
-
/**
|
|
245
|
-
* Block helper that renders a block if `a` is **less than** `b`.
|
|
246
|
-
*
|
|
247
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
248
|
-
* You may optionally use the `compare=""` hash argument for the
|
|
249
|
-
* second value.
|
|
250
|
-
*
|
|
251
|
-
* @param {Object} `context`
|
|
252
|
-
* @param {Object} `options` Handlebars provided options object
|
|
253
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
254
|
-
* @block
|
|
255
|
-
* @api public
|
|
256
|
-
*/
|
|
257
|
-
helpers.lt = function (a, b, options) {
|
|
258
|
-
if (arguments.length === 2) {
|
|
259
|
-
options = b;
|
|
260
|
-
b = options.hash.compare;
|
|
261
|
-
}
|
|
262
|
-
return util.value(a < b, this, options);
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* Block helper that renders a block if `a` is **less than or
|
|
266
|
-
* equal to** `b`.
|
|
267
|
-
*
|
|
268
|
-
* If an inverse block is specified it will be rendered when falsy.
|
|
269
|
-
* You may optionally use the `compare=""` hash argument for the
|
|
270
|
-
* second value.
|
|
271
|
-
*
|
|
272
|
-
* @param {Sring} `a`
|
|
273
|
-
* @param {Sring} `b`
|
|
274
|
-
* @param {Object} `options` Handlebars provided options object
|
|
275
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
276
|
-
* @block
|
|
277
|
-
* @api public
|
|
278
|
-
*/
|
|
279
|
-
helpers.lte = function (a, b, options) {
|
|
280
|
-
if (arguments.length === 2) {
|
|
281
|
-
options = b;
|
|
282
|
-
b = options.hash.compare;
|
|
283
|
-
}
|
|
284
|
-
return util.value(a <= b, this, options);
|
|
285
|
-
};
|
|
286
|
-
/**
|
|
287
|
-
* Block helper that renders a block if **neither of** the given values
|
|
288
|
-
* are truthy. If an inverse block is specified it will be rendered
|
|
289
|
-
* when falsy.
|
|
290
|
-
*
|
|
291
|
-
* @param {any} `a`
|
|
292
|
-
* @param {any} `b`
|
|
293
|
-
* @param `options` Handlebars options object
|
|
294
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
295
|
-
* @block
|
|
296
|
-
* @api public
|
|
297
|
-
*/
|
|
298
|
-
helpers.neither = function (a, b, options) {
|
|
299
|
-
return util.value(!a && !b, this, options);
|
|
300
|
-
};
|
|
301
|
-
/**
|
|
302
|
-
* Returns true if `val` is falsey. Works as a block or inline helper.
|
|
303
|
-
*
|
|
304
|
-
* @param {String} `val`
|
|
305
|
-
* @param {Object} `options` Handlebars provided options object
|
|
306
|
-
* @return {String}
|
|
307
|
-
* @block
|
|
308
|
-
* @api public
|
|
309
|
-
*/
|
|
310
|
-
helpers.not = function (val, options) {
|
|
311
|
-
return util.value(!val, this, options);
|
|
312
|
-
};
|
|
313
|
-
/**
|
|
314
|
-
* Block helper that renders a block if **any of** the given values
|
|
315
|
-
* is truthy. If an inverse block is specified it will be rendered
|
|
316
|
-
* when falsy.
|
|
317
|
-
*
|
|
318
|
-
* ```handlebars
|
|
319
|
-
* {{#or a b c}}
|
|
320
|
-
* If any value is true this will be rendered.
|
|
321
|
-
* {{/or}}
|
|
322
|
-
* ```
|
|
323
|
-
*
|
|
324
|
-
* @param {...any} `arguments` Variable number of arguments
|
|
325
|
-
* @param {Object} `options` Handlebars options object
|
|
326
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
327
|
-
* @block
|
|
328
|
-
* @api public
|
|
329
|
-
*/
|
|
330
|
-
helpers.or = function (...args) {
|
|
331
|
-
const len = args.length - 1;
|
|
332
|
-
const options = args[len];
|
|
333
|
-
let val = false;
|
|
334
|
-
for (let i = 0; i < len; i++) {
|
|
335
|
-
if (args[i]) {
|
|
336
|
-
val = true;
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
return util.value(val, this, options);
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* Block helper that always renders the inverse block **unless `a` is
|
|
344
|
-
* is equal to `b`**.
|
|
345
|
-
*
|
|
346
|
-
* @param {String} `a`
|
|
347
|
-
* @param {String} `b`
|
|
348
|
-
* @param {Object} `options` Handlebars provided options object
|
|
349
|
-
* @return {String} Inverse block by default, or block if falsey.
|
|
350
|
-
* @block
|
|
351
|
-
* @api public
|
|
352
|
-
*/
|
|
353
|
-
helpers.unlessEq = function (a, b, options) {
|
|
354
|
-
if (util.isOptions(b)) {
|
|
355
|
-
options = b;
|
|
356
|
-
b = options.hash.compare;
|
|
357
|
-
}
|
|
358
|
-
return util.value(a !== b, this, options);
|
|
359
|
-
};
|
|
360
|
-
/**
|
|
361
|
-
* Block helper that always renders the inverse block **unless `a` is
|
|
362
|
-
* is greater than `b`**.
|
|
363
|
-
*
|
|
364
|
-
* @param {Object} `a` The default value
|
|
365
|
-
* @param {Object} `b` The value to compare
|
|
366
|
-
* @param {Object} `options` Handlebars provided options object
|
|
367
|
-
* @return {String} Inverse block by default, or block if falsey.
|
|
368
|
-
* @block
|
|
369
|
-
* @api public
|
|
370
|
-
*/
|
|
371
|
-
helpers.unlessGt = function (a, b, options) {
|
|
372
|
-
if (util.isOptions(b)) {
|
|
373
|
-
options = b;
|
|
374
|
-
b = options.hash.compare;
|
|
375
|
-
}
|
|
376
|
-
return util.value(a <= b, this, options);
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* Block helper that always renders the inverse block **unless `a` is
|
|
380
|
-
* is less than `b`**.
|
|
381
|
-
*
|
|
382
|
-
* @param {Object} `a` The default value
|
|
383
|
-
* @param {Object} `b` The value to compare
|
|
384
|
-
* @param {Object} `options` Handlebars provided options object
|
|
385
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
386
|
-
* @block
|
|
387
|
-
* @api public
|
|
388
|
-
*/
|
|
389
|
-
helpers.unlessLt = function (a, b, options) {
|
|
390
|
-
if (util.isOptions(b)) {
|
|
391
|
-
options = b;
|
|
392
|
-
b = options.hash.compare;
|
|
393
|
-
}
|
|
394
|
-
return util.value(a >= b, this, options);
|
|
395
|
-
};
|
|
396
|
-
/**
|
|
397
|
-
* Block helper that always renders the inverse block **unless `a` is
|
|
398
|
-
* is greater than or equal to `b`**.
|
|
399
|
-
*
|
|
400
|
-
* @param {any} `a`
|
|
401
|
-
* @param {any} `b`
|
|
402
|
-
* @param {Object} `options` Handlebars provided options object
|
|
403
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
404
|
-
* @block
|
|
405
|
-
* @api public
|
|
406
|
-
*/
|
|
407
|
-
helpers.unlessGteq = function (a, b, options) {
|
|
408
|
-
if (util.isOptions(b)) {
|
|
409
|
-
options = b;
|
|
410
|
-
b = options.hash.compare;
|
|
411
|
-
}
|
|
412
|
-
return util.value(a < b, this, options);
|
|
413
|
-
};
|
|
414
|
-
/**
|
|
415
|
-
* Block helper that always renders the inverse block **unless `a` is
|
|
416
|
-
* is less than or equal to `b`**.
|
|
417
|
-
*
|
|
418
|
-
* @param {any} `a`
|
|
419
|
-
* @param {any} `b`
|
|
420
|
-
* @param {Object} `options` Handlebars provided options object
|
|
421
|
-
* @return {String} Block, or inverse block if specified and falsey.
|
|
422
|
-
* @block
|
|
423
|
-
* @api public
|
|
424
|
-
*/
|
|
425
|
-
helpers.unlessLteq = function (a, b, options) {
|
|
426
|
-
if (util.isOptions(b)) {
|
|
427
|
-
options = b;
|
|
428
|
-
b = options.hash.compare;
|
|
429
|
-
}
|
|
430
|
-
return util.value(a > b, this, options);
|
|
431
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import handlebars from "handlebars";
|
|
2
|
-
import { helpers as array } from "./array.js";
|
|
3
|
-
import { helpers as collection } from "./collection.js";
|
|
4
|
-
import { helpers as comparison } from "./comparison.js";
|
|
5
|
-
import { helpers as object } from "./object.js";
|
|
6
|
-
import { helpers as switchHelpers } from "./switch.js";
|
|
7
|
-
handlebars.registerHelper(array);
|
|
8
|
-
handlebars.registerHelper(object);
|
|
9
|
-
handlebars.registerHelper(collection);
|
|
10
|
-
handlebars.registerHelper(comparison);
|
|
11
|
-
handlebars.registerHelper(switchHelpers);
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
import { getValue, isNumber, isObject } from "@tsed/core";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import createFrame from "create-frame";
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import util from "handlebars-utils";
|
|
6
|
-
import { helpers as array } from "./array.js";
|
|
7
|
-
const hasOwn = Object.hasOwnProperty;
|
|
8
|
-
export const helpers = {};
|
|
9
|
-
/**
|
|
10
|
-
* Extend the context with the properties of other objects.
|
|
11
|
-
* A shallow merge is performed to avoid mutating the context.
|
|
12
|
-
*
|
|
13
|
-
* @param {Object} `objects` One or more objects to extend.
|
|
14
|
-
* @return {Object}
|
|
15
|
-
* @api public
|
|
16
|
-
*/
|
|
17
|
-
helpers.extend = function ( /*objects*/) {
|
|
18
|
-
const args = [].slice.call(arguments);
|
|
19
|
-
let opts = {};
|
|
20
|
-
if (util.isOptions(args[args.length - 1])) {
|
|
21
|
-
// remove handlebars options object
|
|
22
|
-
opts = args.pop().hash;
|
|
23
|
-
// re-add handlebars options.hash object
|
|
24
|
-
args.push(opts);
|
|
25
|
-
}
|
|
26
|
-
const context = {};
|
|
27
|
-
for (let i = 0; i < args.length; i++) {
|
|
28
|
-
const obj = args[i];
|
|
29
|
-
if (util.isObject(obj)) {
|
|
30
|
-
const keys = Object.keys(obj);
|
|
31
|
-
for (let j = 0; j < keys.length; j++) {
|
|
32
|
-
const key = keys[j];
|
|
33
|
-
context[key] = obj[key];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return context;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Block helper that iterates over the properties of
|
|
41
|
-
* an object, exposing each key and value on the context.
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} `context`
|
|
44
|
-
* @param {Object} `options`
|
|
45
|
-
* @return {String}
|
|
46
|
-
* @block
|
|
47
|
-
* @api public
|
|
48
|
-
*/
|
|
49
|
-
helpers.forIn = function (obj, options) {
|
|
50
|
-
if (!util.isOptions(options)) {
|
|
51
|
-
return obj.inverse(this);
|
|
52
|
-
}
|
|
53
|
-
const data = createFrame(options, options.hash);
|
|
54
|
-
let result = "";
|
|
55
|
-
for (const key in obj) {
|
|
56
|
-
data.key = key;
|
|
57
|
-
result += options.fn(obj[key], { data: data });
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Block helper that iterates over the **own** properties of
|
|
63
|
-
* an object, exposing each key and value on the context.
|
|
64
|
-
*
|
|
65
|
-
* @param {Object} `obj` The object to iterate over.
|
|
66
|
-
* @param {Object} `options`
|
|
67
|
-
* @return {String}
|
|
68
|
-
* @block
|
|
69
|
-
* @api public
|
|
70
|
-
*/
|
|
71
|
-
helpers.forOwn = function (obj, options) {
|
|
72
|
-
if (!util.isOptions(options)) {
|
|
73
|
-
return obj.inverse(this);
|
|
74
|
-
}
|
|
75
|
-
const data = createFrame(options, options.hash);
|
|
76
|
-
let result = "";
|
|
77
|
-
for (const key in obj) {
|
|
78
|
-
if (obj.hasOwnProperty(key)) {
|
|
79
|
-
data.key = key;
|
|
80
|
-
result += options.fn(obj[key], { data: data });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
|
|
87
|
-
*
|
|
88
|
-
* @param {String|Number} `prop` The property segments to assemble (can be multiple).
|
|
89
|
-
* @return {String}
|
|
90
|
-
* @api public
|
|
91
|
-
*/
|
|
92
|
-
helpers.toPath = function (...args) {
|
|
93
|
-
const prop = [];
|
|
94
|
-
for (let i = 0; i < arguments.length; i++) {
|
|
95
|
-
if (typeof args[i] === "string" || typeof args[i] === "number") {
|
|
96
|
-
prop.push(args[i]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return prop.join(".");
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Use property paths (`a.b.c`) to get a value or nested value from
|
|
103
|
-
* the context. Works as a regular helper or block helper.
|
|
104
|
-
*
|
|
105
|
-
* @param {String} `prop` The property to get, optionally using dot notation for nested properties.
|
|
106
|
-
* @param {Object} `context` The context object
|
|
107
|
-
* @param {Object} `options` The handlebars options object, if used as a block helper.
|
|
108
|
-
* @return {String}
|
|
109
|
-
* @block
|
|
110
|
-
* @api public
|
|
111
|
-
*/
|
|
112
|
-
helpers.get = function (prop, context, options) {
|
|
113
|
-
const val = getValue(context, prop);
|
|
114
|
-
if (options && options.fn) {
|
|
115
|
-
return val ? options.fn(val) : options.inverse(context);
|
|
116
|
-
}
|
|
117
|
-
return val;
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Return true if `key` is an own, enumerable property
|
|
121
|
-
* of the given `context` object.
|
|
122
|
-
*
|
|
123
|
-
* ```handlebars
|
|
124
|
-
* {{hasOwn context key}}
|
|
125
|
-
* ```
|
|
126
|
-
*
|
|
127
|
-
* @param {String} `key`
|
|
128
|
-
* @param {Object} `context` The context object.
|
|
129
|
-
* @return {Boolean}
|
|
130
|
-
* @api public
|
|
131
|
-
*/
|
|
132
|
-
helpers.hasOwn = function (context, key) {
|
|
133
|
-
return hasOwn.call(context, key);
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Return true if `value` is an object.
|
|
137
|
-
*
|
|
138
|
-
* ```handlebars
|
|
139
|
-
* {{isObject "foo"}}
|
|
140
|
-
* //=> false
|
|
141
|
-
* ```
|
|
142
|
-
* @param {String} `value`
|
|
143
|
-
* @return {Boolean}
|
|
144
|
-
* @api public
|
|
145
|
-
*/
|
|
146
|
-
helpers.isObject = isObject;
|
|
147
|
-
/**
|
|
148
|
-
* Parses the given string using `JSON.parse`.
|
|
149
|
-
*
|
|
150
|
-
* ```handlebars
|
|
151
|
-
* <!-- string: '{"foo": "bar"}' -->
|
|
152
|
-
* {{JSONparse string}}
|
|
153
|
-
* <!-- results in: { foo: 'bar' } -->
|
|
154
|
-
* ```
|
|
155
|
-
* @param {String} `string` The string to parse
|
|
156
|
-
* @contributor github.com/keeganstreet
|
|
157
|
-
* @block
|
|
158
|
-
* @api public
|
|
159
|
-
*/
|
|
160
|
-
helpers.JSONparse = function (str) {
|
|
161
|
-
return JSON.parse(str);
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Stringify an object using `JSON.stringify`.
|
|
165
|
-
*
|
|
166
|
-
* ```handlebars
|
|
167
|
-
* <!-- object: { foo: 'bar' } -->
|
|
168
|
-
* {{JSONstringify object}}
|
|
169
|
-
* <!-- results in: '{"foo": "bar"}' -->
|
|
170
|
-
* ```
|
|
171
|
-
* @param {Object} `obj` Object to stringify
|
|
172
|
-
* @return {String}
|
|
173
|
-
* @api public
|
|
174
|
-
*/
|
|
175
|
-
helpers.JSONstringify = function (obj, indent) {
|
|
176
|
-
if (!isNumber(indent)) {
|
|
177
|
-
indent = 0;
|
|
178
|
-
}
|
|
179
|
-
return JSON.stringify(obj, null, indent);
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Deeply merge the properties of the given `objects` with the
|
|
183
|
-
* context object.
|
|
184
|
-
*
|
|
185
|
-
* @param {Object} `object` The target object. Pass an empty object to shallow clone.
|
|
186
|
-
* @param {Object} `objects`
|
|
187
|
-
* @return {Object}
|
|
188
|
-
* @api public
|
|
189
|
-
*/
|
|
190
|
-
helpers.merge = function (...args1) {
|
|
191
|
-
const args = [].slice.call(args1);
|
|
192
|
-
let opts = {};
|
|
193
|
-
if (util.isOptions(args[args.length - 1])) {
|
|
194
|
-
// remove handlebars options object
|
|
195
|
-
opts = args.pop().hash;
|
|
196
|
-
// re-add options.hash
|
|
197
|
-
args.push(opts);
|
|
198
|
-
}
|
|
199
|
-
return Object.assign.apply(null, args);
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* Alias for parseJSON. this will be
|
|
203
|
-
* deprecated in a future release
|
|
204
|
-
*/
|
|
205
|
-
helpers.parseJSON = helpers.JSONparse;
|
|
206
|
-
/**
|
|
207
|
-
* Pick properties from the context object.
|
|
208
|
-
*
|
|
209
|
-
* @param {Array|String} `properties` One or more properties to pick.
|
|
210
|
-
* @param {Object} `context`
|
|
211
|
-
* @param {Object} `options` Handlebars options object.
|
|
212
|
-
* @return {Object} Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
|
|
213
|
-
* @block
|
|
214
|
-
* @api public
|
|
215
|
-
*/
|
|
216
|
-
helpers.pick = function (props, context, options) {
|
|
217
|
-
const keys = array.arrayify(props);
|
|
218
|
-
const len = keys.length;
|
|
219
|
-
let i = -1;
|
|
220
|
-
let result = {};
|
|
221
|
-
while (++i < len) {
|
|
222
|
-
result = helpers.extend({}, result, getValue(context, keys[i]));
|
|
223
|
-
}
|
|
224
|
-
if (options.fn) {
|
|
225
|
-
if (Object.keys(result).length) {
|
|
226
|
-
return options.fn(result);
|
|
227
|
-
}
|
|
228
|
-
return options.inverse(context);
|
|
229
|
-
}
|
|
230
|
-
return result;
|
|
231
|
-
};
|
|
232
|
-
/**
|
|
233
|
-
* Alias for JSONstringify. this will be
|
|
234
|
-
* deprecated in a future release
|
|
235
|
-
*/
|
|
236
|
-
helpers.stringify = helpers.JSONstringify;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function insertAfter(fileContent, content, pattern) {
|
|
2
|
-
const lines = fileContent.split("\n");
|
|
3
|
-
const index = lines.findIndex((line) => {
|
|
4
|
-
return line.match(pattern);
|
|
5
|
-
});
|
|
6
|
-
const indent = lines[index].replace(lines[index].trim(), "");
|
|
7
|
-
lines[index] = lines[index] + "\n" + indent + content;
|
|
8
|
-
if (!["]", "}"].includes(lines[index + 1].trim()) && lines[index - 1].slice(-1) === ",") {
|
|
9
|
-
lines[index] += ",";
|
|
10
|
-
}
|
|
11
|
-
return lines.join("\n");
|
|
12
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function insertImport(fileContent, content) {
|
|
2
|
-
const lines = fileContent.split("\n");
|
|
3
|
-
const index = lines.findIndex((line) => {
|
|
4
|
-
if (line.startsWith("#!")) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
return !line.startsWith("import ");
|
|
8
|
-
});
|
|
9
|
-
lines[index] = content + "\n" + lines[index];
|
|
10
|
-
return lines.join("\n");
|
|
11
|
-
}
|