@tsed/cli 6.6.3 → 7.0.0-alpha.2
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/commands/add/AddCmd.js +16 -16
- package/lib/esm/commands/generate/GenerateCmd.js +69 -222
- package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
- package/lib/esm/commands/init/InitCmd.js +190 -171
- package/lib/esm/commands/init/config/FeaturesPrompt.js +101 -3
- package/lib/esm/commands/init/mappers/mapToContext.js +4 -3
- package/lib/esm/commands/run/RunCmd.js +22 -26
- package/lib/esm/commands/update/UpdateCmd.js +9 -13
- package/lib/esm/fn/exec.js +5 -0
- package/lib/esm/fn/render.js +5 -0
- package/lib/esm/fn/taskOutput.js +7 -0
- package/lib/esm/index.js +7 -4
- package/lib/esm/interfaces/AlterPackageJson.js +1 -0
- package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
- package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
- package/lib/esm/interfaces/CliCommandHooks.js +1 -0
- package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
- package/lib/esm/interfaces/InitCmdOptions.js +1 -0
- package/lib/esm/interfaces/RenderDataContext.js +1 -0
- package/lib/esm/interfaces/RuntimeTypes.js +1 -0
- package/lib/esm/interfaces/index.js +9 -0
- package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
- package/lib/esm/pipes/RoutePipe.js +4 -8
- package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
- package/lib/esm/pipes/index.js +1 -1
- package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
- package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
- package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
- package/lib/esm/processors/transformBinFile.js +47 -0
- package/lib/esm/processors/transformConfigFile.js +105 -0
- package/lib/esm/processors/transformIndexFile.js +23 -0
- package/lib/esm/processors/transformServerFile.js +60 -0
- package/lib/esm/runtimes/RuntimesModule.js +7 -17
- package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
- package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
- package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
- package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
- package/lib/esm/services/CliProjectService.js +96 -0
- package/lib/esm/services/CliRunScript.js +4 -8
- package/lib/esm/services/CliTemplatesService.js +68 -0
- package/lib/esm/services/ProjectClient.js +161 -0
- package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
- package/lib/esm/templates/asyncFactory.template.js +38 -0
- package/lib/esm/templates/barrels.template.js +22 -0
- package/lib/esm/templates/command.template.js +56 -0
- package/lib/esm/templates/config.template.js +27 -0
- package/lib/esm/templates/controller.template.js +45 -0
- package/lib/esm/templates/decorator.template.js +182 -0
- package/lib/esm/templates/docker-compose.template.js +25 -0
- package/lib/esm/templates/dockerfile.template.js +236 -0
- package/lib/esm/templates/exception-filter.template.js +19 -0
- package/lib/esm/templates/factory.template.js +37 -0
- package/lib/esm/templates/index.command.template.js +18 -0
- package/lib/esm/templates/index.config.utils.template.js +17 -0
- package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
- package/lib/esm/templates/index.js +32 -0
- package/lib/esm/templates/index.logger.template.js +38 -0
- package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
- package/lib/esm/templates/interceptor.template.js +31 -0
- package/lib/esm/templates/interface.template.js +13 -0
- package/lib/esm/templates/middleware.template.js +34 -0
- package/lib/esm/templates/model.template.js +16 -0
- package/lib/esm/templates/module.template.js +16 -0
- package/lib/esm/templates/pipe.template.js +19 -0
- package/lib/esm/templates/pm2.template.js +111 -0
- package/lib/esm/templates/prisma.service.template.js +23 -0
- package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
- package/lib/esm/templates/repository.template.js +16 -0
- package/lib/esm/templates/response-filter.template.js +19 -0
- package/lib/esm/templates/server.template.js +37 -0
- package/lib/esm/templates/service.template.js +16 -0
- package/lib/esm/templates/tsconfig.spec.template.js +34 -0
- package/lib/esm/templates/tsconfig.template.js +31 -0
- package/lib/esm/templates/value.template.js +13 -0
- package/lib/esm/utils/defineTemplate.js +13 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/add/AddCmd.d.ts +2 -2
- package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
- package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
- package/lib/types/commands/init/InitCmd.d.ts +18 -20
- package/lib/types/commands/init/config/FeaturesPrompt.d.ts +11 -2
- package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
- package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
- package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
- package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
- package/lib/types/fn/exec.d.ts +1 -0
- package/lib/types/fn/render.d.ts +2 -0
- package/lib/types/fn/taskOutput.d.ts +1 -0
- package/lib/types/index.d.ts +7 -4
- package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
- package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
- package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
- package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
- package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
- package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
- package/lib/types/interfaces/PlatformType.d.ts +7 -0
- package/lib/types/interfaces/RenderDataContext.d.ts +61 -0
- package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +9 -0
- package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
- package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
- package/lib/types/pipes/index.d.ts +1 -1
- package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
- package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
- package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
- package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
- package/lib/types/processors/transformBinFile.d.ts +3 -0
- package/lib/types/processors/transformConfigFile.d.ts +3 -0
- package/lib/types/processors/transformIndexFile.d.ts +3 -0
- package/lib/types/processors/transformServerFile.d.ts +3 -0
- package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
- package/lib/types/services/CliProjectService.d.ts +16 -0
- package/lib/types/services/CliTemplatesService.d.ts +29 -0
- package/lib/types/services/ProjectClient.d.ts +40 -0
- package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
- package/lib/types/templates/asyncFactory.template.d.ts +2 -0
- package/lib/types/templates/barrels.template.d.ts +2 -0
- package/lib/types/templates/command.template.d.ts +2 -0
- package/lib/types/templates/config.template.d.ts +2 -0
- package/lib/types/templates/controller.template.d.ts +2 -0
- package/lib/types/templates/decorator.template.d.ts +2 -0
- package/lib/types/templates/docker-compose.template.d.ts +2 -0
- package/lib/types/templates/dockerfile.template.d.ts +1 -0
- package/lib/types/templates/exception-filter.template.d.ts +2 -0
- package/lib/types/templates/factory.template.d.ts +2 -0
- package/lib/types/templates/index.command.template.d.ts +2 -0
- package/lib/types/templates/index.config.utils.template.d.ts +2 -0
- package/lib/types/templates/index.controller.template.d.ts +2 -0
- package/lib/types/templates/index.d.ts +31 -0
- package/lib/types/templates/index.logger.template.d.ts +2 -0
- package/lib/types/templates/index.template.d.ts +2 -0
- package/lib/types/templates/interceptor.template.d.ts +2 -0
- package/lib/types/templates/interface.template.d.ts +2 -0
- package/lib/types/templates/middleware.template.d.ts +2 -0
- package/lib/types/templates/model.template.d.ts +2 -0
- package/lib/types/templates/module.template.d.ts +2 -0
- package/lib/types/templates/pipe.template.d.ts +2 -0
- package/lib/types/templates/pm2.template.d.ts +1 -0
- package/lib/types/templates/prisma.service.template.d.ts +2 -0
- package/lib/types/templates/readme.template.d.ts +2 -0
- package/lib/types/templates/repository.template.d.ts +2 -0
- package/lib/types/templates/response-filter.template.d.ts +2 -0
- package/lib/types/templates/server.template.d.ts +2 -0
- package/lib/types/templates/service.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.template.d.ts +2 -0
- package/lib/types/templates/value.template.d.ts +2 -0
- package/lib/types/utils/defineTemplate.d.ts +39 -0
- package/package.json +14 -12
- package/templates/tsconfig.node.json +14 -0
- package/templates/webpack.config.js +55 -0
- package/lib/esm/commands/generate/ProviderTypes.js +0 -103
- package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
- package/lib/esm/services/ProvidersInfoService.js +0 -46
- package/lib/esm/services/Renderer.js +0 -162
- package/lib/esm/utils/fillImports.js +0 -38
- 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/commands/generate/ProviderTypes.d.ts +0 -11
- package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
- package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
- package/lib/types/services/ProvidersInfoService.d.ts +0 -21
- package/lib/types/services/Renderer.d.ts +0 -44
- package/lib/types/utils/fillImports.d.ts +0 -1
- 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/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
- package/templates/generate/async.factory.hbs +0 -35
- package/templates/generate/command.hbs +0 -45
- package/templates/generate/controller.hbs +0 -10
- package/templates/generate/decorator.class.hbs +0 -14
- package/templates/generate/decorator.endpoint.hbs +0 -15
- package/templates/generate/decorator.generic.hbs +0 -19
- package/templates/generate/decorator.method.hbs +0 -16
- package/templates/generate/decorator.middleware.hbs +0 -26
- package/templates/generate/decorator.param.hbs +0 -15
- package/templates/generate/decorator.parameters.hbs +0 -9
- package/templates/generate/decorator.prop.hbs +0 -14
- package/templates/generate/decorator.property.hbs +0 -5
- package/templates/generate/exception-filter.hbs +0 -9
- package/templates/generate/factory.hbs +0 -11
- package/templates/generate/injectable.hbs +0 -6
- package/templates/generate/interceptor.hbs +0 -21
- package/templates/generate/interface.hbs +0 -3
- package/templates/generate/middleware.hbs +0 -9
- package/templates/generate/model.hbs +0 -6
- package/templates/generate/module.hbs +0 -6
- package/templates/generate/pipe.hbs +0 -9
- package/templates/generate/prisma.service.hbs +0 -13
- package/templates/generate/repository.hbs +0 -6
- package/templates/generate/response-filter.hbs +0 -9
- package/templates/generate/server/_partials/server-footer.hbs +0 -10
- package/templates/generate/server/_partials/server-header.hbs +0 -34
- package/templates/generate/server/express/server.hbs +0 -10
- package/templates/generate/server/fastify/server.hbs +0 -14
- package/templates/generate/server/koa/server.hbs +0 -8
- package/templates/generate/service.hbs +0 -6
- package/templates/generate/value.hbs +0 -3
- package/templates/init/.barrels.json.hbs +0 -9
- package/templates/init/.gitignore.hbs +0 -57
- package/templates/init/.npmrc.hbs +0 -2
- package/templates/init/docker/_partials/docker-body.hbs +0 -5
- package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
- package/templates/init/docker/_partials/docker-header.hbs +0 -16
- package/templates/init/docker/bun/Dockerfile.hbs +0 -36
- package/templates/init/docker/npm/Dockerfile.hbs +0 -28
- package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
- package/templates/init/docker-compose.yml.hbs +0 -14
- package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
- package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
- package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
- package/templates/init/src/bin/index.ts.hbs +0 -9
- package/templates/init/src/config/envs/index.ts.hbs +0 -7
- package/templates/init/src/config/index.ts.hbs +0 -38
- package/templates/init/src/config/logger/index.ts.hbs +0 -25
- package/templates/init/tsconfig.json.hbs +0 -16
- package/templates/init/tsconfig.node.json.hbs +0 -20
- package/templates/init/tsconfig.spec.json.hbs +0 -25
- package/templates/init/webpack.config.js.hbs +0 -65
- /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
- /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
- /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
- /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
- /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
- /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
- /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
- /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
- /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import util from "handlebars-utils";
|
|
3
|
-
import { helpers as array } from "./array.js";
|
|
4
|
-
import { helpers as object } from "./object.js";
|
|
5
|
-
const forEach = array.forEach;
|
|
6
|
-
const forOwn = object.forOwn;
|
|
7
|
-
export const helpers = {};
|
|
8
|
-
/**
|
|
9
|
-
* Inline, subexpression, or block helper that returns true (or the block)
|
|
10
|
-
* if the given collection is empty, or false (or the inverse block, if
|
|
11
|
-
* supplied) if the colleciton is not empty.
|
|
12
|
-
*
|
|
13
|
-
* ```handlebars
|
|
14
|
-
* <!-- array: [] -->
|
|
15
|
-
* {{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
|
|
16
|
-
* <!-- results in: 'AAA' -->
|
|
17
|
-
*
|
|
18
|
-
* <!-- array: [] -->
|
|
19
|
-
* {{isEmpty array}}
|
|
20
|
-
* <!-- results in: true -->
|
|
21
|
-
* ```
|
|
22
|
-
* @param {Object} `collection`
|
|
23
|
-
* @param {Object} `options`
|
|
24
|
-
* @return {String}
|
|
25
|
-
* @block
|
|
26
|
-
* @api public
|
|
27
|
-
*/
|
|
28
|
-
helpers.isEmpty = function (collection, options) {
|
|
29
|
-
if (!util.isOptions(options)) {
|
|
30
|
-
options = collection;
|
|
31
|
-
return util.fn(true, this, options);
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(collection) && !collection.length) {
|
|
34
|
-
return util.fn(true, this, options);
|
|
35
|
-
}
|
|
36
|
-
const keys = Object.keys(collection);
|
|
37
|
-
const isEmpty = typeof collection === "object" && !keys.length;
|
|
38
|
-
return util.value(isEmpty, this, options);
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Block helper that iterates over an array or object. If
|
|
42
|
-
* an array is given, `.forEach` is called, or if an object
|
|
43
|
-
* is given, `.forOwn` is called, otherwise the inverse block
|
|
44
|
-
* is returned.
|
|
45
|
-
*
|
|
46
|
-
* @param {Object|Array} `collection` The collection to iterate over
|
|
47
|
-
* @param {Object} `options`
|
|
48
|
-
* @return {String}
|
|
49
|
-
* @block
|
|
50
|
-
* @api public
|
|
51
|
-
*/
|
|
52
|
-
helpers.iterate = function (collection, options) {
|
|
53
|
-
if (Array.isArray(collection)) {
|
|
54
|
-
return forEach.apply(null, [collection, options]);
|
|
55
|
-
}
|
|
56
|
-
if (util.isObject(collection)) {
|
|
57
|
-
return forOwn.apply(null, [collection, options]);
|
|
58
|
-
}
|
|
59
|
-
return options.inverse(this);
|
|
60
|
-
};
|
|
@@ -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);
|