@taon-dev/i18n 0.0.1

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 (301) hide show
  1. package/VERIFIED-BUILD-DATA.jsonc +5 -0
  2. package/assets/shared/shared_folder_info.txt +7 -0
  3. package/bin/i18n +5 -0
  4. package/bin/i18n-debug +5 -0
  5. package/bin/i18n-debug-brk +4 -0
  6. package/bin/start.js +38 -0
  7. package/browser/README.md +24 -0
  8. package/browser/fesm2022/i18n-browser.mjs +521 -0
  9. package/browser/fesm2022/i18n-browser.mjs.map +1 -0
  10. package/browser/package.json +23 -0
  11. package/browser/types/i18n-browser.d.ts +353 -0
  12. package/browser-prod/README.md +24 -0
  13. package/browser-prod/fesm2022/i18n-browser-prod.mjs +521 -0
  14. package/browser-prod/fesm2022/i18n-browser-prod.mjs.map +1 -0
  15. package/browser-prod/package.json +23 -0
  16. package/browser-prod/types/i18n-browser-prod.d.ts +353 -0
  17. package/browser-prod.re-export.json +1 -0
  18. package/browser-prod.split-namespaces.json +4 -0
  19. package/cli.d.ts +1 -0
  20. package/cli.js +8 -0
  21. package/cli.js.map +1 -0
  22. package/html/assets/generated/pwa/html-pwa.html +60 -0
  23. package/html/imports.html +3 -0
  24. package/index.d.ts +3 -0
  25. package/index.js +20 -0
  26. package/index.js.map +1 -0
  27. package/lib/build-info._auto-generated_.d.ts +24 -0
  28. package/lib/build-info._auto-generated_.js +30 -0
  29. package/lib/build-info._auto-generated_.js.map +1 -0
  30. package/lib/env/env.angular-node-app.d.ts +67 -0
  31. package/lib/env/env.angular-node-app.js +141 -0
  32. package/lib/env/env.angular-node-app.js.map +1 -0
  33. package/lib/env/env.docs-webapp.d.ts +67 -0
  34. package/lib/env/env.docs-webapp.js +141 -0
  35. package/lib/env/env.docs-webapp.js.map +1 -0
  36. package/lib/env/env.electron-app.d.ts +67 -0
  37. package/lib/env/env.electron-app.js +141 -0
  38. package/lib/env/env.electron-app.js.map +1 -0
  39. package/lib/env/env.mobile-app.d.ts +67 -0
  40. package/lib/env/env.mobile-app.js +141 -0
  41. package/lib/env/env.mobile-app.js.map +1 -0
  42. package/lib/env/env.npm-lib-and-cli-tool.d.ts +67 -0
  43. package/lib/env/env.npm-lib-and-cli-tool.js +141 -0
  44. package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -0
  45. package/lib/env/env.vscode-plugin.d.ts +67 -0
  46. package/lib/env/env.vscode-plugin.js +141 -0
  47. package/lib/env/env.vscode-plugin.js.map +1 -0
  48. package/lib/env/index.d.ts +6 -0
  49. package/lib/env/index.js +23 -0
  50. package/lib/env/index.js.map +1 -0
  51. package/lib/features/index.d.ts +4 -0
  52. package/lib/features/index.js +21 -0
  53. package/lib/features/index.js.map +1 -0
  54. package/lib/features/types.d.ts +4 -0
  55. package/lib/features/types.js +3 -0
  56. package/lib/features/types.js.map +1 -0
  57. package/lib/features/withLanguageLocalStorageSync.d.ts +9 -0
  58. package/lib/features/withLanguageLocalStorageSync.js +39 -0
  59. package/lib/features/withLanguageLocalStorageSync.js.map +1 -0
  60. package/lib/features/withNavigatorLanguage.d.ts +6 -0
  61. package/lib/features/withNavigatorLanguage.js +29 -0
  62. package/lib/features/withNavigatorLanguage.js.map +1 -0
  63. package/lib/features/withPreloadScopes.d.ts +8 -0
  64. package/lib/features/withPreloadScopes.js +25 -0
  65. package/lib/features/withPreloadScopes.js.map +1 -0
  66. package/lib/features/withServerSideLanguage.d.ts +6 -0
  67. package/lib/features/withServerSideLanguage.js +29 -0
  68. package/lib/features/withServerSideLanguage.js.map +1 -0
  69. package/lib/features/withTranslatedTitle.d.ts +34 -0
  70. package/lib/features/withTranslatedTitle.js +69 -0
  71. package/lib/features/withTranslatedTitle.js.map +1 -0
  72. package/lib/index._auto-generated_.d.ts +16 -0
  73. package/lib/index._auto-generated_.js +38 -0
  74. package/lib/index._auto-generated_.js.map +1 -0
  75. package/lib/index.d.ts +4 -0
  76. package/lib/index.js +20 -0
  77. package/lib/index.js.map +1 -0
  78. package/lib/internals.d.ts +2 -0
  79. package/lib/internals.js +6 -0
  80. package/lib/internals.js.map +1 -0
  81. package/lib/package.json +4 -0
  82. package/lib/start-cli.d.ts +7 -0
  83. package/lib/start-cli.js +46 -0
  84. package/lib/start-cli.js.map +1 -0
  85. package/lib/transignal-config.d.ts +34 -0
  86. package/lib/transignal-config.js +42 -0
  87. package/lib/transignal-config.js.map +1 -0
  88. package/lib/transignal-param-handlers.d.ts +11 -0
  89. package/lib/transignal-param-handlers.js +31 -0
  90. package/lib/transignal-param-handlers.js.map +1 -0
  91. package/lib/transignal-service.d.ts +32 -0
  92. package/lib/transignal-service.js +206 -0
  93. package/lib/transignal-service.js.map +1 -0
  94. package/lib/transignal-testing.d.ts +8 -0
  95. package/lib/transignal-testing.js +14 -0
  96. package/lib/transignal-testing.js.map +1 -0
  97. package/lib/types.d.ts +124 -0
  98. package/lib/types.js +3 -0
  99. package/lib/types.js.map +1 -0
  100. package/lib/utility-types.d.ts +29 -0
  101. package/lib/utility-types.js +3 -0
  102. package/lib/utility-types.js.map +1 -0
  103. package/lib/utils.d.ts +15 -0
  104. package/lib/utils.js +20 -0
  105. package/lib/utils.js.map +1 -0
  106. package/lib-esm/app.d.ts +3 -0
  107. package/lib-esm/app.electron.d.ts +1 -0
  108. package/lib-esm/app.electron.js +2 -0
  109. package/lib-esm/app.electron.js.map +1 -0
  110. package/lib-esm/app.hosts.d.ts +95 -0
  111. package/lib-esm/app.hosts.js +157 -0
  112. package/lib-esm/app.hosts.js.map +1 -0
  113. package/lib-esm/app.js +460 -0
  114. package/lib-esm/app.js.map +1 -0
  115. package/lib-esm/app.vscode.d.ts +9 -0
  116. package/lib-esm/app.vscode.js +37 -0
  117. package/lib-esm/app.vscode.js.map +1 -0
  118. package/lib-esm/cli.d.ts +1 -0
  119. package/lib-esm/cli.js +4 -0
  120. package/lib-esm/cli.js.map +1 -0
  121. package/lib-esm/index.d.ts +3 -0
  122. package/lib-esm/index.js +4 -0
  123. package/lib-esm/index.js.map +1 -0
  124. package/lib-esm/lib/build-info._auto-generated_.d.ts +24 -0
  125. package/lib-esm/lib/build-info._auto-generated_.js +27 -0
  126. package/lib-esm/lib/build-info._auto-generated_.js.map +1 -0
  127. package/lib-esm/lib/env/env.angular-node-app.d.ts +67 -0
  128. package/lib-esm/lib/env/env.angular-node-app.js +137 -0
  129. package/lib-esm/lib/env/env.angular-node-app.js.map +1 -0
  130. package/lib-esm/lib/env/env.docs-webapp.d.ts +67 -0
  131. package/lib-esm/lib/env/env.docs-webapp.js +137 -0
  132. package/lib-esm/lib/env/env.docs-webapp.js.map +1 -0
  133. package/lib-esm/lib/env/env.electron-app.d.ts +67 -0
  134. package/lib-esm/lib/env/env.electron-app.js +137 -0
  135. package/lib-esm/lib/env/env.electron-app.js.map +1 -0
  136. package/lib-esm/lib/env/env.mobile-app.d.ts +67 -0
  137. package/lib-esm/lib/env/env.mobile-app.js +137 -0
  138. package/lib-esm/lib/env/env.mobile-app.js.map +1 -0
  139. package/lib-esm/lib/env/env.npm-lib-and-cli-tool.d.ts +67 -0
  140. package/lib-esm/lib/env/env.npm-lib-and-cli-tool.js +137 -0
  141. package/lib-esm/lib/env/env.npm-lib-and-cli-tool.js.map +1 -0
  142. package/lib-esm/lib/env/env.vscode-plugin.d.ts +67 -0
  143. package/lib-esm/lib/env/env.vscode-plugin.js +137 -0
  144. package/lib-esm/lib/env/env.vscode-plugin.js.map +1 -0
  145. package/lib-esm/lib/env/index.d.ts +6 -0
  146. package/lib-esm/lib/env/index.js +7 -0
  147. package/lib-esm/lib/env/index.js.map +1 -0
  148. package/lib-esm/lib/features/index.d.ts +4 -0
  149. package/lib-esm/lib/features/index.js +5 -0
  150. package/lib-esm/lib/features/index.js.map +1 -0
  151. package/lib-esm/lib/features/types.d.ts +4 -0
  152. package/lib-esm/lib/features/types.js +2 -0
  153. package/lib-esm/lib/features/types.js.map +1 -0
  154. package/lib-esm/lib/features/withLanguageLocalStorageSync.d.ts +9 -0
  155. package/lib-esm/lib/features/withLanguageLocalStorageSync.js +35 -0
  156. package/lib-esm/lib/features/withLanguageLocalStorageSync.js.map +1 -0
  157. package/lib-esm/lib/features/withNavigatorLanguage.d.ts +6 -0
  158. package/lib-esm/lib/features/withNavigatorLanguage.js +25 -0
  159. package/lib-esm/lib/features/withNavigatorLanguage.js.map +1 -0
  160. package/lib-esm/lib/features/withPreloadScopes.d.ts +8 -0
  161. package/lib-esm/lib/features/withPreloadScopes.js +21 -0
  162. package/lib-esm/lib/features/withPreloadScopes.js.map +1 -0
  163. package/lib-esm/lib/features/withServerSideLanguage.d.ts +6 -0
  164. package/lib-esm/lib/features/withServerSideLanguage.js +25 -0
  165. package/lib-esm/lib/features/withServerSideLanguage.js.map +1 -0
  166. package/lib-esm/lib/features/withTranslatedTitle.d.ts +34 -0
  167. package/lib-esm/lib/features/withTranslatedTitle.js +65 -0
  168. package/lib-esm/lib/features/withTranslatedTitle.js.map +1 -0
  169. package/lib-esm/lib/index._auto-generated_.d.ts +16 -0
  170. package/lib-esm/lib/index._auto-generated_.js +22 -0
  171. package/lib-esm/lib/index._auto-generated_.js.map +1 -0
  172. package/lib-esm/lib/index.d.ts +4 -0
  173. package/lib-esm/lib/index.js +4 -0
  174. package/lib-esm/lib/index.js.map +1 -0
  175. package/lib-esm/lib/internals.d.ts +2 -0
  176. package/lib-esm/lib/internals.js +3 -0
  177. package/lib-esm/lib/internals.js.map +1 -0
  178. package/lib-esm/lib/start-cli.d.ts +7 -0
  179. package/lib-esm/lib/start-cli.js +43 -0
  180. package/lib-esm/lib/start-cli.js.map +1 -0
  181. package/lib-esm/lib/transignal-config.d.ts +34 -0
  182. package/lib-esm/lib/transignal-config.js +36 -0
  183. package/lib-esm/lib/transignal-config.js.map +1 -0
  184. package/lib-esm/lib/transignal-param-handlers.d.ts +11 -0
  185. package/lib-esm/lib/transignal-param-handlers.js +25 -0
  186. package/lib-esm/lib/transignal-param-handlers.js.map +1 -0
  187. package/lib-esm/lib/transignal-service.d.ts +32 -0
  188. package/lib-esm/lib/transignal-service.js +197 -0
  189. package/lib-esm/lib/transignal-service.js.map +1 -0
  190. package/lib-esm/lib/transignal-testing.d.ts +8 -0
  191. package/lib-esm/lib/transignal-testing.js +10 -0
  192. package/lib-esm/lib/transignal-testing.js.map +1 -0
  193. package/lib-esm/lib/types.d.ts +124 -0
  194. package/lib-esm/lib/types.js +2 -0
  195. package/lib-esm/lib/types.js.map +1 -0
  196. package/lib-esm/lib/utility-types.d.ts +29 -0
  197. package/lib-esm/lib/utility-types.js +2 -0
  198. package/lib-esm/lib/utility-types.js.map +1 -0
  199. package/lib-esm/lib/utils.d.ts +15 -0
  200. package/lib-esm/lib/utils.js +15 -0
  201. package/lib-esm/lib/utils.js.map +1 -0
  202. package/lib-prod/build-info._auto-generated_.d.ts +24 -0
  203. package/lib-prod/build-info._auto-generated_.js +27 -0
  204. package/lib-prod/build-info._auto-generated_.js.map +1 -0
  205. package/lib-prod/env/env.angular-node-app.d.ts +67 -0
  206. package/lib-prod/env/env.angular-node-app.js +137 -0
  207. package/lib-prod/env/env.angular-node-app.js.map +1 -0
  208. package/lib-prod/env/env.docs-webapp.d.ts +67 -0
  209. package/lib-prod/env/env.docs-webapp.js +137 -0
  210. package/lib-prod/env/env.docs-webapp.js.map +1 -0
  211. package/lib-prod/env/env.electron-app.d.ts +67 -0
  212. package/lib-prod/env/env.electron-app.js +137 -0
  213. package/lib-prod/env/env.electron-app.js.map +1 -0
  214. package/lib-prod/env/env.mobile-app.d.ts +67 -0
  215. package/lib-prod/env/env.mobile-app.js +137 -0
  216. package/lib-prod/env/env.mobile-app.js.map +1 -0
  217. package/lib-prod/env/env.npm-lib-and-cli-tool.d.ts +67 -0
  218. package/lib-prod/env/env.npm-lib-and-cli-tool.js +137 -0
  219. package/lib-prod/env/env.npm-lib-and-cli-tool.js.map +1 -0
  220. package/lib-prod/env/env.vscode-plugin.d.ts +67 -0
  221. package/lib-prod/env/env.vscode-plugin.js +137 -0
  222. package/lib-prod/env/env.vscode-plugin.js.map +1 -0
  223. package/lib-prod/env/index.d.ts +6 -0
  224. package/lib-prod/env/index.js +7 -0
  225. package/lib-prod/env/index.js.map +1 -0
  226. package/lib-prod/features/index.d.ts +4 -0
  227. package/lib-prod/features/index.js +5 -0
  228. package/lib-prod/features/index.js.map +1 -0
  229. package/lib-prod/features/types.d.ts +4 -0
  230. package/lib-prod/features/types.js +2 -0
  231. package/lib-prod/features/types.js.map +1 -0
  232. package/lib-prod/features/withLanguageLocalStorageSync.d.ts +9 -0
  233. package/lib-prod/features/withLanguageLocalStorageSync.js +35 -0
  234. package/lib-prod/features/withLanguageLocalStorageSync.js.map +1 -0
  235. package/lib-prod/features/withNavigatorLanguage.d.ts +6 -0
  236. package/lib-prod/features/withNavigatorLanguage.js +25 -0
  237. package/lib-prod/features/withNavigatorLanguage.js.map +1 -0
  238. package/lib-prod/features/withPreloadScopes.d.ts +8 -0
  239. package/lib-prod/features/withPreloadScopes.js +21 -0
  240. package/lib-prod/features/withPreloadScopes.js.map +1 -0
  241. package/lib-prod/features/withServerSideLanguage.d.ts +6 -0
  242. package/lib-prod/features/withServerSideLanguage.js +25 -0
  243. package/lib-prod/features/withServerSideLanguage.js.map +1 -0
  244. package/lib-prod/features/withTranslatedTitle.d.ts +34 -0
  245. package/lib-prod/features/withTranslatedTitle.js +65 -0
  246. package/lib-prod/features/withTranslatedTitle.js.map +1 -0
  247. package/lib-prod/index._auto-generated_.d.ts +16 -0
  248. package/lib-prod/index._auto-generated_.js +22 -0
  249. package/lib-prod/index._auto-generated_.js.map +1 -0
  250. package/lib-prod/index.d.ts +4 -0
  251. package/lib-prod/index.js +4 -0
  252. package/lib-prod/index.js.map +1 -0
  253. package/lib-prod/internals.d.ts +2 -0
  254. package/lib-prod/internals.js +3 -0
  255. package/lib-prod/internals.js.map +1 -0
  256. package/lib-prod/package.json +4 -0
  257. package/lib-prod/start-cli.d.ts +7 -0
  258. package/lib-prod/start-cli.js +43 -0
  259. package/lib-prod/start-cli.js.map +1 -0
  260. package/lib-prod/transignal-config.d.ts +34 -0
  261. package/lib-prod/transignal-config.js +36 -0
  262. package/lib-prod/transignal-config.js.map +1 -0
  263. package/lib-prod/transignal-param-handlers.d.ts +11 -0
  264. package/lib-prod/transignal-param-handlers.js +25 -0
  265. package/lib-prod/transignal-param-handlers.js.map +1 -0
  266. package/lib-prod/transignal-service.d.ts +32 -0
  267. package/lib-prod/transignal-service.js +197 -0
  268. package/lib-prod/transignal-service.js.map +1 -0
  269. package/lib-prod/transignal-testing.d.ts +8 -0
  270. package/lib-prod/transignal-testing.js +10 -0
  271. package/lib-prod/transignal-testing.js.map +1 -0
  272. package/lib-prod/types.d.ts +124 -0
  273. package/lib-prod/types.js +2 -0
  274. package/lib-prod/types.js.map +1 -0
  275. package/lib-prod/utility-types.d.ts +29 -0
  276. package/lib-prod/utility-types.js +2 -0
  277. package/lib-prod/utility-types.js.map +1 -0
  278. package/lib-prod/utils.d.ts +15 -0
  279. package/lib-prod/utils.js +15 -0
  280. package/lib-prod/utils.js.map +1 -0
  281. package/lib-prod.re-export.json +1 -0
  282. package/lib-prod.split-namespaces.json +4 -0
  283. package/package.json +39 -0
  284. package/scss/global.scss +94 -0
  285. package/scss/index.scss +2 -0
  286. package/scss/lib/index.scss +2 -0
  287. package/scss/vars.scss +7 -0
  288. package/src.d.ts +6 -0
  289. package/src.js +4 -0
  290. package/websql/README.md +24 -0
  291. package/websql/fesm2022/i18n-websql.mjs +521 -0
  292. package/websql/fesm2022/i18n-websql.mjs.map +1 -0
  293. package/websql/package.json +23 -0
  294. package/websql/types/i18n-websql.d.ts +353 -0
  295. package/websql-prod/README.md +24 -0
  296. package/websql-prod/fesm2022/i18n-websql-prod.mjs +521 -0
  297. package/websql-prod/fesm2022/i18n-websql-prod.mjs.map +1 -0
  298. package/websql-prod/package.json +23 -0
  299. package/websql-prod/types/i18n-websql-prod.d.ts +353 -0
  300. package/websql-prod.re-export.json +1 -0
  301. package/websql-prod.split-namespaces.json +4 -0
