@tsed/cli-core 3.20.16 → 3.21.0-rc.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.
Files changed (298) hide show
  1. package/lib/cjs/CliCore.js +97 -0
  2. package/lib/cjs/CliCore.js.map +1 -0
  3. package/lib/cjs/decorators/command.js +11 -0
  4. package/lib/cjs/decorators/command.js.map +1 -0
  5. package/lib/cjs/decorators/index.js +9 -0
  6. package/lib/cjs/decorators/index.js.map +1 -0
  7. package/lib/cjs/decorators/on.js +13 -0
  8. package/lib/cjs/decorators/on.js.map +1 -0
  9. package/lib/cjs/decorators/onAdd.js +10 -0
  10. package/lib/cjs/decorators/onAdd.js.map +1 -0
  11. package/lib/cjs/decorators/onExec.js +10 -0
  12. package/lib/cjs/decorators/onExec.js.map +1 -0
  13. package/lib/cjs/decorators/onPostInstall.js +10 -0
  14. package/lib/cjs/decorators/onPostInstall.js.map +1 -0
  15. package/lib/cjs/decorators/onPrompt.js +10 -0
  16. package/lib/cjs/decorators/onPrompt.js.map +1 -0
  17. package/lib/cjs/domains/CliError.js +14 -0
  18. package/lib/cjs/domains/CliError.js.map +1 -0
  19. package/lib/cjs/domains/CommandStoreKeys.js +12 -0
  20. package/lib/cjs/domains/CommandStoreKeys.js.map +1 -0
  21. package/lib/cjs/index.js +30 -0
  22. package/lib/cjs/index.js.map +1 -0
  23. package/lib/cjs/interfaces/CliDefaultOptions.js +3 -0
  24. package/lib/cjs/interfaces/CliDefaultOptions.js.map +1 -0
  25. package/lib/cjs/interfaces/CommandMetadata.js +3 -0
  26. package/lib/cjs/interfaces/CommandMetadata.js.map +1 -0
  27. package/lib/cjs/interfaces/CommandParameters.js +3 -0
  28. package/lib/cjs/interfaces/CommandParameters.js.map +1 -0
  29. package/lib/cjs/interfaces/CommandProvider.js +3 -0
  30. package/lib/cjs/interfaces/CommandProvider.js.map +1 -0
  31. package/lib/cjs/interfaces/PackageJson.js +3 -0
  32. package/lib/cjs/interfaces/PackageJson.js.map +1 -0
  33. package/lib/cjs/interfaces/ProjectPreferences.js +10 -0
  34. package/lib/cjs/interfaces/ProjectPreferences.js.map +1 -0
  35. package/lib/cjs/interfaces/Tasks.js +3 -0
  36. package/lib/cjs/interfaces/Tasks.js.map +1 -0
  37. package/lib/cjs/interfaces/index.js +11 -0
  38. package/lib/cjs/interfaces/index.js.map +1 -0
  39. package/lib/cjs/package.json +3 -0
  40. package/lib/cjs/registries/CommandRegistry.js +13 -0
  41. package/lib/cjs/registries/CommandRegistry.js.map +1 -0
  42. package/lib/cjs/services/CliConfiguration.js +21 -0
  43. package/lib/cjs/services/CliConfiguration.js.map +1 -0
  44. package/lib/cjs/services/CliDockerComposeYaml.js +83 -0
  45. package/lib/cjs/services/CliDockerComposeYaml.js.map +1 -0
  46. package/lib/cjs/services/CliExeca.js +45 -0
  47. package/lib/cjs/services/CliExeca.js.map +1 -0
  48. package/lib/cjs/services/CliFs.js +55 -0
  49. package/lib/cjs/services/CliFs.js.map +1 -0
  50. package/lib/cjs/services/CliHooks.js +34 -0
  51. package/lib/cjs/services/CliHooks.js.map +1 -0
  52. package/lib/cjs/services/CliHttpClient.js +107 -0
  53. package/lib/cjs/services/CliHttpClient.js.map +1 -0
  54. package/lib/cjs/services/CliHttpLogClient.js +83 -0
  55. package/lib/cjs/services/CliHttpLogClient.js.map +1 -0
  56. package/lib/cjs/services/CliPackageJson.js +16 -0
  57. package/lib/cjs/services/CliPackageJson.js.map +1 -0
  58. package/lib/cjs/services/CliPlugins.js +78 -0
  59. package/lib/cjs/services/CliPlugins.js.map +1 -0
  60. package/lib/cjs/services/CliProxyAgent.js +87 -0
  61. package/lib/cjs/services/CliProxyAgent.js.map +1 -0
  62. package/lib/cjs/services/CliRunScript.js +31 -0
  63. package/lib/cjs/services/CliRunScript.js.map +1 -0
  64. package/lib/cjs/services/CliService.js +271 -0
  65. package/lib/cjs/services/CliService.js.map +1 -0
  66. package/lib/cjs/services/CliYaml.js +37 -0
  67. package/lib/cjs/services/CliYaml.js.map +1 -0
  68. package/lib/cjs/services/NpmRegistryClient.js +121 -0
  69. package/lib/cjs/services/NpmRegistryClient.js.map +1 -0
  70. package/lib/cjs/services/ProjectPackageJson.js +420 -0
  71. package/lib/cjs/services/ProjectPackageJson.js.map +1 -0
  72. package/lib/cjs/services/Renderer.js +154 -0
  73. package/lib/cjs/services/Renderer.js.map +1 -0
  74. package/lib/cjs/services/index.js +17 -0
  75. package/lib/cjs/services/index.js.map +1 -0
  76. package/lib/cjs/utils/createInjector.js +35 -0
  77. package/lib/cjs/utils/createInjector.js.map +1 -0
  78. package/lib/cjs/utils/createTasksRunner.js +75 -0
  79. package/lib/cjs/utils/createTasksRunner.js.map +1 -0
  80. package/lib/cjs/utils/getCommandMetadata.js +19 -0
  81. package/lib/cjs/utils/getCommandMetadata.js.map +1 -0
  82. package/lib/cjs/utils/getPackageJson.js +38 -0
  83. package/lib/cjs/utils/getPackageJson.js.map +1 -0
  84. package/lib/cjs/utils/hbs/array.js +522 -0
  85. package/lib/cjs/utils/hbs/array.js.map +1 -0
  86. package/lib/cjs/utils/hbs/collection.js +66 -0
  87. package/lib/cjs/utils/hbs/collection.js.map +1 -0
  88. package/lib/cjs/utils/hbs/comparison.js +437 -0
  89. package/lib/cjs/utils/hbs/comparison.js.map +1 -0
  90. package/lib/cjs/utils/hbs/index.js +15 -0
  91. package/lib/cjs/utils/hbs/index.js.map +1 -0
  92. package/lib/cjs/utils/hbs/object.js +245 -0
  93. package/lib/cjs/utils/hbs/object.js.map +1 -0
  94. package/lib/cjs/utils/hbs/switch.js +14 -0
  95. package/lib/cjs/utils/hbs/switch.js.map +1 -0
  96. package/lib/cjs/utils/index.js +14 -0
  97. package/lib/cjs/utils/index.js.map +1 -0
  98. package/lib/cjs/utils/isValidVersion.js +11 -0
  99. package/lib/cjs/utils/isValidVersion.js.map +1 -0
  100. package/lib/cjs/utils/loadPlugins.js +47 -0
  101. package/lib/cjs/utils/loadPlugins.js.map +1 -0
  102. package/lib/cjs/utils/logToCurl.js +19 -0
  103. package/lib/cjs/utils/logToCurl.js.map +1 -0
  104. package/lib/cjs/utils/mapCommanderArgs.js +40 -0
  105. package/lib/cjs/utils/mapCommanderArgs.js.map +1 -0
  106. package/lib/cjs/utils/mapCommanderOptions.js +16 -0
  107. package/lib/cjs/utils/mapCommanderOptions.js.map +1 -0
  108. package/lib/cjs/utils/normalizePath.js +19 -0
  109. package/lib/cjs/utils/normalizePath.js.map +1 -0
  110. package/lib/cjs/utils/parseOption.js +27 -0
  111. package/lib/cjs/utils/parseOption.js.map +1 -0
  112. package/lib/cjs/utils/patchCommander.js +58 -0
  113. package/lib/cjs/utils/patchCommander.js.map +1 -0
  114. package/lib/cjs/utils/renderer/insertAfter.js +17 -0
  115. package/lib/cjs/utils/renderer/insertAfter.js.map +1 -0
  116. package/lib/cjs/utils/renderer/insertImport.js +16 -0
  117. package/lib/cjs/utils/renderer/insertImport.js.map +1 -0
  118. package/lib/esm/CliCore.js +94 -0
  119. package/lib/esm/CliCore.js.map +1 -0
  120. package/lib/esm/decorators/command.js +7 -0
  121. package/lib/esm/decorators/command.js.map +1 -0
  122. package/lib/esm/decorators/index.js +6 -0
  123. package/lib/esm/decorators/index.js.map +1 -0
  124. package/lib/esm/decorators/on.js +9 -0
  125. package/lib/esm/decorators/on.js.map +1 -0
  126. package/lib/esm/decorators/onAdd.js +6 -0
  127. package/lib/esm/decorators/onAdd.js.map +1 -0
  128. package/lib/esm/decorators/onExec.js +6 -0
  129. package/lib/esm/decorators/onExec.js.map +1 -0
  130. package/lib/esm/decorators/onPostInstall.js +6 -0
  131. package/lib/esm/decorators/onPostInstall.js.map +1 -0
  132. package/lib/esm/decorators/onPrompt.js +6 -0
  133. package/lib/esm/decorators/onPrompt.js.map +1 -0
  134. package/lib/esm/domains/CliError.js +10 -0
  135. package/lib/esm/domains/CliError.js.map +1 -0
  136. package/lib/esm/domains/CommandStoreKeys.js +9 -0
  137. package/lib/esm/domains/CommandStoreKeys.js.map +1 -0
  138. package/lib/esm/index.js +12 -0
  139. package/lib/esm/index.js.map +1 -0
  140. package/lib/esm/interfaces/CliDefaultOptions.js +2 -0
  141. package/lib/esm/interfaces/CliDefaultOptions.js.map +1 -0
  142. package/lib/esm/interfaces/CommandMetadata.js +2 -0
  143. package/lib/esm/interfaces/CommandMetadata.js.map +1 -0
  144. package/lib/esm/interfaces/CommandParameters.js +2 -0
  145. package/lib/esm/interfaces/CommandParameters.js.map +1 -0
  146. package/lib/esm/interfaces/CommandProvider.js +2 -0
  147. package/lib/esm/interfaces/CommandProvider.js.map +1 -0
  148. package/lib/esm/interfaces/PackageJson.js +2 -0
  149. package/lib/esm/interfaces/PackageJson.js.map +1 -0
  150. package/lib/esm/interfaces/ProjectPreferences.js +7 -0
  151. package/lib/esm/interfaces/ProjectPreferences.js.map +1 -0
  152. package/lib/esm/interfaces/Tasks.js +2 -0
  153. package/lib/esm/interfaces/Tasks.js.map +1 -0
  154. package/lib/esm/interfaces/index.js +8 -0
  155. package/lib/esm/interfaces/index.js.map +1 -0
  156. package/lib/esm/package.json +3 -0
  157. package/lib/esm/registries/CommandRegistry.js +10 -0
  158. package/lib/esm/registries/CommandRegistry.js.map +1 -0
  159. package/lib/esm/services/CliConfiguration.js +18 -0
  160. package/lib/esm/services/CliConfiguration.js.map +1 -0
  161. package/lib/esm/services/CliDockerComposeYaml.js +80 -0
  162. package/lib/esm/services/CliDockerComposeYaml.js.map +1 -0
  163. package/lib/esm/services/CliExeca.js +42 -0
  164. package/lib/esm/services/CliExeca.js.map +1 -0
  165. package/lib/esm/services/CliFs.js +52 -0
  166. package/lib/esm/services/CliFs.js.map +1 -0
  167. package/lib/esm/services/CliHooks.js +31 -0
  168. package/lib/esm/services/CliHooks.js.map +1 -0
  169. package/lib/esm/services/CliHttpClient.js +104 -0
  170. package/lib/esm/services/CliHttpClient.js.map +1 -0
  171. package/lib/esm/services/CliHttpLogClient.js +80 -0
  172. package/lib/esm/services/CliHttpLogClient.js.map +1 -0
  173. package/lib/esm/services/CliPackageJson.js +12 -0
  174. package/lib/esm/services/CliPackageJson.js.map +1 -0
  175. package/lib/esm/services/CliPlugins.js +75 -0
  176. package/lib/esm/services/CliPlugins.js.map +1 -0
  177. package/lib/esm/services/CliProxyAgent.js +84 -0
  178. package/lib/esm/services/CliProxyAgent.js.map +1 -0
  179. package/lib/esm/services/CliRunScript.js +28 -0
  180. package/lib/esm/services/CliRunScript.js.map +1 -0
  181. package/lib/esm/services/CliService.js +268 -0
  182. package/lib/esm/services/CliService.js.map +1 -0
  183. package/lib/esm/services/CliYaml.js +34 -0
  184. package/lib/esm/services/CliYaml.js.map +1 -0
  185. package/lib/esm/services/NpmRegistryClient.js +117 -0
  186. package/lib/esm/services/NpmRegistryClient.js.map +1 -0
  187. package/lib/esm/services/ProjectPackageJson.js +417 -0
  188. package/lib/esm/services/ProjectPackageJson.js.map +1 -0
  189. package/lib/esm/services/Renderer.js +150 -0
  190. package/lib/esm/services/Renderer.js.map +1 -0
  191. package/lib/esm/services/index.js +14 -0
  192. package/lib/esm/services/index.js.map +1 -0
  193. package/lib/esm/utils/createInjector.js +30 -0
  194. package/lib/esm/utils/createInjector.js.map +1 -0
  195. package/lib/esm/utils/createTasksRunner.js +69 -0
  196. package/lib/esm/utils/createTasksRunner.js.map +1 -0
  197. package/lib/esm/utils/getCommandMetadata.js +15 -0
  198. package/lib/esm/utils/getCommandMetadata.js.map +1 -0
  199. package/lib/esm/utils/getPackageJson.js +33 -0
  200. package/lib/esm/utils/getPackageJson.js.map +1 -0
  201. package/lib/esm/utils/hbs/array.js +518 -0
  202. package/lib/esm/utils/hbs/array.js.map +1 -0
  203. package/lib/esm/utils/hbs/collection.js +62 -0
  204. package/lib/esm/utils/hbs/collection.js.map +1 -0
  205. package/lib/esm/utils/hbs/comparison.js +433 -0
  206. package/lib/esm/utils/hbs/comparison.js.map +1 -0
  207. package/lib/esm/utils/hbs/index.js +12 -0
  208. package/lib/esm/utils/hbs/index.js.map +1 -0
  209. package/lib/esm/utils/hbs/object.js +241 -0
  210. package/lib/esm/utils/hbs/object.js.map +1 -0
  211. package/lib/esm/utils/hbs/switch.js +11 -0
  212. package/lib/esm/utils/hbs/switch.js.map +1 -0
  213. package/lib/esm/utils/index.js +11 -0
  214. package/lib/esm/utils/index.js.map +1 -0
  215. package/lib/esm/utils/isValidVersion.js +6 -0
  216. package/lib/esm/utils/isValidVersion.js.map +1 -0
  217. package/lib/esm/utils/loadPlugins.js +42 -0
  218. package/lib/esm/utils/loadPlugins.js.map +1 -0
  219. package/lib/esm/utils/logToCurl.js +14 -0
  220. package/lib/esm/utils/logToCurl.js.map +1 -0
  221. package/lib/esm/utils/mapCommanderArgs.js +36 -0
  222. package/lib/esm/utils/mapCommanderArgs.js.map +1 -0
  223. package/lib/esm/utils/mapCommanderOptions.js +12 -0
  224. package/lib/esm/utils/mapCommanderOptions.js.map +1 -0
  225. package/lib/esm/utils/normalizePath.js +14 -0
  226. package/lib/esm/utils/normalizePath.js.map +1 -0
  227. package/lib/esm/utils/parseOption.js +23 -0
  228. package/lib/esm/utils/parseOption.js.map +1 -0
  229. package/lib/esm/utils/patchCommander.js +55 -0
  230. package/lib/esm/utils/patchCommander.js.map +1 -0
  231. package/lib/esm/utils/renderer/insertAfter.js +13 -0
  232. package/lib/esm/utils/renderer/insertAfter.js.map +1 -0
  233. package/lib/esm/utils/renderer/insertImport.js +12 -0
  234. package/lib/esm/utils/renderer/insertImport.js.map +1 -0
  235. package/lib/{CliCore.d.ts → types/CliCore.d.ts} +0 -0
  236. package/lib/{decorators → types/decorators}/command.d.ts +0 -0
  237. package/lib/{decorators → types/decorators}/index.d.ts +0 -0
  238. package/lib/{decorators → types/decorators}/on.d.ts +0 -0
  239. package/lib/{decorators → types/decorators}/onAdd.d.ts +0 -0
  240. package/lib/{decorators → types/decorators}/onExec.d.ts +0 -0
  241. package/lib/{decorators → types/decorators}/onPostInstall.d.ts +0 -0
  242. package/lib/{decorators → types/decorators}/onPrompt.d.ts +0 -0
  243. package/lib/{domains → types/domains}/CliError.d.ts +0 -0
  244. package/lib/{domains → types/domains}/CommandStoreKeys.d.ts +0 -0
  245. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  246. package/lib/{interfaces → types/interfaces}/CliDefaultOptions.d.ts +0 -0
  247. package/lib/{interfaces → types/interfaces}/CommandMetadata.d.ts +0 -0
  248. package/lib/{interfaces → types/interfaces}/CommandParameters.d.ts +0 -0
  249. package/lib/{interfaces → types/interfaces}/CommandProvider.d.ts +0 -0
  250. package/lib/{interfaces → types/interfaces}/PackageJson.d.ts +0 -0
  251. package/lib/{interfaces → types/interfaces}/ProjectPreferences.d.ts +0 -0
  252. package/lib/{interfaces → types/interfaces}/Tasks.d.ts +0 -0
  253. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  254. package/lib/{registries → types/registries}/CommandRegistry.d.ts +0 -0
  255. package/lib/{services → types/services}/CliConfiguration.d.ts +0 -0
  256. package/lib/{services → types/services}/CliDockerComposeYaml.d.ts +0 -0
  257. package/lib/{services → types/services}/CliExeca.d.ts +1 -0
  258. package/lib/{services → types/services}/CliFs.d.ts +1 -0
  259. package/lib/{services → types/services}/CliHooks.d.ts +0 -0
  260. package/lib/{services → types/services}/CliHttpClient.d.ts +0 -0
  261. package/lib/{services → types/services}/CliHttpLogClient.d.ts +0 -0
  262. package/lib/{services → types/services}/CliPackageJson.d.ts +0 -0
  263. package/lib/{services → types/services}/CliPlugins.d.ts +0 -0
  264. package/lib/{services → types/services}/CliProxyAgent.d.ts +0 -0
  265. package/lib/{services → types/services}/CliRunScript.d.ts +0 -0
  266. package/lib/{services → types/services}/CliService.d.ts +0 -0
  267. package/lib/{services → types/services}/CliYaml.d.ts +0 -0
  268. package/lib/{services → types/services}/NpmRegistryClient.d.ts +0 -0
  269. package/lib/{services → types/services}/ProjectPackageJson.d.ts +0 -0
  270. package/lib/{services → types/services}/Renderer.d.ts +0 -0
  271. package/lib/{services → types/services}/index.d.ts +0 -0
  272. package/lib/{utils → types/utils}/createInjector.d.ts +0 -0
  273. package/lib/{utils → types/utils}/createTasksRunner.d.ts +0 -0
  274. package/lib/{utils → types/utils}/getCommandMetadata.d.ts +0 -0
  275. package/lib/{utils → types/utils}/getPackageJson.d.ts +0 -0
  276. package/lib/{utils → types/utils}/hbs/array.d.ts +0 -0
  277. package/lib/{utils → types/utils}/hbs/collection.d.ts +0 -0
  278. package/lib/{utils → types/utils}/hbs/comparison.d.ts +0 -0
  279. package/lib/{utils → types/utils}/hbs/index.d.ts +0 -0
  280. package/lib/{utils → types/utils}/hbs/object.d.ts +0 -0
  281. package/lib/{utils → types/utils}/hbs/switch.d.ts +0 -0
  282. package/lib/{utils → types/utils}/index.d.ts +0 -0
  283. package/lib/{utils → types/utils}/isValidVersion.d.ts +0 -0
  284. package/lib/{utils → types/utils}/loadPlugins.d.ts +0 -0
  285. package/lib/{utils → types/utils}/logToCurl.d.ts +0 -0
  286. package/lib/{utils → types/utils}/mapCommanderArgs.d.ts +0 -0
  287. package/lib/{utils → types/utils}/mapCommanderOptions.d.ts +0 -0
  288. package/lib/{utils → types/utils}/normalizePath.d.ts +0 -0
  289. package/lib/{utils → types/utils}/parseOption.d.ts +0 -0
  290. package/lib/{utils → types/utils}/patchCommander.d.ts +0 -0
  291. package/lib/{utils → types/utils}/renderer/insertAfter.d.ts +0 -0
  292. package/lib/{utils → types/utils}/renderer/insertImport.d.ts +0 -0
  293. package/package.json +19 -9
  294. package/tsconfig.compile.esm.json +12 -0
  295. package/lib/index.js +0 -3992
  296. package/lib/index.js.map +0 -1
  297. package/lib/index.modern.js +0 -3832
  298. package/lib/index.modern.js.map +0 -1
