@koine/i18n 2.0.0-beta.76 → 2.0.0-beta.78

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 (260) hide show
  1. package/README.md +1 -0
  2. package/api.cjs.js +2203 -0
  3. package/api.esm.js +2179 -0
  4. package/compiler-sync.cjs.d.ts +1 -0
  5. package/compiler-sync.cjs.default.js +1 -0
  6. package/compiler-sync.cjs.js +20 -0
  7. package/compiler-sync.cjs.mjs +2 -0
  8. package/compiler-sync.esm.js +16 -0
  9. package/compiler-worker.cjs.d.ts +1 -0
  10. package/compiler-worker.cjs.default.js +1 -0
  11. package/compiler-worker.cjs.js +18 -0
  12. package/compiler-worker.cjs.mjs +2 -0
  13. package/compiler-worker.esm.js +16 -0
  14. package/compiler.cjs.d.ts +1 -0
  15. package/compiler.cjs.default.js +1 -0
  16. package/compiler.cjs.js +21 -0
  17. package/compiler.cjs.mjs +2 -0
  18. package/compiler.esm.js +13 -0
  19. package/formatRoutePathname.cjs.js +12 -0
  20. package/formatRoutePathname.esm.js +10 -0
  21. package/index.cjs.d.ts +1 -0
  22. package/index.cjs.default.js +1 -0
  23. package/index.cjs.js +47 -0
  24. package/index.cjs.mjs +2 -0
  25. package/index.esm.js +42 -0
  26. package/next.cjs.d.ts +1 -0
  27. package/next.cjs.default.js +1 -0
  28. package/next.cjs.js +377 -0
  29. package/next.cjs.mjs +2 -0
  30. package/next.esm.js +353 -0
  31. package/package.json +22 -305
  32. package/actions/helpers-git.js +0 -45
  33. package/actions/helpers-i18n.js +0 -27
  34. package/actions/i18n.js +0 -17
  35. package/adapter-js/code/config.cjs.js +0 -14
  36. package/adapter-js/code/config.js +0 -14
  37. package/adapter-js/code/defaultLocale.js +0 -7
  38. package/adapter-js/code/deriveLocalisedPathnames.js +0 -78
  39. package/adapter-js/code/index.js +0 -123
  40. package/adapter-js/code/isLocale.js +0 -9
  41. package/adapter-js/code/locales.js +0 -8
  42. package/adapter-js/code/pathnameToRouteId.js +0 -20
  43. package/adapter-js/code/routes.js +0 -11
  44. package/adapter-js/code/routesSlim.js +0 -11
  45. package/adapter-js/code/routesSpa.js +0 -11
  46. package/adapter-js/code/tFns.js +0 -34
  47. package/adapter-js/code/tInterpolateParams.js +0 -18
  48. package/adapter-js/code/tPluralise.js +0 -10
  49. package/adapter-js/code/to.js +0 -32
  50. package/adapter-js/code/toFns.js +0 -25
  51. package/adapter-js/code/toFormat.js +0 -56
  52. package/adapter-js/code/toSpa.js +0 -42
  53. package/adapter-js/code/types.js +0 -327
  54. package/adapter-next/code/index.js +0 -54
  55. package/adapter-next/code/next-redirects.js +0 -5
  56. package/adapter-next/code/next-rewrites.js +0 -5
  57. package/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
  58. package/adapter-next/code/useLocale.js +0 -8
  59. package/adapter-next/code/useRouteId.js +0 -10
  60. package/adapter-next/code/useTo.js +0 -26
  61. package/adapter-next/code/useToSpa.js +0 -34
  62. package/adapter-next/plugin-async.js +0 -11
  63. package/adapter-next/plugin-legacy.js +0 -187
  64. package/adapter-next/plugin-shared.js +0 -39
  65. package/adapter-next/plugin.js +0 -13
  66. package/adapter-next/redirects.js +0 -51
  67. package/adapter-next/rewrites.js +0 -50
  68. package/adapter-next/transformPathname.js +0 -3
  69. package/adapter-next/webpackPluginI18n.js +0 -11
  70. package/adapter-next-translate/code/DynamicNamespaces.js +0 -9
  71. package/adapter-next-translate/code/T.js +0 -31
  72. package/adapter-next-translate/code/TransText.js +0 -9
  73. package/adapter-next-translate/code/getT.js +0 -15
  74. package/adapter-next-translate/code/index.js +0 -49
  75. package/adapter-next-translate/code/nextTranslateI18n.js +0 -19
  76. package/adapter-next-translate/code/useT.js +0 -43
  77. package/cjs/adapter-js/code/config.cjs.d.ts +0 -3
  78. package/cjs/adapter-js/code/config.d.ts +0 -3
  79. package/cjs/adapter-js/code/defaultLocale.d.ts +0 -3
  80. package/cjs/adapter-js/code/deriveLocalisedPathnames.d.ts +0 -2
  81. package/cjs/adapter-js/code/index.d.ts +0 -3
  82. package/cjs/adapter-js/code/isLocale.d.ts +0 -2
  83. package/cjs/adapter-js/code/locales.d.ts +0 -3
  84. package/cjs/adapter-js/code/pathnameToRouteId.d.ts +0 -3
  85. package/cjs/adapter-js/code/routes.d.ts +0 -3
  86. package/cjs/adapter-js/code/routesSlim.d.ts +0 -3
  87. package/cjs/adapter-js/code/routesSpa.d.ts +0 -3
  88. package/cjs/adapter-js/code/tFns.d.ts +0 -3
  89. package/cjs/adapter-js/code/tInterpolateParams.d.ts +0 -3
  90. package/cjs/adapter-js/code/tPluralise.d.ts +0 -2
  91. package/cjs/adapter-js/code/to.d.ts +0 -3
  92. package/cjs/adapter-js/code/toFns.d.ts +0 -3
  93. package/cjs/adapter-js/code/toFormat.d.ts +0 -3
  94. package/cjs/adapter-js/code/toSpa.d.ts +0 -3
  95. package/cjs/adapter-js/code/types.d.ts +0 -3
  96. package/cjs/adapter-next/code/index.d.ts +0 -3
  97. package/cjs/adapter-next/code/next-redirects.d.ts +0 -3
  98. package/cjs/adapter-next/code/next-rewrites.d.ts +0 -3
  99. package/cjs/adapter-next/code/useCurrentLocalisedPathnames.d.ts +0 -2
  100. package/cjs/adapter-next/code/useLocale.d.ts +0 -3
  101. package/cjs/adapter-next/code/useRouteId.d.ts +0 -2
  102. package/cjs/adapter-next/code/useTo.d.ts +0 -2
  103. package/cjs/adapter-next/code/useToSpa.d.ts +0 -2
  104. package/cjs/adapter-next/plugin-async.d.ts +0 -9
  105. package/cjs/adapter-next/plugin-legacy.d.ts +0 -22
  106. package/cjs/adapter-next/plugin-shared.d.ts +0 -13
  107. package/cjs/adapter-next/plugin.d.ts +0 -7
  108. package/cjs/adapter-next/redirects.d.ts +0 -4
  109. package/cjs/adapter-next/rewrites.d.ts +0 -4
  110. package/cjs/adapter-next/transformPathname.d.ts +0 -1
  111. package/cjs/adapter-next/webpackPluginI18n.d.ts +0 -7
  112. package/cjs/adapter-next-translate/code/DynamicNamespaces.d.ts +0 -2
  113. package/cjs/adapter-next-translate/code/T.d.ts +0 -2
  114. package/cjs/adapter-next-translate/code/TransText.d.ts +0 -2
  115. package/cjs/adapter-next-translate/code/getT.d.ts +0 -2
  116. package/cjs/adapter-next-translate/code/index.d.ts +0 -3
  117. package/cjs/adapter-next-translate/code/nextTranslateI18n.d.ts +0 -3
  118. package/cjs/adapter-next-translate/code/useT.d.ts +0 -2
  119. package/cjs/client/formatRoutePathname.d.ts +0 -4
  120. package/cjs/client/index.d.ts +0 -3
  121. package/cjs/client/interpolateTo.d.ts +0 -4
  122. package/cjs/client/routeHasDynamicPortion.d.ts +0 -2
  123. package/cjs/compiler/api.d.ts +0 -30
  124. package/cjs/compiler/code/data-routes.d.ts +0 -19
  125. package/cjs/compiler/code/data-translations.d.ts +0 -13
  126. package/cjs/compiler/code/data.d.ts +0 -33
  127. package/cjs/compiler/code/generate.d.ts +0 -14
  128. package/cjs/compiler/code/index.d.ts +0 -3
  129. package/cjs/compiler/code/tsCompile.d.ts +0 -2
  130. package/cjs/compiler/code/write.d.ts +0 -11
  131. package/cjs/compiler/config.d.ts +0 -12
  132. package/cjs/compiler/helpers.d.ts +0 -2
  133. package/cjs/compiler/input/data-local.d.ts +0 -4
  134. package/cjs/compiler/input/data-remote.d.ts +0 -7
  135. package/cjs/compiler/input/data.d.ts +0 -4
  136. package/cjs/compiler/input/index.d.ts +0 -4
  137. package/cjs/compiler/input/types.d.ts +0 -14
  138. package/cjs/compiler/input/write.d.ts +0 -8
  139. package/cjs/compiler/pluralisation.d.ts +0 -37
  140. package/cjs/compiler/summary/data.d.ts +0 -6
  141. package/cjs/compiler/summary/generate.d.ts +0 -4
  142. package/cjs/compiler/summary/index.d.ts +0 -3
  143. package/cjs/compiler/summary/write.d.ts +0 -10
  144. package/cjs/compiler/types.d.ts +0 -82
  145. package/cjs/compiler-sync.d.ts +0 -4
  146. package/cjs/compiler-worker.d.ts +0 -1
  147. package/cjs/compiler.d.ts +0 -2
  148. package/cjs/i18n/actions/helpers-git.js +0 -45
  149. package/cjs/i18n/actions/helpers-i18n.js +0 -27
  150. package/cjs/i18n/actions/i18n.js +0 -17
  151. package/cjs/i18n/adapter-js/code/config.cjs.js +0 -14
  152. package/cjs/i18n/adapter-js/code/config.js +0 -14
  153. package/cjs/i18n/adapter-js/code/defaultLocale.js +0 -7
  154. package/cjs/i18n/adapter-js/code/deriveLocalisedPathnames.js +0 -78
  155. package/cjs/i18n/adapter-js/code/index.js +0 -123
  156. package/cjs/i18n/adapter-js/code/isLocale.js +0 -9
  157. package/cjs/i18n/adapter-js/code/locales.js +0 -8
  158. package/cjs/i18n/adapter-js/code/pathnameToRouteId.js +0 -20
  159. package/cjs/i18n/adapter-js/code/routes.js +0 -11
  160. package/cjs/i18n/adapter-js/code/routesSlim.js +0 -11
  161. package/cjs/i18n/adapter-js/code/routesSpa.js +0 -11
  162. package/cjs/i18n/adapter-js/code/tFns.js +0 -34
  163. package/cjs/i18n/adapter-js/code/tInterpolateParams.js +0 -18
  164. package/cjs/i18n/adapter-js/code/tPluralise.js +0 -10
  165. package/cjs/i18n/adapter-js/code/to.js +0 -32
  166. package/cjs/i18n/adapter-js/code/toFns.js +0 -25
  167. package/cjs/i18n/adapter-js/code/toFormat.js +0 -56
  168. package/cjs/i18n/adapter-js/code/toSpa.js +0 -42
  169. package/cjs/i18n/adapter-js/code/types.js +0 -327
  170. package/cjs/i18n/adapter-next/code/index.js +0 -54
  171. package/cjs/i18n/adapter-next/code/next-redirects.js +0 -5
  172. package/cjs/i18n/adapter-next/code/next-rewrites.js +0 -5
  173. package/cjs/i18n/adapter-next/code/useCurrentLocalisedPathnames.js +0 -20
  174. package/cjs/i18n/adapter-next/code/useLocale.js +0 -8
  175. package/cjs/i18n/adapter-next/code/useRouteId.js +0 -10
  176. package/cjs/i18n/adapter-next/code/useTo.js +0 -26
  177. package/cjs/i18n/adapter-next/code/useToSpa.js +0 -34
  178. package/cjs/i18n/adapter-next/plugin-async.js +0 -11
  179. package/cjs/i18n/adapter-next/plugin-legacy.js +0 -187
  180. package/cjs/i18n/adapter-next/plugin-shared.js +0 -39
  181. package/cjs/i18n/adapter-next/plugin.js +0 -13
  182. package/cjs/i18n/adapter-next/redirects.js +0 -51
  183. package/cjs/i18n/adapter-next/rewrites.js +0 -50
  184. package/cjs/i18n/adapter-next/transformPathname.js +0 -3
  185. package/cjs/i18n/adapter-next/webpackPluginI18n.js +0 -11
  186. package/cjs/i18n/adapter-next-translate/code/DynamicNamespaces.js +0 -9
  187. package/cjs/i18n/adapter-next-translate/code/T.js +0 -31
  188. package/cjs/i18n/adapter-next-translate/code/TransText.js +0 -9
  189. package/cjs/i18n/adapter-next-translate/code/getT.js +0 -15
  190. package/cjs/i18n/adapter-next-translate/code/index.js +0 -49
  191. package/cjs/i18n/adapter-next-translate/code/nextTranslateI18n.js +0 -19
  192. package/cjs/i18n/adapter-next-translate/code/useT.js +0 -43
  193. package/cjs/i18n/client/formatRoutePathname.js +0 -5
  194. package/cjs/i18n/client/index.js +0 -3
  195. package/cjs/i18n/client/interpolateTo.js +0 -14
  196. package/cjs/i18n/client/routeHasDynamicPortion.js +0 -2
  197. package/cjs/i18n/compiler/api.js +0 -18
  198. package/cjs/i18n/compiler/code/data-routes.js +0 -99
  199. package/cjs/i18n/compiler/code/data-translations.js +0 -86
  200. package/cjs/i18n/compiler/code/data.js +0 -20
  201. package/cjs/i18n/compiler/code/generate.js +0 -46
  202. package/cjs/i18n/compiler/code/index.js +0 -2
  203. package/cjs/i18n/compiler/code/tsCompile.js +0 -27
  204. package/cjs/i18n/compiler/code/write.js +0 -39
  205. package/cjs/i18n/compiler/config.js +0 -13
  206. package/cjs/i18n/compiler/helpers.js +0 -14
  207. package/cjs/i18n/compiler/input/data-local.js +0 -60
  208. package/cjs/i18n/compiler/input/data-remote.js +0 -41
  209. package/cjs/i18n/compiler/input/data.js +0 -11
  210. package/cjs/i18n/compiler/input/index.js +0 -3
  211. package/cjs/i18n/compiler/input/types.js +0 -1
  212. package/cjs/i18n/compiler/input/write.js +0 -15
  213. package/cjs/i18n/compiler/pluralisation.js +0 -59
  214. package/cjs/i18n/compiler/summary/data.js +0 -28
  215. package/cjs/i18n/compiler/summary/generate.js +0 -27
  216. package/cjs/i18n/compiler/summary/index.js +0 -2
  217. package/cjs/i18n/compiler/summary/write.js +0 -18
  218. package/cjs/i18n/compiler/types.js +0 -1
  219. package/cjs/i18n/compiler-sync.js +0 -2
  220. package/cjs/i18n/compiler-worker.js +0 -3
  221. package/cjs/i18n/compiler.js +0 -1
  222. package/cjs/i18n/index.js +0 -2
  223. package/cjs/i18n/next.js +0 -3
  224. package/cjs/i18n/types.js +0 -1
  225. package/cjs/index.d.ts +0 -2
  226. package/cjs/next.d.ts +0 -3
  227. package/cjs/package.json +0 -34
  228. package/cjs/types.d.ts +0 -48
  229. package/client/formatRoutePathname.js +0 -5
  230. package/client/index.js +0 -3
  231. package/client/interpolateTo.js +0 -14
  232. package/client/routeHasDynamicPortion.js +0 -2
  233. package/compiler/api.js +0 -18
  234. package/compiler/code/data-routes.js +0 -99
  235. package/compiler/code/data-translations.js +0 -86
  236. package/compiler/code/data.js +0 -20
  237. package/compiler/code/generate.js +0 -46
  238. package/compiler/code/index.js +0 -2
  239. package/compiler/code/tsCompile.js +0 -27
  240. package/compiler/code/write.js +0 -39
  241. package/compiler/config.js +0 -13
  242. package/compiler/helpers.js +0 -14
  243. package/compiler/input/data-local.js +0 -60
  244. package/compiler/input/data-remote.js +0 -41
  245. package/compiler/input/data.js +0 -11
  246. package/compiler/input/index.js +0 -3
  247. package/compiler/input/types.js +0 -1
  248. package/compiler/input/write.js +0 -15
  249. package/compiler/pluralisation.js +0 -59
  250. package/compiler/summary/data.js +0 -28
  251. package/compiler/summary/generate.js +0 -27
  252. package/compiler/summary/index.js +0 -2
  253. package/compiler/summary/write.js +0 -18
  254. package/compiler/types.js +0 -1
  255. package/compiler-sync.js +0 -2
  256. package/compiler-worker.js +0 -3
  257. package/compiler.js +0 -1
  258. package/index.js +0 -2
  259. package/next.js +0 -3
  260. package/types.js +0 -1