@@ -0,0 +1,197 @@
1
+ import { computed, EnvironmentInjector, inject, Injectable, resource, runInInjectionContext, signal, untracked, } from '@angular/core';
2
+ import { TREE_SHAKED_TRANSLATIONS } from './internals';
3
+ import { injectTransignalConfig } from './transignal-config';
4
+ import { simpleParamsHandler } from './transignal-param-handlers';
5
+ /**
6
+ * Main transignal service, used to process and cache translations
7
+ * Can be injected directly or with use of transignal object created with {@link prepareTransignal} function (recommended)
8
+ */
9
+ let TransignalService = class TransignalService {
10
+ injector = inject(EnvironmentInjector);
11
+ config = injectTransignalConfig();
12
+ paramsHandler = this.config.paramHandler ?? simpleParamsHandler;
13
+ loadingFn = this.config.loadingFn ?? (() => '...');
14
+ // eslint-disable-next-line no-console
15
+ errorHandler = this.config.errorHandler ?? console.error; // TODO maybe add a link to error page in docs
16
+ loadingCount = signal(0);
17
+ scopeMap = new Map();
18
+ languageMap = new Map();
19
+ /**
20
+ * Use to set or get active language
21
+ */
22
+ activeLang = signal(this.config.defaultLang);
23
+ /**
24
+ * Use to determine whether service is currently loading translation files
25
+ */
26
+ isLoading = computed(() => this.loadingCount() > 0);
27
+ t(scope) {
28
+ const existing = this.scopeMap.get(scope);
29
+ if (existing) {
30
+ return existing;
31
+ }
32
+ const scopeObj = this.initT(scope);
33
+ this.scopeMap.set(scope, scopeObj);
34
+ return scopeObj;
35
+ }
36
+ initT(scope) {
37
+ const cache = new Map();
38
+ const t = ((key, params) => {
39
+ const lang = this.activeLang();
40
+ const baseKey = `${lang}/${key}`;
41
+ const memoKey = params ? `${baseKey}_${JSON.stringify(params)}` : baseKey;
42
+ const alreadyComputed = cache.get(memoKey);
43
+ if (alreadyComputed) {
44
+ return alreadyComputed;
45
+ }
46
+ const { isLoading, error, value } = this.fetchLanguage(scope, lang);
47
+ if (isLoading()) {
48
+ return this.loadingFn?.(key);
49
+ }
50
+ if (error() || !value()) {
51
+ this.errorHandler('missing_file', error());
52
+ return '';
53
+ }
54
+ const result = this.replaceParams(this.resolveObjectPath(value(), key), params);
55
+ cache.set(memoKey, result);
56
+ return result;
57
+ }); // needed as other props are assigned below
58
+ t.arr = t;
59
+ t.obj = t;
60
+ t.prefix = this.preparePrefixFn(t, 1);
61
+ t.plural = this.preparePluralFn(t);
62
+ t.select = this.prepareSelectFn(t);
63
+ return t;
64
+ }
65
+ preparePrefixFn(t, depth) {
66
+ return (prefix) => {
67
+ const prefixedT = (key, params) => t(`${prefix}.${key}`, params);
68
+ prefixedT.arr = prefixedT;
69
+ prefixedT.obj = prefixedT;
70
+ prefixedT.plural = this.preparePluralFn(prefixedT);
71
+ prefixedT.select = this.prepareSelectFn(prefixedT);
72
+ prefixedT.prefix =
73
+ this.config.maxPrefixDepth || 3 >= depth
74
+ ? this.preparePrefixFn(prefixedT, depth + 1)
75
+ : () => {
76
+ this.errorHandler('prefix_too_deep');
77
+ const t = () => '';
78
+ t.arr = () => [];
79
+ t.obj = () => ({});
80
+ t.plural = () => '';
81
+ return t;
82
+ };
83
+ return prefixedT;
84
+ };
85
+ }
86
+ preparePluralFn(t) {
87
+ return (key, count, params) => {
88
+ const plurals = t(key, { count, ...params });
89
+ if (typeof plurals === 'string') {
90
+ if (plurals === this.loadingFn(key)) {
91
+ return plurals;
92
+ }
93
+ this.errorHandler('invalid_plural', key, plurals);
94
+ return plurals;
95
+ }
96
+ if (plurals[count]) {
97
+ return plurals[count];
98
+ }
99
+ const valueLastDigit = +count.toFixed(0).at(-1);
100
+ if (plurals.one && valueLastDigit === 1) {
101
+ return plurals.one;
102
+ }
103
+ if (plurals.many && valueLastDigit >= 5) {
104
+ return plurals.many;
105
+ }
106
+ if (plurals.few && valueLastDigit > 1 && valueLastDigit < 5) {
107
+ return plurals.few;
108
+ }
109
+ if (plurals.other) {
110
+ return plurals.other;
111
+ }
112
+ this.errorHandler('missing_plural', key, plurals, count);
113
+ return '';
114
+ };
115
+ }
116
+ prepareSelectFn(t) {
117
+ return (key, value, params) => {
118
+ const selects = t(key, { value, ...params });
119
+ if (typeof selects === 'string') {
120
+ if (selects === this.loadingFn(key)) {
121
+ return selects;
122
+ }
123
+ this.errorHandler('invalid_select', key, selects);
124
+ return selects;
125
+ }
126
+ if (value !== null) {
127
+ if (selects[value]) {
128
+ return selects[value];
129
+ }
130
+ }
131
+ else if (selects['null']) {
132
+ return selects['null'];
133
+ }
134
+ this.errorHandler('missing_select', key, selects, value);
135
+ return '';
136
+ };
137
+ }
138
+ replaceParams(translation, params) {
139
+ if (!translation)
140
+ return translation;
141
+ if (typeof translation === 'string') {
142
+ return this.paramsHandler(translation, params);
143
+ }
144
+ if (Array.isArray(translation)) {
145
+ return translation.map(val => this.replaceParams(val, params));
146
+ }
147
+ if (typeof translation === 'object') {
148
+ return Object.entries(translation).reduce((prev, [objKey, objVal]) => {
149
+ prev[objKey] = this.replaceParams(objVal, params);
150
+ return prev;
151
+ }, {});
152
+ }
153
+ return translation;
154
+ }
155
+ fetchLanguage(scope, lang) {
156
+ const cacheKey = `${scope}/${lang}`;
157
+ const existing = this.languageMap.get(cacheKey);
158
+ if (existing)
159
+ return existing;
160
+ const { translations, loader } = this.config;
161
+ const translation = runInInjectionContext(this.injector, () => translations === TREE_SHAKED_TRANSLATIONS
162
+ ? untracked(() => resource({
163
+ loader: async () => {
164
+ this.loadingCount.update(count => ++count);
165
+ const file = await runInInjectionContext(this.injector, () => loader(scope, lang));
166
+ this.loadingCount.update(count => --count);
167
+ return file;
168
+ },
169
+ }))
170
+ : {
171
+ value: signal(translations[scope]),
172
+ isLoading: signal(false),
173
+ error: signal(undefined),
174
+ });
175
+ this.languageMap.set(cacheKey, translation);
176
+ return translation;
177
+ }
178
+ resolveObjectPath(obj, path) {
179
+ const keys = path.split('.');
180
+ let current = obj;
181
+ for (const key of keys) {
182
+ if (current && typeof current === 'object') {
183
+ current = current[key];
184
+ }
185
+ else {
186
+ this.errorHandler('missing_key', { obj, path });
187
+ return undefined;
188
+ }
189
+ }
190
+ return current;
191
+ }
192
+ };
193
+ TransignalService = __decorate([
194
+ Injectable()
195
+ ], TransignalService);
196
+ export { TransignalService };
197
+ //# sourceMappingURL=transignal-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transignal-service.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,MAAM,EACN,UAAU,EACV,QAAQ,EACR,qBAAqB,EACrB,MAAM,EACN,SAAS,GACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAWlE;;;GAGG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAKX,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;IACvC,MAAM,GAAG,sBAAsB,EAA2B,CAAC;IAC3D,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,mBAAmB,CAAC;IAChE,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;IACpE,sCAAsC;IACrB,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,8CAA8C;IACxG,YAAY,GAAG,MAAM,CAAS,CAAC,CAAC,CAAC;IACjC,QAAQ,GAAG,IAAI,GAAG,EAA8C,CAAC;IACjE,WAAW,GAAG,IAAI,GAAG,EAAwD,CAAC;IAE/F;;OAEG;IACM,UAAU,GAAG,MAAM,CAAY,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACjE;;OAEG;IACM,SAAS,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC;IAE7D,CAAC,CAAuB,KAAY;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,QA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AAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AA9MY,iBAAiB;IAD7B,UAAU,EAAE;GACA,iBAAiB,CA8M7B"}
@@ -0,0 +1,8 @@
1
+ import { prepareTransignal } from './transignal-config';
2
+ /**
3
+ * Provides unit-test version of transignal that loads translation instantly without loading
4
+ *
5
+ * @param transignal existing transignal instance
6
+ * @param translations real translations in a selected language
7
+ */
8
+ export declare const provideTransignalTesting: <Languages extends string, Translations extends Record<string, Record<string, unknown>>>(transignal: ReturnType<typeof prepareTransignal<Languages, Translations>>, translations: Translations) => import("@angular/core").EnvironmentProviders;
@@ -0,0 +1,10 @@
1
+ import { INTERNAL_TRANSIGNAL_CONFIG } from './internals';
2
+ import { prepareTransignal } from './transignal-config';
3
+ /**
4
+ * Provides unit-test version of transignal that loads translation instantly without loading
5
+ *
6
+ * @param transignal existing transignal instance
7
+ * @param translations real translations in a selected language
8
+ */
9
+ export const provideTransignalTesting = (transignal, translations) => prepareTransignal({ ...transignal[INTERNAL_TRANSIGNAL_CONFIG].config, translations }, ...transignal[INTERNAL_TRANSIGNAL_CONFIG].features).provide();
10
+ //# sourceMappingURL=transignal-testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transignal-testing.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAItC,UAAyE,EACzE,YAA0B,EAC1B,EAAE,CACF,iBAAiB,CACf,EAAE,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC,MAAM,EAAE,YAAY,EAAE,EAClE,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC,QAAQ,CACnD,CAAC,OAAO,EAAE,CAAC"}
@@ -0,0 +1,124 @@
1
+ import { ParamHandler } from './transignal-param-handlers';
2
+ import { ArrayPaths, GetNestedType, ObjectPaths, PluralPaths, SelectPaths, StringKeys, StringPaths } from './utility-types';
3
+ export type TransignalError =
4
+ /** Error when key is not found in translations */
5
+ 'missing_key'
6
+ /** Error when translation file for scope and lang has not been found */
7
+ | 'missing_file'
8
+ /** Error plural for a value is not defined for a language */
9
+ | 'missing_plural'
10
+ /** Error when plural used on a non-plural translation */
11
+ | 'invalid_plural'
12
+ /** Error select for a value is not defined for a language */
13
+ | 'missing_select'
14
+ /** Error when select used on a non-select translation */
15
+ | 'invalid_select'
16
+ /** Error when prefix chain is called more then {@link TransignalConfig.maxPrefixDepth} */
17
+ | 'prefix_too_deep';
18
+ export type TranslateParams = Record<string, unknown>;
19
+ export type Marked<K, T> = K & {
20
+ __marker: T;
21
+ };
22
+ export type BasePluralTranslation = Partial<Record<number | 'one' | 'few' | 'many' | 'other', string>>;
23
+ export type PluralTranslation = Marked<BasePluralTranslation, 'plural'>;
24
+ export type BaseSelectTranslation = Partial<Record<string | number | 'null', string>>;
25
+ export type MarkedAsSelect<T extends BaseSelectTranslation> = Marked<T, 'select'>;
26
+ export type SelectTranslation = MarkedAsSelect<BaseSelectTranslation>;
27
+ export type TranslateFn<Keys extends string, Result> = (key: Keys, params?: TranslateParams) => Result;
28
+ export type TranslateObj<Context extends Record<string, any>> = TranslateFn<StringPaths<Context>, string> & {
29
+ /**
30
+ * Returns translating function that returns an array of translations
31
+ * @param key path of translation
32
+ * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
33
+ */
34
+ arr: <ArrKey extends ArrayPaths<Context>>(key: ArrKey, params?: TranslateParams) => GetNestedType<Context, ArrKey>;
35
+ /**
36
+ * Returns translating function that returns an object of translations
37
+ * @param key path of translation
38
+ * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
39
+ */
40
+ obj: <ObjKey extends ObjectPaths<Context>>(key: ObjKey, params?: TranslateParams) => GetNestedType<Context, ObjKey>;
41
+ /**
42
+ * Returns translating function that returns a string translation depending on a correct plural form
43
+ * @param key path of translation
44
+ * @param count count to determine correct plural form
45
+ * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
46
+ */
47
+ plural: <ObjKey extends PluralPaths<Context>>(key: ObjKey, count: number, params?: TranslateParams) => string;
48
+ /**
49
+ * Returns translating function that returns a string translation depending on a selected value
50
+ * @param key path of translation
51
+ * @param value value to determine selected translation
52
+ * @param params parameters of translation in syntax defined by {@link TransignalConfig.paramHandler}
53
+ */
54
+ select: <ObjKey extends SelectPaths<Context>>(key: ObjKey, value: keyof SelectTranslation | null, params?: TranslateParams) => string;
55
+ /**
56
+ * Returns translating function that is encapsulated in a selected prefix
57
+ * @param prefix path of new root translation
58
+ */
59
+ prefix: <T extends ObjectPaths<Context>>(prefix: T) => TranslateObj<GetNestedType<Context, T>>;
60
+ };
61
+ export type TranslationFile = Record<string, unknown>;
62
+ export type TransignalConfig<Languages extends string, Translations extends Record<string, Record<string, unknown>>> = {
63
+ /**
64
+ * Default language code
65
+ */
66
+ defaultLang: NoInfer<Languages>;
67
+ /**
68
+ * An array of available languages that your application supports.
69
+ * These should be unique string identifiers for each language (e.g., ['en', 'fr', 'es']).
70
+ */
71
+ availableLangs: Languages[];
72
+ /**
73
+ * Defines the type of translations.
74
+ * Please use helper function {@link treeShakedTranslations()}
75
+ * @example
76
+ * ```typescript
77
+ * import type translations from './i18n/translations';
78
+ * ...
79
+ * translations: treeShakedTranslations<typeof translations>(),
80
+ * ```
81
+ */
82
+ translations: Translations;
83
+ /**
84
+ * A function responsible for dynamically loading translation files.
85
+ * This function is called when a specific translation scope and language is requested
86
+ * It runs in TransignalService injection context so {@link inject()} can be used to e.g. use HttpClient
87
+ *
88
+ * @param scope The string key representing the translation scope (e.g., 'common', 'auth').
89
+ * @param lang The language identifier for which to load translations (e.g., 'en', 'fr').
90
+ * @returns A Promise that resolves to a `TranslationFile` object, which is
91
+ * a record of string keys to unknown values representing the translations for
92
+ * the given scope and language.
93
+ */
94
+ loader: (scope: StringKeys<Translations>, lang: Languages) => Promise<TranslationFile>;
95
+ /**
96
+ * An optional function that defines how a loading message should be displayed
97
+ * while translations are being loaded.
98
+ *
99
+ * @param key The translation key that is currently being loaded.
100
+ * @returns A string representing the loading message.
101
+ */
102
+ loadingFn?: (key: string) => string;
103
+ /**
104
+ * An optional function that defines how params should be processed
105
+ * Defaults to {@link simpleParamsHandler}
106
+ * Use {@link noParamsHandler} if you don't want to use params
107
+ * If you want to handle message format then you can install TODO
108
+ */
109
+ paramHandler?: ParamHandler;
110
+ /**
111
+ * An optional error handler function that will be called when a `TransignalError` occurs.
112
+ * This allows you to implement custom error reporting or logging.
113
+ *
114
+ * @param errorCode Code of an error {@link TransignalError} code that occurred.
115
+ * @param args Any additional arguments relevant to the error.
116
+ */
117
+ errorHandler?: (errorCode: TransignalError, ...args: unknown[]) => void;
118
+ /**
119
+ * Defines max depth of prefix functions in {@link TranslateObj}
120
+ * Defaults to 3, this means that if prefix function is used more than 3 time on the same t then it will fail
121
+ * Required for performance reasons
122
+ */
123
+ maxPrefixDepth?: number;
124
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
@@ -0,0 +1,29 @@
1
+ import { Signal } from '@angular/core';
2
+ import { PluralTranslation, SelectTranslation } from './types';
3
+ export type GetNestedType<T, P extends string> = P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? GetNestedType<T[Key], Rest> : never : P extends keyof T ? NonNullable<T[P]> : never;
4
+ type DotPrefix<T extends string> = T extends '' ? '' : `.${T}`;
5
+ export type Paths<T> = T extends object ? T extends Array<infer U> ? `${number}${'' | DotPrefix<Paths<U>>}` : {
6
+ [K in keyof T]-?: K extends string | number ? `${K}${'' | DotPrefix<Paths<T[K]>>}` : never;
7
+ }[keyof T] : '';
8
+ export type ArrayPaths<T> = {
9
+ [P in Paths<T>]: GetNestedType<T, P> extends Array<unknown> ? P : never;
10
+ }[Paths<T>];
11
+ export type ObjectPaths<T> = {
12
+ [P in Paths<T>]: GetNestedType<T, P> extends Record<any, unknown> ? P : never;
13
+ }[Paths<T>];
14
+ export type PluralPaths<T> = {
15
+ [P in Paths<T>]: GetNestedType<T, P> extends PluralTranslation ? P : never;
16
+ }[Paths<T>];
17
+ export type SelectPaths<T> = {
18
+ [P in Paths<T>]: GetNestedType<T, P> extends SelectTranslation ? P : never;
19
+ }[Paths<T>];
20
+ export type StringPaths<T> = {
21
+ [P in Paths<T>]: GetNestedType<T, P> extends string ? P : never;
22
+ }[Paths<T>];
23
+ export type StringKeys<T> = Extract<keyof T, string>;
24
+ export type ResourceRefLike<T> = {
25
+ value: Signal<T | undefined>;
26
+ isLoading: Signal<boolean>;
27
+ error: Signal<Error | undefined>;
28
+ };
29
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utility-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility-types.js","sourceRoot":"","sources":[""],"names":[],"mappings":""}
@@ -0,0 +1,15 @@
1
+ import { BasePluralTranslation, BaseSelectTranslation, MarkedAsSelect, PluralTranslation } from './types';
2
+ /**
3
+ * Utility to create a plural translation that can differ between languages and includes variants of translations for different plurals
4
+ * Can be used with {@link TranslateObj.plural}
5
+ * Translations may use automatic param: `{count}`
6
+ * @param translation plural translation object
7
+ */
8
+ export declare const plural: (translation: BasePluralTranslation) => PluralTranslation;
9
+ /**
10
+ * Utility to create a select translation
11
+ * Can be used with {@link TranslateObj.select}
12
+ * Translations may use automatic param: `{value}`
13
+ * @param translation select translation object
14
+ */
15
+ export declare const select: <T extends BaseSelectTranslation>(translation: T) => MarkedAsSelect<T>;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Utility to create a plural translation that can differ between languages and includes variants of translations for different plurals
3
+ * Can be used with {@link TranslateObj.plural}
4
+ * Translations may use automatic param: `{count}`
5
+ * @param translation plural translation object
6
+ */
7
+ export const plural = (translation) => translation;
8
+ /**
9
+ * Utility to create a select translation
10
+ * Can be used with {@link TranslateObj.select}
11
+ * Translations may use automatic param: `{value}`
12
+ * @param translation select translation object
13
+ */
14
+ export const select = (translation) => translation;
15
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,WAAkC,EAAqB,EAAE,CAC9E,WAAgC,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAkC,WAAc,EAAE,EAAE,CACxE,WAAgC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Autogenerated by current cli tool
3
+ */
4
+ export declare const BUILD_FRAMEWORK_CLI_NAME = "tnp";
5
+ /**
6
+ * This value can be change in taon.jsonc (appId)
7
+ */
8
+ export declare const APP_ID = "com.domain.example.i18n";
9
+ /**
10
+ * Autogenerated by current cli tool
11
+ */
12
+ export declare const BUILD_BASE_HREF = "";
13
+ /**
14
+ * This value can be change in taon.jsonc (overrideNpmName)
15
+ */
16
+ export declare const PROJECT_NPM_NAME = "@taon-dev/i18n";
17
+ /**
18
+ * Taon version from you project taon.json
19
+ */
20
+ export declare const CURRENT_PACKAGE_TAON_VERSION = "v21";
21
+ /**
22
+ * Autogenerated by current cli tool. Use *tnp release* to bump version.
23
+ */
24
+ export declare const CURRENT_PACKAGE_VERSION = "0.0.1";
@@ -0,0 +1,27 @@
1
+ // THIS FILE IS GENERATED - DO NOT MODIFY
2
+ /**
3
+ * Autogenerated by current cli tool
4
+ */
5
+ export const BUILD_FRAMEWORK_CLI_NAME = 'tnp';
6
+ /**
7
+ * This value can be change in taon.jsonc (appId)
8
+ */
9
+ export const APP_ID = 'com.domain.example.i18n';
10
+ /**
11
+ * Autogenerated by current cli tool
12
+ */
13
+ export const BUILD_BASE_HREF = '';
14
+ /**
15
+ * This value can be change in taon.jsonc (overrideNpmName)
16
+ */
17
+ export const PROJECT_NPM_NAME = '@taon-dev/i18n';
18
+ /**
19
+ * Taon version from you project taon.json
20
+ */
21
+ export const CURRENT_PACKAGE_TAON_VERSION = 'v21';
22
+ /**
23
+ * Autogenerated by current cli tool. Use *tnp release* to bump version.
24
+ */
25
+ export const CURRENT_PACKAGE_VERSION = '0.0.1';
26
+ // THIS FILE IS GENERATED - DO NOT MODIFY
27
+ //# sourceMappingURL=build-info._auto-generated_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-info._auto-generated_.js","sourceRoot":"","sources":[""],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAC9C;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,yBAAyB,CAAC;AAChD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC;AACjD;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAClD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAM/C,yCAAyC"}
@@ -0,0 +1,67 @@
1
+ export declare const ENV_ANGULAR_NODE_APP_LOADING_PRE_ANGULAR_BOOTSTRAP_BACKGROUND = "#fdebed";
2
+ export declare const ENV_ANGULAR_NODE_APP_LOADING_PRE_ANGULAR_BOOTSTRAP_LOADER_NAME = "lds-default";
3
+ export declare const ENV_ANGULAR_NODE_APP_WEBSITE_DOMAIN = "i18n.example.domain.com";
4
+ export declare const ENV_ANGULAR_NODE_APP_WEBSITE_TITLE = "I 18 N";
5
+ export declare const ENV_ANGULAR_NODE_APP_WEBSITE_USE_DOMAIN = true;
6
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_TARGET_ARTIFACT = "angular-node-app";
7
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_ENV_NAME = "__";
8
+ export declare const ENV_ANGULAR_NODE_APP_CONTAINER_ONLY: any;
9
+ export declare const ENV_ANGULAR_NODE_APP_CONTAINER_END: any;
10
+ export declare const ENV_ANGULAR_NODE_APP_CONTAINER_START: any;
11
+ export declare const ENV_ANGULAR_NODE_APP_CONTAINER_SKIP_RELEASED: any;
12
+ export declare const ENV_ANGULAR_NODE_APP_CONTAINER_SKIP: any;
13
+ export declare const ENV_ANGULAR_NODE_APP_INIT_BRANDING: any;
14
+ export declare const ENV_ANGULAR_NODE_APP_INIT_STRUCT: any;
15
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_PWA_DISABLE_SERVICE_WORKER: any;
16
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_PWA_NAME: any;
17
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_PWA_SHORT_NAME: any;
18
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_PWA_START_URL: any;
19
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_ELECTRON_SHOW_DEV_TOOLS: any;
20
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_SSR: any;
21
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_WEBSQL: any;
22
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_PROD: any;
23
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_OVERRIDE_OUTPUT_PATH: any;
24
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_BASE_HREF: any;
25
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_WATCH: any;
26
+ export declare const ENV_ANGULAR_NODE_APP_BUILD_GEN_ONLY_CLIENT_CODE: any;
27
+ export declare const ENV_ANGULAR_NODE_APP_LOADING_PRE_ANGULAR_BOOTSTRAP_LOADER: any;
28
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_CLI_MINIFY: any;
29
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_CLI_INCLUDE_NODE_MODULES: any;
30
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_CLI_UGLIFY: any;
31
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_CLI_OBSCURE: any;
32
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_CLI_COMPRESS: any;
33
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_NODE_BACKEND_APP_MINIFY: any;
34
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_REMOVE_DTS: any;
35
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_OBSCURE_FILE_BY_FILE: any;
36
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_UGLIFY_FILE_BY_FILE: any;
37
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_INCLUDE_SOURCE_MAPS: any;
38
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_COMPRESS: any;
39
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_LIB_DO_NOT_INCLUDE_LIB_FILES: any;
40
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_RESOLVED_NEW_VERSION: any;
41
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_RELEASE_VERSION_BUMP_TYPE: any;
42
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_ENV_NUMBER: any;
43
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_INSTALL_LOCALLY: any;
44
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_REMOVE_RELEASE_OUTPUT_AFTER_LOCAL_INSTALL: any;
45
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_RELEASE_TYPE: any;
46
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_AUTO_RELEASE_USING_CONFIG: any;
47
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_AUTO_RELEASE_TASK_NAME: any;
48
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_TAON_INSTANCE_IP: any;
49
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_NPM_PUBLISH: any;
50
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_DEPLOY: any;
51
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_TAG_GIT_PUSH: any;
52
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_RELEASE_QUESTION: any;
53
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_RESOLVING_GIT_CHANGES: any;
54
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_CODE_CUTTING: any;
55
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_SKIP_BUILDING_ARTIFACTS: any;
56
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_PUSH_TO_ALL_ORIGINS_WHEN_LOCAL_RELEASE_BRANCH: any;
57
+ export declare const ENV_ANGULAR_NODE_APP_RELEASE_USE_LOCAL_RELEASE_BRANCH: any;
58
+ export declare const ENV_ANGULAR_NODE_APP_COPY_TO_MANAGER_BEFORE_COPY_HOOK: any;
59
+ export declare const ENV_ANGULAR_NODE_APP_COPY_TO_MANAGER_COPY_TO_LOCATIONS: any;
60
+ export declare const ENV_ANGULAR_NODE_APP_COPY_TO_MANAGER_COPY_TO_PROJECTS: any;
61
+ export declare const ENV_ANGULAR_NODE_APP_COPY_TO_MANAGER_SKIP: any;
62
+ export declare const ENV_ANGULAR_NODE_APP_PURPOSE: any;
63
+ export declare const ENV_ANGULAR_NODE_APP_RECURSIVE_ACTION: any;
64
+ export declare const ENV_ANGULAR_NODE_APP_IS_CI_PROCESS: any;
65
+ export declare const ENV_ANGULAR_NODE_APP_DOCKER_ADDITIONAL_CONTAINER: any;
66
+ export declare const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_START_IN_ORDER: any;
67
+ export declare const ENV_ANGULAR_NODE_APP_DOCKER_SKIP_USING_MYSQL_DB: any;