@@ -0,0 +1,522 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.helpers = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@tsed/core");
6
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
+ // @ts-ignore
8
+ const create_frame_1 = tslib_1.__importDefault(require("create-frame"));
9
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
10
+ // @ts-ignore
11
+ const handlebars_utils_1 = tslib_1.__importDefault(require("handlebars-utils"));
12
+ exports.helpers = {};
13
+ /**
14
+ * Returns all of the items in an array after the specified index.
15
+ * Opposite of [before](#before).
16
+ *
17
+ * ```handlebars
18
+ * <!-- array: ['a', 'b', 'c'] -->
19
+ * {{after array 1}}
20
+ * <!-- results in: '["c"]' -->
21
+ * ```
22
+ * @param {Array} `array` Collection
23
+ * @param {Number} `n` Starting index (number of items to exclude)
24
+ * @return {Array} Array exluding `n` items.
25
+ * @api public
26
+ */
27
+ exports.helpers.after = function (array, n) {
28
+ if (handlebars_utils_1.default.isUndefined(array))
29
+ return "";
30
+ return array.slice(n);
31
+ };
32
+ /**
33
+ * Cast the given `value` to an array.
34
+ *
35
+ * ```handlebars
36
+ * {{arrayify "foo"}}
37
+ * <!-- results in: [ "foo" ] -->
38
+ * ```
39
+ * @param {any} `value`
40
+ * @return {Array}
41
+ * @api public
42
+ */
43
+ exports.helpers.arrayify = function (value) {
44
+ return value ? ((0, core_1.isArray)(value) ? value : [value]) : [];
45
+ };
46
+ /**
47
+ * Return all of the items in the collection before the specified
48
+ * count. Opposite of [after](#after).
49
+ *
50
+ * ```handlebars
51
+ * <!-- array: ['a', 'b', 'c'] -->
52
+ * {{before array 2}}
53
+ * <!-- results in: '["a", "b"]' -->
54
+ * ```
55
+ * @param {Array} `array`
56
+ * @param {Number} `n`
57
+ * @return {Array} Array excluding items after the given number.
58
+ * @api public
59
+ */
60
+ exports.helpers.before = function (array, n) {
61
+ if (handlebars_utils_1.default.isUndefined(array))
62
+ return "";
63
+ return array.slice(0, -n);
64
+ };
65
+ /**
66
+ * ```handlebars
67
+ * <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
68
+ * {{#eachIndex array}}
69
+ * {{item}} is {{index}}
70
+ * {{/eachIndex}}
71
+ * ```
72
+ * @param {Array} `array`
73
+ * @param {Object} `options`
74
+ * @return {String}
75
+ * @block
76
+ * @api public
77
+ */
78
+ exports.helpers.eachIndex = function (array, options) {
79
+ let result = "";
80
+ for (let i = 0; i < array.length; i++) {
81
+ result += options.fn({ item: array[i], index: i });
82
+ }
83
+ return result;
84
+ };
85
+ /**
86
+ * Block helper that filters the given array and renders the block for values that
87
+ * evaluate to `true`, otherwise the inverse block is returned.
88
+ *
89
+ * ```handlebars
90
+ * <!-- array: ['a', 'b', 'c'] -->
91
+ * {{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
92
+ * <!-- results in: 'BBB' -->
93
+ * ```
94
+ * @param {Array} `array`
95
+ * @param {any} `value`
96
+ * @param {Object} `options`
97
+ * @return {String}
98
+ * @block
99
+ * @api public
100
+ */
101
+ exports.helpers.filter = function (array, value, options) {
102
+ let content = "";
103
+ let results = [];
104
+ // filter on a specific property
105
+ const prop = options.hash && (options.hash.property || options.hash.prop);
106
+ if (prop) {
107
+ results = array.filter(function (val) {
108
+ return value === (0, core_1.getValue)(val, prop);
109
+ });
110
+ }
111
+ else {
112
+ // filter on a string value
113
+ results = array.filter(function (v) {
114
+ return value === v;
115
+ });
116
+ }
117
+ if (results && results.length > 0) {
118
+ for (let i = 0; i < results.length; i++) {
119
+ content += options.fn(results[i]);
120
+ }
121
+ return content;
122
+ }
123
+ return options.inverse(this);
124
+ };
125
+ /**
126
+ * Returns the first item, or first `n` items of an array.
127
+ *
128
+ * ```handlebars
129
+ * {{first "['a', 'b', 'c', 'd', 'e']" 2}}
130
+ * <!-- results in: '["a", "b"]' -->
131
+ * ```
132
+ * @param {Array} `array`
133
+ * @param {Number} `n` Number of items to return, starting at `0`.
134
+ * @return {Array}
135
+ * @api public
136
+ */
137
+ exports.helpers.first = function (array, n) {
138
+ if (array === undefined)
139
+ return "";
140
+ if (!(0, core_1.isNumber)(n)) {
141
+ return array[0];
142
+ }
143
+ return array.slice(0, n);
144
+ };
145
+ /**
146
+ * Iterates over each item in an array and exposes the current item
147
+ * in the array as context to the inner block. In addition to
148
+ * the current array item, the helper exposes the following variables
149
+ * to the inner block:
150
+ *
151
+ * - `index`
152
+ * - `total`
153
+ * - `isFirst`
154
+ * - `isLast`
155
+ *
156
+ * Also, `@index` is exposed as a private variable, and additional
157
+ * private variables may be defined as hash arguments.
158
+ *
159
+ * ```handlebars
160
+ * <!-- accounts = [
161
+ * {'name': 'John', 'email': 'john@example.com'},
162
+ * {'name': 'Malcolm', 'email': 'malcolm@example.com'},
163
+ * {'name': 'David', 'email': 'david@example.com'}
164
+ * ] -->
165
+ *
166
+ * {{#forEach accounts}}
167
+ * <a href="mailto:{{ email }}" title="Send an email to {{ name }}">
168
+ * {{ name }}
169
+ * </a>{{#unless isLast}}, {{/unless}}
170
+ * {{/forEach}}
171
+ * ```
172
+ * @source <http://stackoverflow.com/questions/13861007>
173
+ * @param {Array} `array`
174
+ * @return {String}
175
+ * @block
176
+ * @api public
177
+ */
178
+ exports.helpers.forEach = function (array, options) {
179
+ const data = (0, create_frame_1.default)(options, options.hash);
180
+ const len = array.length;
181
+ let buffer = "";
182
+ let i = -1;
183
+ while (++i < len) {
184
+ const item = array[i];
185
+ data.index = i;
186
+ item.index = i + 1;
187
+ item.total = len;
188
+ item.isFirst = i === 0;
189
+ item.isLast = i === len - 1;
190
+ buffer += options.fn(item, { data: data });
191
+ }
192
+ return buffer;
193
+ };
194
+ /**
195
+ * Block helper that renders the block if an array has the
196
+ * given `value`. Optionally specify an inverse block to render
197
+ * when the array does not have the given value.
198
+ *
199
+ * ```handlebars
200
+ * <!-- array: ['a', 'b', 'c'] -->
201
+ * {{#inArray array "d"}}
202
+ * foo
203
+ * {{else}}
204
+ * bar
205
+ * {{/inArray}}
206
+ * <!-- results in: 'bar' -->
207
+ * ```
208
+ * @param {Array} `array`
209
+ * @param {any} `value`
210
+ * @param {Object} `options`
211
+ * @return {String}
212
+ * @block
213
+ * @api public
214
+ */
215
+ exports.helpers.inArray = function (array, value, options) {
216
+ return handlebars_utils_1.default.value(handlebars_utils_1.default.indexOf(array, value) > -1, this, options);
217
+ };
218
+ /**
219
+ * Returns true if `value` is an es5 array.
220
+ *
221
+ * ```handlebars
222
+ * {{isArray "abc"}}
223
+ * <!-- results in: false -->
224
+ *
225
+ * <!-- array: [1, 2, 3] -->
226
+ * {{isArray array}}
227
+ * <!-- results in: true -->
228
+ * ```
229
+ * @param {any} `value` The value to test.
230
+ * @return {Boolean}
231
+ * @api public
232
+ */
233
+ exports.helpers.isArray = function (value) {
234
+ return Array.isArray(value);
235
+ };
236
+ /**
237
+ * Returns the item from `array` at index `idx`.
238
+ *
239
+ * ```handlebars
240
+ * <!-- array: ['a', 'b', 'c'] -->
241
+ * {{itemAt array 1}}
242
+ * <!-- results in: 'b' -->
243
+ * ```
244
+ * @param {Array} `array`
245
+ * @param {Number} `idx`
246
+ * @return {any} `value`
247
+ * @block
248
+ * @api public
249
+ */
250
+ exports.helpers.itemAt = function (array, idx) {
251
+ array = handlebars_utils_1.default.result(array);
252
+ if ((0, core_1.isArray)(array)) {
253
+ idx = (0, core_1.isNumber)(idx) ? +idx : 0;
254
+ if (idx < 0) {
255
+ return array[array.length + idx];
256
+ }
257
+ if (idx < array.length) {
258
+ return array[idx];
259
+ }
260
+ }
261
+ };
262
+ /**
263
+ * Join all elements of array into a string, optionally using a
264
+ * given separator.
265
+ *
266
+ * ```handlebars
267
+ * <!-- array: ['a', 'b', 'c'] -->
268
+ * {{join array}}
269
+ * <!-- results in: 'a, b, c' -->
270
+ *
271
+ * {{join array '-'}}
272
+ * <!-- results in: 'a-b-c' -->
273
+ * ```
274
+ * @param {Array} `array`
275
+ * @param {String} `separator` The separator to use. Defaults to `, `.
276
+ * @return {String}
277
+ * @api public
278
+ */
279
+ exports.helpers.join = function (array, separator) {
280
+ if ((0, core_1.isString)(array))
281
+ return array;
282
+ if (!(0, core_1.isArray)(array))
283
+ return "";
284
+ separator = handlebars_utils_1.default.isString(separator) ? separator : ", ";
285
+ return array.join(separator);
286
+ };
287
+ /**
288
+ * Returns true if the the length of the given `value` is equal
289
+ * to the given `length`. Can be used as a block or inline helper.
290
+ *
291
+ * @param {Array|String} `value`
292
+ * @param {Number} `length`
293
+ * @param {Object} `options`
294
+ * @return {String}
295
+ * @block
296
+ * @api public
297
+ */
298
+ exports.helpers.equalsLength = function (value, length, options) {
299
+ if (handlebars_utils_1.default.isOptions(length)) {
300
+ options = length;
301
+ length = 0;
302
+ }
303
+ let len = 0;
304
+ if (typeof value === "string" || Array.isArray(value)) {
305
+ len = value.length;
306
+ }
307
+ return handlebars_utils_1.default.value(len === length, this, options);
308
+ };
309
+ /**
310
+ * Returns the last item, or last `n` items of an array or string.
311
+ * Opposite of [first](#first).
312
+ *
313
+ * ```handlebars
314
+ * <!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
315
+ *
316
+ * {{last value}}
317
+ * <!-- results in: ['e'] -->
318
+ *
319
+ * {{last value 2}}
320
+ * <!-- results in: ['d', 'e'] -->
321
+ *
322
+ * {{last value 3}}
323
+ * <!-- results in: ['c', 'd', 'e'] -->
324
+ * ```
325
+ * @param {Array|String} `value` Array or string.
326
+ * @param {Number} `n` Number of items to return from the end of the array.
327
+ * @return {Array}
328
+ * @api public
329
+ */
330
+ exports.helpers.last = function (value, n) {
331
+ if (!(0, core_1.isArray)(value) && typeof value !== "string") {
332
+ return "";
333
+ }
334
+ if (!(0, core_1.isNumber)(n)) {
335
+ return value[value.length - 1];
336
+ }
337
+ return value.slice(-Math.abs(n));
338
+ };
339
+ /**
340
+ * Returns the length of the given string or array.
341
+ *
342
+ * ```handlebars
343
+ * {{length '["a", "b", "c"]'}}
344
+ * <!-- results in: 3 -->
345
+ *
346
+ * <!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
347
+ * {{length myArray}}
348
+ * <!-- results in: 5 -->
349
+ *
350
+ * <!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
351
+ * {{length myObject}}
352
+ * <!-- results in: 2 -->
353
+ * ```
354
+ * @param {Array|Object|String} `value`
355
+ * @return {Number} The length of the value.
356
+ * @api public
357
+ */
358
+ exports.helpers.length = function (value) {
359
+ if ((0, core_1.isObject)(value) && !handlebars_utils_1.default.isOptions(value)) {
360
+ value = Object.keys(value);
361
+ }
362
+ if (typeof value === "string" || Array.isArray(value)) {
363
+ return value.length;
364
+ }
365
+ return 0;
366
+ };
367
+ /**
368
+ * Returns a new array, created by calling `function` on each
369
+ * element of the given `array`. For example,
370
+ *
371
+ * ```handlebars
372
+ * <!-- array: ['a', 'b', 'c'], and "double" is a
373
+ * fictitious function that duplicates letters -->
374
+ * {{map array double}}
375
+ * <!-- results in: '["aa", "bb", "cc"]' -->
376
+ * ```
377
+ *
378
+ * @param {Array} `array`
379
+ * @param {Function} `fn`
380
+ * @return {String}
381
+ * @api public
382
+ */
383
+ exports.helpers.map = function (array, iter) {
384
+ if (!Array.isArray(array))
385
+ return "";
386
+ const len = array.length;
387
+ const res = new Array(len);
388
+ let i = -1;
389
+ if (typeof iter !== "function") {
390
+ return array;
391
+ }
392
+ while (++i < len) {
393
+ res[i] = iter(array[i], i, array);
394
+ }
395
+ return res;
396
+ };
397
+ /**
398
+ * Map over the given object or array or objects and create an array of values
399
+ * from the given `prop`. Dot-notation may be used (as a string) to get
400
+ * nested properties.
401
+ *
402
+ * ```handlebars
403
+ * // {{pluck items "data.title"}}
404
+ * <!-- results in: '["aa", "bb", "cc"]' -->
405
+ * ```
406
+ * @param {Array|Object} `collection`
407
+ * @param {Function} `prop`
408
+ * @return {String}
409
+ * @api public
410
+ */
411
+ exports.helpers.pluck = function (arr, prop) {
412
+ if (handlebars_utils_1.default.isUndefined(arr))
413
+ return "";
414
+ const res = [];
415
+ for (let i = 0; i < arr.length; i++) {
416
+ const val = (0, core_1.getValue)(arr[i], prop);
417
+ if (typeof val !== "undefined") {
418
+ res.push(val);
419
+ }
420
+ }
421
+ return res;
422
+ };
423
+ /**
424
+ * Reverse the elements in an array, or the characters in a string.
425
+ *
426
+ * ```handlebars
427
+ * <!-- value: 'abcd' -->
428
+ * {{reverse value}}
429
+ * <!-- results in: 'dcba' -->
430
+ * <!-- value: ['a', 'b', 'c', 'd'] -->
431
+ * {{reverse value}}
432
+ * <!-- results in: ['d', 'c', 'b', 'a'] -->
433
+ * ```
434
+ * @param {Array|String} `value`
435
+ * @return {Array|String} Returns the reversed string or array.
436
+ * @api public
437
+ */
438
+ exports.helpers.reverse = function (val) {
439
+ if (Array.isArray(val)) {
440
+ val.reverse();
441
+ return val;
442
+ }
443
+ if (val && (0, core_1.isString)(val)) {
444
+ return val.split("").reverse().join("");
445
+ }
446
+ };
447
+ /**
448
+ * Block helper that returns the block if the callback returns true
449
+ * for some value in the given array.
450
+ *
451
+ * ```handlebars
452
+ * <!-- array: [1, 'b', 3] -->
453
+ * {{#some array isString}}
454
+ * Render me if the array has a string.
455
+ * {{else}}
456
+ * Render me if it doesn't.
457
+ * {{/some}}
458
+ * <!-- results in: 'Render me if the array has a string.' -->
459
+ * ```
460
+ * @param {Array} `array`
461
+ * @param {Function} `iter` Iteratee
462
+ * @param {Options} Handlebars provided options object
463
+ * @return {String}
464
+ * @block
465
+ * @api public
466
+ */
467
+ exports.helpers.some = function (array, iter, options) {
468
+ if (Array.isArray(array)) {
469
+ for (let i = 0; i < array.length; i++) {
470
+ if (iter(array[i], i, array)) {
471
+ return options.fn(this);
472
+ }
473
+ }
474
+ }
475
+ return options.inverse(this);
476
+ };
477
+ /**
478
+ * Sort the given `array`. If an array of objects is passed,
479
+ * you may optionally pass a `key` to sort on as the second
480
+ * argument. You may alternatively pass a sorting function as
481
+ * the second argument.
482
+ *
483
+ * ```handlebars
484
+ * <!-- array: ['b', 'a', 'c'] -->
485
+ * {{sort array}}
486
+ * <!-- results in: '["a", "b", "c"]' -->
487
+ * ```
488
+ *
489
+ * @param {Array} `array` the array to sort.
490
+ * @param {String|Function} `key` The object key to sort by, or sorting function.
491
+ * @api public
492
+ */
493
+ exports.helpers.sort = function (array, options) {
494
+ if (!Array.isArray(array))
495
+ return "";
496
+ if ((0, core_1.getValue)(options, "hash.reverse")) {
497
+ return array.sort().reverse();
498
+ }
499
+ return array.sort();
500
+ };
501
+ /**
502
+ * Block helper that return an array with all duplicate
503
+ * values removed. Best used along with a [each](#each) helper.
504
+ *
505
+ * ```handlebars
506
+ * <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
507
+ * {{#each (unique array)}}{{.}}{{/each}}
508
+ * <!-- results in: 'acbe' -->
509
+ * ```
510
+ * @param {Array} `array`
511
+ * @param {Object} `options`
512
+ * @return {Array}
513
+ * @api public
514
+ */
515
+ exports.helpers.unique = function (array) {
516
+ if (handlebars_utils_1.default.isUndefined(array))
517
+ return "";
518
+ return array.filter(function (item, index, arr) {
519
+ return arr.indexOf(item) === index;
520
+ });
521
+ };
522
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../../../src/utils/hbs/array.ts"],"names":[],"mappings":";;;;AAAA,qCAA2E;AAC3E,6DAA6D;AAC7D,aAAa;AACb,wEAAuC;AACvC,6DAA6D;AAC7D,aAAa;AACb,gFAAoC;AAEvB,QAAA,OAAO,GAAQ,EAAE,CAAC;AAE/B;;;;;;;;;;;;;GAaG;AAEH,eAAO,CAAC,KAAK,GAAG,UAAU,KAAqB,EAAE,CAAM;IACrD,IAAI,0BAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACvC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AAEH,eAAO,CAAC,QAAQ,GAAG,UAAU,KAAU;IACrC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzD,CAAC,CAAC;AAEF;;;;;;;;;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;;;;;;;;;;;;;;GAeG;AAEH,eAAO,CAAC,IAAI,GAAG,UAAU,KAAY,EAAE,OAAY;IACjD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,IAAI,IAAA,eAAQ,EAAC,OAAO,EAAE,cAAc,CAAC,EAAE;QACrC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;KAC/B;IACD,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AACtB,CAAC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AAEH,eAAO,CAAC,MAAM,GAAG,UAAU,KAAY;IACrC,IAAI,0BAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEvC,OAAO,KAAK,CAAC,MAAM,CAAC,UAAU,IAAI,EAAE,KAAK,EAAE,GAAG;QAC5C,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC;IACrC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import {getValue, isArray, isNumber, isObject, isString} from \"@tsed/core\";\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport createFrame from \"create-frame\";\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport util from \"handlebars-utils\";\n\nexport const helpers: any = {};\n\n/**\n * Returns all of the items in an array after the specified index.\n * Opposite of [before](#before).\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{after array 1}}\n * <!-- results in: '[\"c\"]' -->\n * ```\n * @param {Array} `array` Collection\n * @param {Number} `n` Starting index (number of items to exclude)\n * @return {Array} Array exluding `n` items.\n * @api public\n */\n\nhelpers.after = function (array: string | any[], n: any) {\n if (util.isUndefined(array)) return \"\";\n return array.slice(n);\n};\n\n/**\n * Cast the given `value` to an array.\n *\n * ```handlebars\n * {{arrayify \"foo\"}}\n * <!-- results in: [ \"foo\" ] -->\n * ```\n * @param {any} `value`\n * @return {Array}\n * @api public\n */\n\nhelpers.arrayify = function (value: any) {\n return value ? (isArray(value) ? value : [value]) : [];\n};\n\n/**\n * Return all of the items in the collection before the specified\n * count. Opposite of [after](#after).\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{before array 2}}\n * <!-- results in: '[\"a\", \"b\"]' -->\n * ```\n * @param {Array} `array`\n * @param {Number} `n`\n * @return {Array} Array excluding items after the given number.\n * @api public\n */\n\nhelpers.before = function (array: string | any[], n: number) {\n if (util.isUndefined(array)) return \"\";\n return array.slice(0, -n);\n};\n\n/**\n * ```handlebars\n * <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->\n * {{#eachIndex array}}\n * {{item}} is {{index}}\n * {{/eachIndex}}\n * ```\n * @param {Array} `array`\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.eachIndex = function (array: string | any[], options: {fn: (arg0: {item: any; index: number}) => string}) {\n let result = \"\";\n for (let i = 0; i < array.length; i++) {\n result += options.fn({item: array[i], index: i});\n }\n return result;\n};\n\n/**\n * Block helper that filters the given array and renders the block for values that\n * evaluate to `true`, otherwise the inverse block is returned.\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{#filter array \"foo\"}}AAA{{else}}BBB{{/filter}}\n * <!-- results in: 'BBB' -->\n * ```\n * @param {Array} `array`\n * @param {any} `value`\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.filter = function (\n array: any[],\n value: any,\n options: {hash: {property: any; prop: any}; fn: (arg0: any) => string; inverse: (arg0: any) => any}\n) {\n let content = \"\";\n let results = [];\n\n // filter on a specific property\n const prop = options.hash && (options.hash.property || options.hash.prop);\n if (prop) {\n results = array.filter(function (val) {\n return value === getValue(val, prop);\n });\n } else {\n // filter on a string value\n results = array.filter(function (v) {\n return value === v;\n });\n }\n\n if (results && results.length > 0) {\n for (let i = 0; i < results.length; i++) {\n content += options.fn(results[i]);\n }\n return content;\n }\n return options.inverse(this);\n};\n\n/**\n * Returns the first item, or first `n` items of an array.\n *\n * ```handlebars\n * {{first \"['a', 'b', 'c', 'd', 'e']\" 2}}\n * <!-- results in: '[\"a\", \"b\"]' -->\n * ```\n * @param {Array} `array`\n * @param {Number} `n` Number of items to return, starting at `0`.\n * @return {Array}\n * @api public\n */\n\nhelpers.first = function (array: string | any[], n: any) {\n if (array === undefined) return \"\";\n if (!isNumber(n)) {\n return array[0];\n }\n return array.slice(0, n);\n};\n\n/**\n * Iterates over each item in an array and exposes the current item\n * in the array as context to the inner block. In addition to\n * the current array item, the helper exposes the following variables\n * to the inner block:\n *\n * - `index`\n * - `total`\n * - `isFirst`\n * - `isLast`\n *\n * Also, `@index` is exposed as a private variable, and additional\n * private variables may be defined as hash arguments.\n *\n * ```handlebars\n * <!-- accounts = [\n * {'name': 'John', 'email': 'john@example.com'},\n * {'name': 'Malcolm', 'email': 'malcolm@example.com'},\n * {'name': 'David', 'email': 'david@example.com'}\n * ] -->\n *\n * {{#forEach accounts}}\n * <a href=\"mailto:{{ email }}\" title=\"Send an email to {{ name }}\">\n * {{ name }}\n * </a>{{#unless isLast}}, {{/unless}}\n * {{/forEach}}\n * ```\n * @source <http://stackoverflow.com/questions/13861007>\n * @param {Array} `array`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.forEach = function (array: string | any[], options: any) {\n const data = createFrame(options, options.hash);\n const len = array.length;\n let buffer = \"\";\n let i = -1;\n\n while (++i < len) {\n const item = array[i];\n data.index = i;\n item.index = i + 1;\n item.total = len;\n item.isFirst = i === 0;\n item.isLast = i === len - 1;\n buffer += options.fn(item, {data: data});\n }\n return buffer;\n};\n\n/**\n * Block helper that renders the block if an array has the\n * given `value`. Optionally specify an inverse block to render\n * when the array does not have the given value.\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{#inArray array \"d\"}}\n * foo\n * {{else}}\n * bar\n * {{/inArray}}\n * <!-- results in: 'bar' -->\n * ```\n * @param {Array} `array`\n * @param {any} `value`\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.inArray = function (array: any[], value: any, options: any) {\n return util.value(util.indexOf(array, value) > -1, this, options);\n};\n\n/**\n * Returns true if `value` is an es5 array.\n *\n * ```handlebars\n * {{isArray \"abc\"}}\n * <!-- results in: false -->\n *\n * <!-- array: [1, 2, 3] -->\n * {{isArray array}}\n * <!-- results in: true -->\n * ```\n * @param {any} `value` The value to test.\n * @return {Boolean}\n * @api public\n */\n\nhelpers.isArray = function (value: any) {\n return Array.isArray(value);\n};\n\n/**\n * Returns the item from `array` at index `idx`.\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{itemAt array 1}}\n * <!-- results in: 'b' -->\n * ```\n * @param {Array} `array`\n * @param {Number} `idx`\n * @return {any} `value`\n * @block\n * @api public\n */\n\nhelpers.itemAt = function (array: string | any[], idx: number) {\n array = util.result(array);\n if (isArray(array)) {\n idx = isNumber(idx) ? +idx : 0;\n if (idx < 0) {\n return array[array.length + idx];\n }\n if (idx < array.length) {\n return array[idx];\n }\n }\n};\n\n/**\n * Join all elements of array into a string, optionally using a\n * given separator.\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'] -->\n * {{join array}}\n * <!-- results in: 'a, b, c' -->\n *\n * {{join array '-'}}\n * <!-- results in: 'a-b-c' -->\n * ```\n * @param {Array} `array`\n * @param {String} `separator` The separator to use. Defaults to `, `.\n * @return {String}\n * @api public\n */\n\nhelpers.join = function (array: string | any[], separator: string | undefined) {\n if (isString(array)) return array;\n if (!isArray(array)) return \"\";\n separator = util.isString(separator) ? separator : \", \";\n return array.join(separator);\n};\n\n/**\n * Returns true if the the length of the given `value` is equal\n * to the given `length`. Can be used as a block or inline helper.\n *\n * @param {Array|String} `value`\n * @param {Number} `length`\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.equalsLength = function (value: string | any[], length: number, options: any) {\n if (util.isOptions(length)) {\n options = length;\n length = 0;\n }\n\n let len = 0;\n if (typeof value === \"string\" || Array.isArray(value)) {\n len = value.length;\n }\n\n return util.value(len === length, this, options);\n};\n\n/**\n * Returns the last item, or last `n` items of an array or string.\n * Opposite of [first](#first).\n *\n * ```handlebars\n * <!-- var value = ['a', 'b', 'c', 'd', 'e'] -->\n *\n * {{last value}}\n * <!-- results in: ['e'] -->\n *\n * {{last value 2}}\n * <!-- results in: ['d', 'e'] -->\n *\n * {{last value 3}}\n * <!-- results in: ['c', 'd', 'e'] -->\n * ```\n * @param {Array|String} `value` Array or string.\n * @param {Number} `n` Number of items to return from the end of the array.\n * @return {Array}\n * @api public\n */\n\nhelpers.last = function (value: string | any[], n: number) {\n if (!isArray(value) && typeof value !== \"string\") {\n return \"\";\n }\n if (!isNumber(n)) {\n return value[value.length - 1];\n }\n return value.slice(-Math.abs(n));\n};\n\n/**\n * Returns the length of the given string or array.\n *\n * ```handlebars\n * {{length '[\"a\", \"b\", \"c\"]'}}\n * <!-- results in: 3 -->\n *\n * <!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->\n * {{length myArray}}\n * <!-- results in: 5 -->\n *\n * <!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->\n * {{length myObject}}\n * <!-- results in: 2 -->\n * ```\n * @param {Array|Object|String} `value`\n * @return {Number} The length of the value.\n * @api public\n */\n\nhelpers.length = function (value: string | any[]) {\n if (isObject(value) && !util.isOptions(value)) {\n value = Object.keys(value);\n }\n if (typeof value === \"string\" || Array.isArray(value)) {\n return value.length;\n }\n return 0;\n};\n\n/**\n * Returns a new array, created by calling `function` on each\n * element of the given `array`. For example,\n *\n * ```handlebars\n * <!-- array: ['a', 'b', 'c'], and \"double\" is a\n * fictitious function that duplicates letters -->\n * {{map array double}}\n * <!-- results in: '[\"aa\", \"bb\", \"cc\"]' -->\n * ```\n *\n * @param {Array} `array`\n * @param {Function} `fn`\n * @return {String}\n * @api public\n */\n\nhelpers.map = function (array: string | any[], iter: (arg0: any, arg1: number, arg2: any[]) => any) {\n if (!Array.isArray(array)) return \"\";\n const len = array.length;\n const res = new Array(len);\n let i = -1;\n\n if (typeof iter !== \"function\") {\n return array;\n }\n\n while (++i < len) {\n res[i] = iter(array[i], i, array);\n }\n return res;\n};\n\n/**\n * Map over the given object or array or objects and create an array of values\n * from the given `prop`. Dot-notation may be used (as a string) to get\n * nested properties.\n *\n * ```handlebars\n * // {{pluck items \"data.title\"}}\n * <!-- results in: '[\"aa\", \"bb\", \"cc\"]' -->\n * ```\n * @param {Array|Object} `collection`\n * @param {Function} `prop`\n * @return {String}\n * @api public\n */\n\nhelpers.pluck = function (arr: string | any[], prop: any) {\n if (util.isUndefined(arr)) return \"\";\n const res = [];\n for (let i = 0; i < arr.length; i++) {\n const val = getValue(arr[i], prop);\n if (typeof val !== \"undefined\") {\n res.push(val);\n }\n }\n return res;\n};\n\n/**\n * Reverse the elements in an array, or the characters in a string.\n *\n * ```handlebars\n * <!-- value: 'abcd' -->\n * {{reverse value}}\n * <!-- results in: 'dcba' -->\n * <!-- value: ['a', 'b', 'c', 'd'] -->\n * {{reverse value}}\n * <!-- results in: ['d', 'c', 'b', 'a'] -->\n * ```\n * @param {Array|String} `value`\n * @return {Array|String} Returns the reversed string or array.\n * @api public\n */\n\nhelpers.reverse = function (val: string | []) {\n if (Array.isArray(val)) {\n val.reverse();\n return val;\n }\n if (val && isString(val)) {\n return val.split(\"\").reverse().join(\"\");\n }\n};\n\n/**\n * Block helper that returns the block if the callback returns true\n * for some value in the given array.\n *\n * ```handlebars\n * <!-- array: [1, 'b', 3] -->\n * {{#some array isString}}\n * Render me if the array has a string.\n * {{else}}\n * Render me if it doesn't.\n * {{/some}}\n * <!-- results in: 'Render me if the array has a string.' -->\n * ```\n * @param {Array} `array`\n * @param {Function} `iter` Iteratee\n * @param {Options} Handlebars provided options object\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.some = function (array: string | any[], iter: (arg0: any, arg1: number, arg2: any[]) => any, options: any) {\n if (Array.isArray(array)) {\n for (let i = 0; i < array.length; i++) {\n if (iter(array[i], i, array)) {\n return options.fn(this);\n }\n }\n }\n return options.inverse(this);\n};\n\n/**\n * Sort the given `array`. If an array of objects is passed,\n * you may optionally pass a `key` to sort on as the second\n * argument. You may alternatively pass a sorting function as\n * the second argument.\n *\n * ```handlebars\n * <!-- array: ['b', 'a', 'c'] -->\n * {{sort array}}\n * <!-- results in: '[\"a\", \"b\", \"c\"]' -->\n * ```\n *\n * @param {Array} `array` the array to sort.\n * @param {String|Function} `key` The object key to sort by, or sorting function.\n * @api public\n */\n\nhelpers.sort = function (array: any[], options: any) {\n if (!Array.isArray(array)) return \"\";\n if (getValue(options, \"hash.reverse\")) {\n return array.sort().reverse();\n }\n return array.sort();\n};\n\n/**\n * Block helper that return an array with all duplicate\n * values removed. Best used along with a [each](#each) helper.\n *\n * ```handlebars\n * <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->\n * {{#each (unique array)}}{{.}}{{/each}}\n * <!-- results in: 'acbe' -->\n * ```\n * @param {Array} `array`\n * @param {Object} `options`\n * @return {Array}\n * @api public\n */\n\nhelpers.unique = function (array: any[]) {\n if (util.isUndefined(array)) return \"\";\n\n return array.filter(function (item, index, arr) {\n return arr.indexOf(item) === index;\n });\n};\n"]}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.helpers = void 0;
4
+ const tslib_1 = require("tslib");
5
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
6
+ // @ts-ignore
7
+ const handlebars_utils_1 = tslib_1.__importDefault(require("handlebars-utils"));
8
+ const object_1 = require("./object");
9
+ const array_1 = require("./array");
10
+ const forEach = array_1.helpers.forEach;
11
+ const forOwn = object_1.helpers.forOwn;
12
+ exports.helpers = {};
13
+ /**
14
+ * Inline, subexpression, or block helper that returns true (or the block)
15
+ * if the given collection is empty, or false (or the inverse block, if
16
+ * supplied) if the colleciton is not empty.
17
+ *
18
+ * ```handlebars
19
+ * <!-- array: [] -->
20
+ * {{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
21
+ * <!-- results in: 'AAA' -->
22
+ *
23
+ * <!-- array: [] -->
24
+ * {{isEmpty array}}
25
+ * <!-- results in: true -->
26
+ * ```
27
+ * @param {Object} `collection`
28
+ * @param {Object} `options`
29
+ * @return {String}
30
+ * @block
31
+ * @api public
32
+ */
33
+ exports.helpers.isEmpty = function (collection, options) {
34
+ if (!handlebars_utils_1.default.isOptions(options)) {
35
+ options = collection;
36
+ return handlebars_utils_1.default.fn(true, this, options);
37
+ }
38
+ if (Array.isArray(collection) && !collection.length) {
39
+ return handlebars_utils_1.default.fn(true, this, options);
40
+ }
41
+ const keys = Object.keys(collection);
42
+ const isEmpty = typeof collection === "object" && !keys.length;
43
+ return handlebars_utils_1.default.value(isEmpty, this, options);
44
+ };
45
+ /**
46
+ * Block helper that iterates over an array or object. If
47
+ * an array is given, `.forEach` is called, or if an object
48
+ * is given, `.forOwn` is called, otherwise the inverse block
49
+ * is returned.
50
+ *
51
+ * @param {Object|Array} `collection` The collection to iterate over
52
+ * @param {Object} `options`
53
+ * @return {String}
54
+ * @block
55
+ * @api public
56
+ */
57
+ exports.helpers.iterate = function (collection, options) {
58
+ if (Array.isArray(collection)) {
59
+ return forEach.apply(null, [collection, options]);
60
+ }
61
+ if (handlebars_utils_1.default.isObject(collection)) {
62
+ return forOwn.apply(null, [collection, options]);
63
+ }
64
+ return options.inverse(this);
65
+ };
66
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../src/utils/hbs/collection.ts"],"names":[],"mappings":";;;;AAAA,6DAA6D;AAC7D,aAAa;AACb,gFAAoC;AACpC,qCAA2C;AAC3C,mCAAyC;AAEzC,MAAM,OAAO,GAAG,eAAK,CAAC,OAAO,CAAC;AAC9B,MAAM,MAAM,GAAG,gBAAM,CAAC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-comment\n// @ts-ignore\nimport util from \"handlebars-utils\";\nimport {helpers as object} from \"./object\";\nimport {helpers as array} from \"./array\";\n\nconst forEach = array.forEach;\nconst forOwn = object.forOwn;\nexport const helpers: any = {};\n\n/**\n * Inline, subexpression, or block helper that returns true (or the block)\n * if the given collection is empty, or false (or the inverse block, if\n * supplied) if the colleciton is not empty.\n *\n * ```handlebars\n * <!-- array: [] -->\n * {{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}\n * <!-- results in: 'AAA' -->\n *\n * <!-- array: [] -->\n * {{isEmpty array}}\n * <!-- results in: true -->\n * ```\n * @param {Object} `collection`\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.isEmpty = function (collection: any, options: any) {\n if (!util.isOptions(options)) {\n options = collection;\n return util.fn(true, this, options);\n }\n\n if (Array.isArray(collection) && !collection.length) {\n return util.fn(true, this, options);\n }\n\n const keys = Object.keys(collection);\n const isEmpty = typeof collection === \"object\" && !keys.length;\n return util.value(isEmpty, this, options);\n};\n\n/**\n * Block helper that iterates over an array or object. If\n * an array is given, `.forEach` is called, or if an object\n * is given, `.forOwn` is called, otherwise the inverse block\n * is returned.\n *\n * @param {Object|Array} `collection` The collection to iterate over\n * @param {Object} `options`\n * @return {String}\n * @block\n * @api public\n */\n\nhelpers.iterate = function (collection: any, options: any) {\n if (Array.isArray(collection)) {\n return forEach.apply(null, [collection, options]);\n }\n if (util.isObject(collection)) {\n return forOwn.apply(null, [collection, options]);\n }\n return options.inverse(this);\n};\n"]}