@@ -1,123 +0,0 @@
1
- import t from "./config";
2
- import e from "./config.cjs";
3
- import o from "./defaultLocale";
4
- import m from "./deriveLocalisedPathnames";
5
- import n from "./isLocale";
6
- import r from "./locales";
7
- import a from "./pathnameToRouteId";
8
- import s from "./routes";
9
- import f from "./routesSlim";
10
- import i from "./routesSpa";
11
- import x from "./tFns";
12
- import p from "./tInterpolateParams";
13
- import l from "./tPluralise";
14
- import d from "./to";
15
- import c from "./toFns";
16
- import u from "./toFormat";
17
- import F from "./toSpa";
18
- import L from "./types";
19
- export default (()=>({
20
- files: [
21
- {
22
- name: "config.cjs",
23
- fn: e,
24
- ext: "js"
25
- },
26
- {
27
- name: "config",
28
- fn: t,
29
- ext: "ts",
30
- index: !0
31
- },
32
- {
33
- name: "defaultLocale",
34
- fn: o,
35
- ext: "ts",
36
- index: !0
37
- },
38
- {
39
- name: "deriveLocalisedPathnames",
40
- fn: m,
41
- ext: "ts",
42
- index: !0
43
- },
44
- {
45
- name: "isLocale",
46
- fn: n,
47
- ext: "ts",
48
- index: !0
49
- },
50
- {
51
- name: "locales",
52
- fn: r,
53
- ext: "ts",
54
- index: !0
55
- },
56
- {
57
- name: "pathnameToRouteId",
58
- fn: a,
59
- ext: "ts",
60
- index: !0
61
- },
62
- {
63
- name: "routes",
64
- fn: s,
65
- ext: "ts"
66
- },
67
- {
68
- name: "routesSlim",
69
- fn: f,
70
- ext: "ts"
71
- },
72
- {
73
- name: "routesSpa",
74
- fn: i,
75
- ext: "ts"
76
- },
77
- {
78
- name: "tFns",
79
- fn: x,
80
- ext: "ts"
81
- },
82
- {
83
- name: "tInterpolateParams",
84
- fn: p,
85
- ext: "ts"
86
- },
87
- {
88
- name: "to",
89
- fn: d,
90
- ext: "ts",
91
- index: !0
92
- },
93
- {
94
- name: "toFns",
95
- fn: c,
96
- ext: "ts",
97
- index: !0
98
- },
99
- {
100
- name: "toFormat",
101
- fn: u,
102
- ext: "ts",
103
- index: !0
104
- },
105
- {
106
- name: "toSpa",
107
- fn: F,
108
- ext: "ts",
109
- index: !0
110
- },
111
- {
112
- name: "tPluralise",
113
- fn: l,
114
- ext: "ts"
115
- },
116
- {
117
- name: "types",
118
- fn: L,
119
- ext: "ts",
120
- index: !0
121
- }
122
- ]
123
- }));
@@ -1,9 +0,0 @@
1
- export default (()=>`
2
- import { locales } from "./locales";
3
- import type { I18n } from "./types";
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export const isLocale = (payload: any): payload is I18n.Locale => locales.includes(payload);
7
-
8
- export default isLocale;
9
- `);
@@ -1,8 +0,0 @@
1
- export default (({ config: e })=>{
2
- let l = `[${e.locales.map((e)=>`"${e}"`).join(", ")}]`;
3
- return `
4
- export const locales = ${l} as const;
5
-
6
- export default locales;
7
- `;
8
- });
@@ -1,20 +0,0 @@
1
- import { escapeRegExp as e } from "@koine/utils";
2
- export default (({ options: t })=>{
3
- let { idDelimiter: a, optionalCatchAll: r, catchAll: o } = t.routes.tokens;
4
- return `
5
- /**
6
- * Convert a URL like pathname to a "named route"
7
- * E.g. it transforms:
8
- * - \`/dashboard/user/[id]\` into \`dashboard.user.[id]\`
9
- */
10
- export const pathnameToRouteId = (pathname: string) =>
11
- pathname
12
- .replace(/^\\//g, "")
13
- .replace(/\\//g, "${a}")
14
- .replace(/${e(a)}${e(r.start)}.+$/, "")
15
- .replace(/${e(a)}${e(o.start)}.+$/, "")
16
- .replace(/\\/index$/, "");
17
-
18
- export default pathnameToRouteId;
19
- `;
20
- });
@@ -1,11 +0,0 @@
1
- export default (({ routes: t })=>{
2
- let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).map(([t, { pathnames: e }])=>[
3
- t,
4
- e
5
- ]).sort()), null, 2);
6
- return `
7
- export const routes = ${e} as const;
8
-
9
- export default routes;
10
- `;
11
- });
@@ -1,11 +0,0 @@
1
- export default (({ routes: t })=>{
2
- let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).map(([t, { pathnamesSlim: e, pathnames: r }])=>[
3
- t,
4
- e || r
5
- ]).sort()), null, 2);
6
- return `
7
- export const routesSlim = ${e} as const;
8
-
9
- export default routesSlim;
10
- `;
11
- });
@@ -1,11 +0,0 @@
1
- export default (({ routes: t })=>{
2
- let e = JSON.stringify(Object.fromEntries(Object.entries(t.byId).filter(([, { pathnamesSpa: t }])=>!!t).map(([t, { pathnamesSpa: e }])=>[
3
- t,
4
- e
5
- ]).sort()), null, 2);
6
- return `
7
- export const routesSpa = ${e} as const;
8
-
9
- export default routesSpa;
10
- `;
11
- });
@@ -1,34 +0,0 @@
1
- import { areEqual as t, isArray as e, isBoolean as r, isNumber as l, isPrimitive as o, isString as a } from "@koine/utils";
2
- import { dataParamsToTsInterfaceBody as n } from "../../compiler/helpers";
3
- let i = (t)=>a(t) || l(t) ? `"${t}"` : r(t) ? `${t}` : e(t) ? JSON.stringify(t) : `(${JSON.stringify(t)})`, s = (e, r)=>t(e, r), p = (t, e)=>{
4
- let { defaultLocale: r } = t, l = "";
5
- for(let t in e){
6
- let o = e[t];
7
- t === r || s(o, e[r]) || (l += `locale === "${t}" ? ${i(o)} : `);
8
- }
9
- return l + i(e[r]);
10
- };
11
- export default (({ config: t, options: e, translations: r })=>{
12
- let l = `
13
- /* eslint-disable @typescript-eslint/no-unused-vars */
14
- /* eslint-disable prefer-const */
15
- import type { I18n } from "./types";
16
- import { tInterpolateParams } from "./tInterpolateParams";
17
- import { tPluralise } from "./tPluralise";
18
-
19
- `;
20
- for(let a in r){
21
- let { values: s, params: m, plural: f } = r[a], u = `${e.translations.fnsPrefix}${a}`;
22
- f && (m ? m.count = "number" : m = {
23
- count: "number"
24
- });
25
- let $ = [
26
- m ? `params: { ${n(m)} }` : "",
27
- "locale?: I18n.Locale"
28
- ].filter(Boolean).join(", ");
29
- l += `export let ${u} = (${$}) => `;
30
- let c = "";
31
- o(s) ? c += i(s) : c += p(t, s), f && (c = `tPluralise(${c}, params.count)`), l += (c = m ? `tInterpolateParams(${c}, params);` : `${c};`) + `\n`;
32
- }
33
- return l;
34
- });
@@ -1,18 +0,0 @@
1
- let e = (e)=>e.split("").map((e)=>`\\${e}`).join("");
2
- export default (({ options: a })=>{
3
- let { start: t, end: r } = a.translations.dynamicDelimiters;
4
- return `
5
- /* eslint-disable prefer-const */
6
- export let tInterpolateParams = (
7
- value: string,
8
- params?: object,
9
- ) =>
10
- params ? value.replace(
11
- /${e(t)}(.*?)${e(r)}/g,
12
- (_, key) =>
13
- params[key.trim() as keyof typeof params] + "",
14
- ) : value;
15
-
16
- export default tInterpolateParams;
17
- `;
18
- });
@@ -1,10 +0,0 @@
1
- export default (()=>`
2
- /* eslint-disable prefer-const */
3
- let pluralRules = new Intl.PluralRules();
4
-
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
- export let tPluralise = (values: any, count: number) =>
7
- values[count] || values[pluralRules.select(count)] || (count === 0 ? values.zero : values["other"]);
8
-
9
- export default tPluralise;
10
- `);
@@ -1,32 +0,0 @@
1
- export default (({ config: o })=>`
2
- import { isLocale } from "./isLocale";
3
- import { toFormat } from "./toFormat";
4
- import { routesSlim } from "./routesSlim";
5
- import type { I18n } from "./types";
6
-
7
- /**
8
- * *To* route utility
9
- *
10
- * @returns A localised relative URL based on your i18nCompiler configuration
11
- */
12
- export function to<Id extends I18n.RouteId>(
13
- id: Id,
14
- ...args: Id extends I18n.RouteIdDynamic
15
- ?
16
- | [I18n.RouteParams[Id]]
17
- | [I18n.RouteParams[Id], I18n.Locale]
18
- : [] | [I18n.Locale]
19
- ) {
20
- const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${o.defaultLocale}";
21
-
22
- return toFormat(
23
- locale,
24
- (routesSlim[id] as Record<string, string>)[locale] ??
25
- (routesSlim[id] as Record<string, string>)["${o.defaultLocale}"] ??
26
- routesSlim[id],
27
- isLocale(args[0]) ? undefined : args[0]
28
- ) as I18n.RoutePathnames[Id];
29
- }
30
-
31
- export default to;
32
- `);
@@ -1,25 +0,0 @@
1
- import { changeCaseSnake as t, isString as e } from "@koine/utils";
2
- let o = (t, e)=>{
3
- let { defaultLocale: o } = t, r = "";
4
- for(let t in e){
5
- let l = e[t];
6
- t !== o && l !== e[o] && (r += `locale === "${t}" ? "${l}" : `);
7
- }
8
- return r + ('"' + e[o]) + '"';
9
- };
10
- export default (({ config: r, routes: l, options: a })=>{
11
- let n = 1 === r.locales.length, $ = `
12
- /* eslint-disable prefer-const */
13
- import { toFormat } from "./toFormat";
14
- import type { I18n } from "./types";
15
-
16
- `;
17
- for(let m in l.byId){
18
- let { pathnames: i, params: s } = l.byId[m], f = `${a.routes.fnsPrefix}${t(m)}`, p = `I18n.RouteParams["${m}"]`, c = [
19
- s ? `params: ${p}` : "",
20
- n ? "" : "locale?: I18n.Locale"
21
- ].filter(Boolean).join(", "), u = n ? '""' : "locale", I = s ? ", params" : "";
22
- $ += `export let ${f} = (${c}) => `, e(i) ? $ += `toFormat(${u}, "${i}"${I});` : $ += `toFormat(${u}, ${o(r, i)}${I});`, $ += `\n`;
23
- }
24
- return $;
25
- });
@@ -1,56 +0,0 @@
1
- export default (({ config: a })=>`
2
- export function toFormat(
3
- locale: string | undefined,
4
- pathname: string,
5
- params?: object,
6
- ) {
7
- locale = locale || "${a.defaultLocale}";
8
- if (process.env["NODE_ENV"] === "development") {
9
- if (params) {
10
- pathname.replace(/\\[(.*?)\\]/g, (_, dynamicKey) => {
11
- const key = dynamicKey as Extract<keyof typeof params, string>;
12
-
13
- if (!(key in params)) {
14
- console.warn(
15
- "[@koine/i18n]::interpolateTo, using '" +
16
- pathname +
17
- "' without param '" +
18
- key +
19
- "'",
20
- { params }
21
- );
22
- }
23
-
24
- if (!["string", "number"].includes(typeof params[key])) {
25
- console.warn(
26
- "[@koine/i18n]::toFormat, using '" +
27
- pathname +
28
- "' with unserializable param '" +
29
- key +
30
- "' (type '" +
31
- Object.prototype.toString.call((params[key])).slice(8, -1) +
32
- "')",
33
- );
34
- }
35
- return "";
36
- });
37
- }
38
- }
39
-
40
- if (params) {
41
- pathname = pathname.replace(
42
- /\\[(.*?)\\]/g,
43
- (_, key) =>
44
- params[key as keyof typeof params] + "",
45
- )
46
- }
47
- ${a.hideDefaultLocaleInUrl ? `
48
- if (locale !== "${a.defaultLocale}") {
49
- return "/" + locale + pathname;
50
- }
51
- ` : ""}
52
- return pathname;
53
- }
54
-
55
- export default toFormat;
56
- `);
@@ -1,42 +0,0 @@
1
- export default (({ config: o, options: t })=>{
2
- let { idDelimiter: e } = t.routes.tokens;
3
- return `
4
- import { isLocale } from "./isLocale";
5
- import { routesSpa } from "./routesSpa";
6
- import { toFormat } from "./toFormat";
7
- import type { I18n } from "./types";
8
-
9
- /**
10
- * *To spa* route utility
11
- *
12
- * @returns A localised relative URL based on your i18nCompiler configuration
13
- */
14
- export function toSpa<
15
- Root extends keyof I18n.RouteSpa,
16
- Path extends Extract<keyof I18n.RouteSpa[Root], string>,
17
- >(
18
- rootId: Root,
19
- pathId: Path,
20
- ...args: I18n.RouteJoinedId<Root, Path> extends I18n.RouteIdDynamic
21
- ?
22
- | [I18n.RouteParams[I18n.RouteJoinedId<Root, Path>]]
23
- | [I18n.RouteParams[I18n.RouteJoinedId<Root, Path>], I18n.Locale]
24
- : [] | [I18n.Locale]
25
- ) {
26
- const locale = (isLocale(args[0]) ? args[0] : args[1]) || "${o.defaultLocale}";
27
- const fullId = \`\${rootId}${e}\${pathId}\` as I18n.RouteJoinedId<Root, Path>;
28
- return toFormat(
29
- // FIXME: actually the locale will be prepended if hideDefaultLocaleInUrl will be false
30
- "", // do not pass the locale so that won't be prepended
31
- (routesSpa[fullId] as Record<string, string>)[locale],
32
- args.length === 2
33
- ? args[0]
34
- : args[0] && !isLocale(args[0])
35
- ? args[0]
36
- : void 0,
37
- ) as I18n.RouteSpa[Root][Path];
38
- }
39
-
40
- export default toSpa;
41
- `;
42
- });