@koine/i18n 2.0.0-beta.29 → 2.0.0-beta.31

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.
@@ -0,0 +1,28 @@
1
+ import type { I18nIndexedFile } from "./types.js";
2
+ export type I18nGenerateSummaryConfig = {
3
+ defaultLocale: string;
4
+ sourceUrl: string;
5
+ };
6
+ type Locale = string & {
7
+ branded: true;
8
+ };
9
+ type I18nGenerateSummaryOptions = I18nGenerateSummaryConfig & {
10
+ files: I18nIndexedFile[];
11
+ };
12
+ type I18nSummary = Record<Locale, {
13
+ words: number;
14
+ characters: number;
15
+ files: I18nSummaryFile[];
16
+ }>;
17
+ type I18nSummaryFile = {
18
+ locale: Locale;
19
+ path: string;
20
+ url: string;
21
+ words: number;
22
+ characters: number;
23
+ };
24
+ export declare function generateSummary(options: I18nGenerateSummaryOptions): Promise<{
25
+ data: I18nSummary;
26
+ md: string;
27
+ }>;
28
+ export {};
@@ -0,0 +1,137 @@
1
+ import { __awaiter, __generator, __read } from "tslib";
2
+ import { arraySum, forin } from "@koine/utils";
3
+ function getWords(value, options) {
4
+ if (options === void 0) { options = {}; }
5
+ var out = "";
6
+ if (value && typeof value === "string") {
7
+ out += " " + value.trim();
8
+ }
9
+ else if (Array.isArray(value)) {
10
+ for (var i = 0; i < value.length; i++) {
11
+ out += getWords(value[i], options);
12
+ }
13
+ }
14
+ else if (typeof value === "object") {
15
+ for (var _key in value) {
16
+ var key = _key;
17
+ var single = value[key];
18
+ out += getWords(single, options);
19
+ }
20
+ }
21
+ return out;
22
+ }
23
+ function getSummaryDataEntry(options, file) {
24
+ var locale = file.locale, path = file.path;
25
+ var url = "".concat(options.sourceUrl, "/").concat(locale, "/").concat(path);
26
+ var words = getWords(file.data);
27
+ var wordsCount = words.split(" ").filter(Boolean).length;
28
+ var characters = words.split(" ").filter(Boolean).join("").length;
29
+ return {
30
+ characters: characters,
31
+ locale: locale,
32
+ path: path,
33
+ url: url,
34
+ words: wordsCount,
35
+ };
36
+ }
37
+ function getSummaryData(options) {
38
+ var files = options.files, defaultLocale = options.defaultLocale;
39
+ var data = {};
40
+ for (var i = 0; i < files.length; i++) {
41
+ var file = files[i];
42
+ var locale = file.locale;
43
+ var entry = getSummaryDataEntry(options, file);
44
+ data[locale] = data[locale] || {};
45
+ data[locale].files = data[locale].files || [];
46
+ data[locale].files.push(entry);
47
+ }
48
+ data = Object.fromEntries(Object.entries(data).sort(function (_a, _b) {
49
+ var _c = __read(_a, 1), a = _c[0];
50
+ var _d = __read(_b, 1), b = _d[0];
51
+ return a === defaultLocale ? -1 : a.localeCompare(b);
52
+ }));
53
+ forin(data, function (locale, dataPerLocale) {
54
+ data[locale].characters = arraySum(dataPerLocale.files.map(function (f) { return f.characters; }));
55
+ data[locale].files = data[locale].files.sort(function (a, b) {
56
+ return a.path.localeCompare(b.path);
57
+ });
58
+ data[locale].words = arraySum(dataPerLocale.files.map(function (f) { return f.words; }));
59
+ data[locale] = Object.fromEntries(Object.entries(data[locale]).sort());
60
+ });
61
+ return data;
62
+ }
63
+ function getSummaryDataByPath(data) {
64
+ var out = {};
65
+ forin(data, function (locale, dataPerLocale) {
66
+ var files = dataPerLocale.files;
67
+ for (var i = 0; i < files.length; i++) {
68
+ var file = files[i];
69
+ var path = file.path;
70
+ out[path] = out[path] || {};
71
+ out[path][locale] = file;
72
+ }
73
+ });
74
+ out = Object.fromEntries(Object.entries(out).sort());
75
+ return out;
76
+ }
77
+ function generateSummaryMarkdownByPath(_options, data) {
78
+ var dataByPath = getSummaryDataByPath(data);
79
+ var output = "";
80
+ var body = "";
81
+ var locales = [];
82
+ var styleBorder = "style=\"border-right:1px solid grey\"";
83
+ forin(dataByPath, function (path, dataPerPath) {
84
+ body += "<tr>";
85
+ body += "<td ".concat(styleBorder, ">").concat(path, "</td>");
86
+ forin(dataPerPath, function (locale, file) {
87
+ var characters = file.characters, words = file.words, url = file.url;
88
+ if (!locales.includes(locale))
89
+ locales.push(locale);
90
+ body += "<td><a href=\"".concat(url, "\">").concat(locale, "</a></td>");
91
+ body += "<td>".concat(words, "</td>");
92
+ body += "<td ".concat(styleBorder, ">").concat(characters, "</td>");
93
+ });
94
+ body += "</tr>";
95
+ });
96
+ output += "<table><thead><tr>";
97
+ output += "<th ".concat(styleBorder, ">file path</th>");
98
+ output += locales.map(function () { return "<th>lang</th><th>words</th><th ".concat(styleBorder, ">chars</th>"); }).join("");
99
+ output += "</tr></thead><tbody>".concat(body, "</tbody></table>\n");
100
+ return output;
101
+ }
102
+ function generateSummaryMarkdownByLocale(options, data) {
103
+ var output = "";
104
+ var body = "";
105
+ forin(data, function (locale, dataPerLocale) {
106
+ var files = dataPerLocale.files, characters = dataPerLocale.characters, words = dataPerLocale.words;
107
+ var url = "".concat(options.sourceUrl, "/").concat(locale);
108
+ body += "<tr>";
109
+ body += "<th><a href=\"".concat(url, "\">").concat(locale, "</a></th>");
110
+ body += "<td>".concat(files.length, "</td>");
111
+ body += "<td>".concat(words, "</td>");
112
+ body += "<td>".concat(characters, "</td>");
113
+ body += "</tr>";
114
+ });
115
+ output += "<table><thead><tr>";
116
+ output += "<th>locale</th><th>files</th><th>words</th><th>chars</th>";
117
+ output += "</tr></thead><tbody>".concat(body, "</tbody></table>\n");
118
+ return output;
119
+ }
120
+ function generateSummaryMarkdown(options, data) {
121
+ var output = "# Summary\n";
122
+ output += "\n### By locale\n\n";
123
+ output += generateSummaryMarkdownByLocale(options, data);
124
+ output += "\n### By file path\n\n";
125
+ output += generateSummaryMarkdownByPath(options, data);
126
+ return output;
127
+ }
128
+ export function generateSummary(options) {
129
+ return __awaiter(this, void 0, void 0, function () {
130
+ var data, md;
131
+ return __generator(this, function (_a) {
132
+ data = getSummaryData(options);
133
+ md = generateSummaryMarkdown(options, data);
134
+ return [2, { data: data, md: md }];
135
+ });
136
+ });
137
+ }
@@ -0,0 +1,5 @@
1
+ import type { I18nIndexedFile } from "./types.js";
2
+ export declare function generateTypes(options: {
3
+ defaultLocale: string;
4
+ files: I18nIndexedFile[];
5
+ }): Promise<string>;
@@ -0,0 +1,133 @@
1
+ import { __awaiter, __generator, __read, __spreadArray } from "tslib";
2
+ import { forin, isNumericLiteral, objectPick, split } from "@koine/utils";
3
+ var pluralSuffixes = ["zero", "one", "two", "few", "many", "other"];
4
+ var requiredPluralSuffix = "other";
5
+ var isPluralSuffix = function (suffix) {
6
+ return (pluralSuffixes.includes(suffix) ||
7
+ isNumericLiteral(suffix));
8
+ };
9
+ var isPluralKey = function (key) {
10
+ var _a = __read(split(key, "_"), 2), suffix = _a[1];
11
+ return isPluralSuffix(suffix);
12
+ };
13
+ var groupPluralsKeysByRoot = function (pluralKeys) {
14
+ var map = {};
15
+ pluralKeys.forEach(function (key) {
16
+ var _a = __read(split(key, "_"), 1), root = _a[0];
17
+ map[root] = map[root] || [];
18
+ map[root].push(key);
19
+ });
20
+ return map;
21
+ };
22
+ var transformKeysForPlurals = function (keys) {
23
+ var pluralKeys = keys.filter(isPluralKey);
24
+ if (pluralKeys.length) {
25
+ var transformedKeys_1 = __spreadArray([], __read(keys), false);
26
+ var groupedPlurals = groupPluralsKeysByRoot(pluralKeys);
27
+ forin(groupedPlurals, function (pluralRoot, pluralKeys) {
28
+ if (!keys.includes(pluralRoot)) {
29
+ transformedKeys_1.push(pluralRoot);
30
+ }
31
+ pluralKeys.forEach(function (pluralKey) {
32
+ if (keys.includes(pluralKey)) {
33
+ transformedKeys_1 = transformedKeys_1.filter(function (k) { return k !== pluralKey; });
34
+ }
35
+ });
36
+ });
37
+ return transformedKeys_1;
38
+ }
39
+ return keys;
40
+ };
41
+ var analyseObjectPlurals = function (obj) {
42
+ var keys = Object.keys(obj);
43
+ var hasPlurals = keys.includes(requiredPluralSuffix);
44
+ var hasOnlyPluralKeys = false;
45
+ var newValue = obj;
46
+ if (hasPlurals) {
47
+ var nonPluralKeys = keys.filter(function (k) { return !isPluralSuffix(k); });
48
+ hasOnlyPluralKeys = nonPluralKeys.length === 0;
49
+ newValue = objectPick(obj, nonPluralKeys);
50
+ }
51
+ return {
52
+ hasPlurals: hasPlurals,
53
+ hasOnlyPluralKeys: hasOnlyPluralKeys,
54
+ newValue: newValue,
55
+ };
56
+ };
57
+ var getTypeForObjectEntry = function (key, value) {
58
+ if (typeof value === "object") {
59
+ var _a = analyseObjectPlurals(value), hasPlurals = _a.hasPlurals, hasOnlyPluralKeys = _a.hasOnlyPluralKeys, newValue = _a.newValue;
60
+ if (hasOnlyPluralKeys) {
61
+ return "'".concat(key, "': string;");
62
+ }
63
+ if (hasPlurals) {
64
+ return "'".concat(key, "': string | ").concat(getType(newValue));
65
+ }
66
+ }
67
+ return "'".concat(key, "': ").concat(getType(value));
68
+ };
69
+ function getType(value) {
70
+ var out = "";
71
+ var primitiveType = "";
72
+ if (typeof value === "boolean") {
73
+ primitiveType = "boolean";
74
+ }
75
+ else if (typeof value === "string") {
76
+ primitiveType = "string";
77
+ }
78
+ if (primitiveType) {
79
+ out += primitiveType + ";";
80
+ }
81
+ else if (!value) {
82
+ out += "";
83
+ }
84
+ else if (Array.isArray(value)) {
85
+ var firstValue = value[0];
86
+ out += "".concat(getType(firstValue), "[];");
87
+ }
88
+ else if (typeof value === "object") {
89
+ out += "{";
90
+ var keys = transformKeysForPlurals(Object.keys(value));
91
+ for (var i = 0; i < keys.length; i++) {
92
+ var key = keys[i];
93
+ var single = value[key] || "";
94
+ out += getTypeForObjectEntry(key, single);
95
+ }
96
+ out += "};";
97
+ }
98
+ out = out.replace(/;\[\];/g, "[];");
99
+ out = out.replace(/;+/g, ";");
100
+ return out;
101
+ }
102
+ export function generateTypes(options) {
103
+ return __awaiter(this, void 0, void 0, function () {
104
+ var defaultLocale, files, defaultLocaleFiles, header, footer, out, i, _a, path, data, namespace, format;
105
+ return __generator(this, function (_b) {
106
+ switch (_b.label) {
107
+ case 0:
108
+ defaultLocale = options.defaultLocale, files = options.files;
109
+ defaultLocaleFiles = files.filter(function (f) { return f.locale === defaultLocale; });
110
+ header = "\n/* eslint-disable @typescript-eslint/ban-types */\n/* eslint-disable @typescript-eslint/no-namespace */\n\ndeclare namespace Koine {\n interface Translations {\n";
111
+ footer = "\n }\n}\n";
112
+ out = header;
113
+ for (i = 0; i < defaultLocaleFiles.length; i++) {
114
+ _a = defaultLocaleFiles[i], path = _a.path, data = _a.data;
115
+ namespace = path.replace(".json", "");
116
+ out += "\"".concat(namespace, "\": ").concat(getType(data), "\n");
117
+ }
118
+ out += footer;
119
+ if (!!process.env["JEST_WORKER_ID"]) return [3, 3];
120
+ return [4, import("prettier")];
121
+ case 1:
122
+ format = (_b.sent()).format;
123
+ return [4, format(out, {
124
+ parser: "typescript",
125
+ })];
126
+ case 2:
127
+ out = _b.sent();
128
+ _b.label = 3;
129
+ case 3: return [2, out];
130
+ }
131
+ });
132
+ });
133
+ }
@@ -0,0 +1,10 @@
1
+ import type { I18nIndexedFile, I18nIndexedLocale } from "./types.js";
2
+ type I18nGetFsDataOutput = {
3
+ locales: I18nIndexedLocale[];
4
+ files: I18nIndexedFile[];
5
+ };
6
+ export declare function getFsData(options: {
7
+ cwd: string;
8
+ onlyFilesForLocales?: string[];
9
+ }): Promise<I18nGetFsDataOutput>;
10
+ export {};
@@ -0,0 +1,63 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { readFile } from "node:fs/promises";
3
+ import { join } from "node:path";
4
+ import { glob } from "glob";
5
+ import { getLocalesFolders } from "./getLocalesFolders.js";
6
+ export function getFsData(options) {
7
+ return __awaiter(this, void 0, void 0, function () {
8
+ var cwd, _a, onlyFilesForLocales, locales, dataOutput;
9
+ var _this = this;
10
+ return __generator(this, function (_b) {
11
+ switch (_b.label) {
12
+ case 0:
13
+ cwd = options.cwd, _a = options.onlyFilesForLocales, onlyFilesForLocales = _a === void 0 ? [] : _a;
14
+ return [4, getLocalesFolders({ cwd: cwd })];
15
+ case 1:
16
+ locales = _b.sent();
17
+ dataOutput = { locales: locales, files: [] };
18
+ if (onlyFilesForLocales.length) {
19
+ locales = locales.filter(function (l) { return onlyFilesForLocales.includes(l.code); });
20
+ }
21
+ return [4, Promise.all(locales.map(function (locale) { return __awaiter(_this, void 0, void 0, function () {
22
+ var jsonFiles;
23
+ var _this = this;
24
+ return __generator(this, function (_a) {
25
+ switch (_a.label) {
26
+ case 0: return [4, glob("**/*.json", {
27
+ cwd: locale.path,
28
+ })];
29
+ case 1:
30
+ jsonFiles = _a.sent();
31
+ return [4, Promise.all(jsonFiles.map(function (relativePath) { return __awaiter(_this, void 0, void 0, function () {
32
+ var fullPath, rawContent;
33
+ return __generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0:
36
+ fullPath = join(locale.path, relativePath);
37
+ return [4, readFile(fullPath, "utf8")];
38
+ case 1:
39
+ rawContent = _a.sent();
40
+ if (rawContent) {
41
+ dataOutput.files.push({
42
+ path: relativePath,
43
+ data: JSON.parse(rawContent),
44
+ locale: locale.code,
45
+ });
46
+ }
47
+ return [2];
48
+ }
49
+ });
50
+ }); }))];
51
+ case 2:
52
+ _a.sent();
53
+ return [2];
54
+ }
55
+ });
56
+ }); }))];
57
+ case 2:
58
+ _b.sent();
59
+ return [2, dataOutput];
60
+ }
61
+ });
62
+ });
63
+ }
@@ -0,0 +1,4 @@
1
+ import type { I18nIndexedLocale } from "./types.js";
2
+ export declare function getLocalesFolders(options: {
3
+ cwd: string;
4
+ }): Promise<I18nIndexedLocale[]>;
@@ -0,0 +1,29 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { join } from "node:path";
3
+ import { glob } from "glob";
4
+ var ignoredFolderNames = ["node_modules"];
5
+ export function getLocalesFolders(options) {
6
+ return __awaiter(this, void 0, void 0, function () {
7
+ var cwd, folders, output;
8
+ return __generator(this, function (_a) {
9
+ switch (_a.label) {
10
+ case 0:
11
+ cwd = options.cwd;
12
+ return [4, glob("*", {
13
+ cwd: cwd,
14
+ withFileTypes: true,
15
+ })];
16
+ case 1:
17
+ folders = (_a.sent())
18
+ .filter(function (folder) { return folder.isDirectory(); })
19
+ .map(function (path) { return path.relative(); })
20
+ .filter(function (path) { return !ignoredFolderNames.includes(path); });
21
+ output = folders.map(function (locale) { return ({
22
+ path: join(cwd, locale),
23
+ code: locale,
24
+ }); });
25
+ return [2, output];
26
+ }
27
+ });
28
+ });
29
+ }
@@ -0,0 +1,7 @@
1
+ export { generateSummary } from "./generateSummary.js";
2
+ export { generateTypes } from "./generateTypes.js";
3
+ export { getFsData } from "./getFsData.js";
4
+ export { getLocalesFolders } from "./getLocalesFolders.js";
5
+ export { writeTypes } from "./writeTypes.js";
6
+ export { writeSummary } from "./writeSummary.js";
7
+ export * from "./types.js";
@@ -0,0 +1,7 @@
1
+ export { generateSummary } from "./generateSummary.js";
2
+ export { generateTypes } from "./generateTypes.js";
3
+ export { getFsData } from "./getFsData.js";
4
+ export { getLocalesFolders } from "./getLocalesFolders.js";
5
+ export { writeTypes } from "./writeTypes.js";
6
+ export { writeSummary } from "./writeSummary.js";
7
+ export * from "./types.js";
@@ -0,0 +1,14 @@
1
+ export type I18nLocale = string & {
2
+ branded: true;
3
+ };
4
+ export type I18nIndexedFile = {
5
+ path: string;
6
+ locale: I18nLocale;
7
+ data: {
8
+ [key: string]: any;
9
+ };
10
+ };
11
+ export type I18nIndexedLocale = {
12
+ path: string;
13
+ code: I18nLocale;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import { type I18nGenerateSummaryConfig } from "./generateSummary.js";
2
+ export declare function writeSummary(options: {
3
+ cwd: string;
4
+ outputJson: string;
5
+ outputMarkdown: string;
6
+ } & I18nGenerateSummaryConfig): Promise<{
7
+ locales: import("./types").I18nIndexedLocale[];
8
+ files: import("./types").I18nIndexedFile[];
9
+ }>;
@@ -0,0 +1,35 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { join } from "node:path";
3
+ import { fsWrite } from "@koine/node";
4
+ import { generateSummary, } from "./generateSummary.js";
5
+ import { getFsData } from "./getFsData.js";
6
+ export function writeSummary(options) {
7
+ return __awaiter(this, void 0, void 0, function () {
8
+ var cwd, defaultLocale, outputJson, outputMarkdown, sourceUrl, data, summary;
9
+ return __generator(this, function (_a) {
10
+ switch (_a.label) {
11
+ case 0:
12
+ cwd = options.cwd, defaultLocale = options.defaultLocale, outputJson = options.outputJson, outputMarkdown = options.outputMarkdown, sourceUrl = options.sourceUrl;
13
+ return [4, getFsData({
14
+ cwd: cwd,
15
+ })];
16
+ case 1:
17
+ data = _a.sent();
18
+ return [4, generateSummary({
19
+ files: data.files,
20
+ defaultLocale: defaultLocale,
21
+ sourceUrl: sourceUrl,
22
+ })];
23
+ case 2:
24
+ summary = _a.sent();
25
+ return [4, fsWrite(join(cwd, outputJson), JSON.stringify(summary.data, null, 2))];
26
+ case 3:
27
+ _a.sent();
28
+ return [4, fsWrite(join(cwd, outputMarkdown), summary.md)];
29
+ case 4:
30
+ _a.sent();
31
+ return [2, data];
32
+ }
33
+ });
34
+ });
35
+ }
@@ -0,0 +1,8 @@
1
+ export declare function writeTypes(options: {
2
+ cwd: string;
3
+ defaultLocale: string;
4
+ outputTypes: string;
5
+ }): Promise<{
6
+ locales: import("./types").I18nIndexedLocale[];
7
+ files: import("./types").I18nIndexedFile[];
8
+ }>;
@@ -0,0 +1,29 @@
1
+ import { __awaiter, __generator } from "tslib";
2
+ import { join } from "node:path";
3
+ import { fsWrite } from "@koine/node";
4
+ import { generateTypes } from "./generateTypes.js";
5
+ import { getFsData } from "./getFsData.js";
6
+ export function writeTypes(options) {
7
+ return __awaiter(this, void 0, void 0, function () {
8
+ var cwd, defaultLocale, outputTypes, data, types;
9
+ return __generator(this, function (_a) {
10
+ switch (_a.label) {
11
+ case 0:
12
+ cwd = options.cwd, defaultLocale = options.defaultLocale, outputTypes = options.outputTypes;
13
+ return [4, getFsData({
14
+ cwd: cwd,
15
+ onlyFilesForLocales: [defaultLocale],
16
+ })];
17
+ case 1:
18
+ data = _a.sent();
19
+ return [4, generateTypes({ files: data.files, defaultLocale: defaultLocale })];
20
+ case 2:
21
+ types = _a.sent();
22
+ return [4, fsWrite(join(cwd, outputTypes), types)];
23
+ case 3:
24
+ _a.sent();
25
+ return [2, data];
26
+ }
27
+ });
28
+ });
29
+ }
@@ -66,6 +66,7 @@ function i18nSummaryGetDataByPath(data) {
66
66
  out[path][locale] = file;
67
67
  }
68
68
  });
69
+ out = Object.fromEntries(Object.entries(out).sort());
69
70
  return out;
70
71
  }
71
72
  function i18nGenerateSummaryMarkdownByPath(_options, data) {
package/index.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  export { createTo } from "./createTo.js";
2
- export { i18nGenerateSummary } from "./i18nGenerateSummary.js";
3
- export { i18nGenerateTypes } from "./i18nGenerateTypes.js";
4
- export { i18nGetFsData } from "./i18nGetFsData.js";
5
- export { i18nGetLocalesFolders } from "./i18nGetLocalesFolders.js";
6
- export { i18nWriteTypes } from "./i18nWriteTypes.js";
7
- export { i18nWriteSummary } from "./i18nWriteSummary.js";
2
+ export { isDynamicRouteId } from "./isDynamicRouteId.js";
3
+ export { isStaticRouteId } from "./isStaticRouteId.js";
4
+ export { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
8
5
  export * from "./types.js";
package/index.js CHANGED
@@ -1,8 +1,5 @@
1
1
  export { createTo } from "./createTo.js";
2
- export { i18nGenerateSummary } from "./i18nGenerateSummary.js";
3
- export { i18nGenerateTypes } from "./i18nGenerateTypes.js";
4
- export { i18nGetFsData } from "./i18nGetFsData.js";
5
- export { i18nGetLocalesFolders } from "./i18nGetLocalesFolders.js";
6
- export { i18nWriteTypes } from "./i18nWriteTypes.js";
7
- export { i18nWriteSummary } from "./i18nWriteSummary.js";
2
+ export { isDynamicRouteId } from "./isDynamicRouteId.js";
3
+ export { isStaticRouteId } from "./isStaticRouteId.js";
4
+ export { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
8
5
  export * from "./types.js";
@@ -0,0 +1,3 @@
1
+ import type { ToRoute, ToRouteDynamic } from "./types.js";
2
+ export declare function isDynamicRouteId(routeId: ToRoute): routeId is ToRouteDynamic;
3
+ export default isDynamicRouteId;
@@ -0,0 +1,5 @@
1
+ import { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
2
+ export function isDynamicRouteId(routeId) {
3
+ return routeHasDynamicPortion(routeId);
4
+ }
5
+ export default isDynamicRouteId;
@@ -0,0 +1,3 @@
1
+ import type { ToRoute, ToRouteStatic } from "./types.js";
2
+ export declare function isStaticRouteId(routeId: ToRoute): routeId is ToRouteStatic;
3
+ export default isStaticRouteId;
@@ -0,0 +1,5 @@
1
+ import { routeHasDynamicPortion } from "./routeHasDynamicPortion.js";
2
+ export function isStaticRouteId(routeId) {
3
+ return !routeHasDynamicPortion(routeId);
4
+ }
5
+ export default isStaticRouteId;
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@koine/i18n",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/node": "2.0.0-beta.29",
6
- "@koine/utils": "2.0.0-beta.29"
5
+ "@koine/node": "2.0.0-beta.31",
6
+ "@koine/utils": "2.0.0-beta.31"
7
7
  },
8
8
  "peerDependenciesMeta": {
9
9
  "prettier": {
@@ -22,6 +22,30 @@
22
22
  "./createTo": {
23
23
  "import": "./createTo.js"
24
24
  },
25
+ "./generate/generateSummary": {
26
+ "import": "./generate/generateSummary.js"
27
+ },
28
+ "./generate/generateTypes": {
29
+ "import": "./generate/generateTypes.js"
30
+ },
31
+ "./generate/getFsData": {
32
+ "import": "./generate/getFsData.js"
33
+ },
34
+ "./generate/getLocalesFolders": {
35
+ "import": "./generate/getLocalesFolders.js"
36
+ },
37
+ "./generate": {
38
+ "import": "./generate/index.js"
39
+ },
40
+ "./generate/types": {
41
+ "import": "./generate/types.js"
42
+ },
43
+ "./generate/writeSummary": {
44
+ "import": "./generate/writeSummary.js"
45
+ },
46
+ "./generate/writeTypes": {
47
+ "import": "./generate/writeTypes.js"
48
+ },
25
49
  "./i18nGenerateSummary": {
26
50
  "import": "./i18nGenerateSummary.js"
27
51
  },
@@ -40,6 +64,15 @@
40
64
  "./i18nWriteTypes": {
41
65
  "import": "./i18nWriteTypes.js"
42
66
  },
67
+ "./isDynamicRouteId": {
68
+ "import": "./isDynamicRouteId.js"
69
+ },
70
+ "./isStaticRouteId": {
71
+ "import": "./isStaticRouteId.js"
72
+ },
73
+ "./routeHasDynamicPortion": {
74
+ "import": "./routeHasDynamicPortion.js"
75
+ },
43
76
  "./types": {
44
77
  "import": "./types.js"
45
78
  }
@@ -48,5 +81,5 @@
48
81
  "prettier": "^3.1.1",
49
82
  "glob": "^10.3.10"
50
83
  },
51
- "version": "2.0.0-beta.29"
84
+ "version": "2.0.0-beta.31"
52
85
  }
@@ -0,0 +1,2 @@
1
+ export declare function routeHasDynamicPortion(routeIdOrPortion: string): boolean;
2
+ export default routeHasDynamicPortion;
@@ -0,0 +1,4 @@
1
+ export function routeHasDynamicPortion(routeIdOrPortion) {
2
+ return /\[/.test(routeIdOrPortion);
3
+ }
4
+ export default routeHasDynamicPortion;
package/types.d.ts CHANGED
@@ -1,18 +1,4 @@
1
1
  import type { Split } from "@koine/utils";
2
- export type I18nLocale = string & {
3
- branded: true;
4
- };
5
- export type I18nIndexedFile = {
6
- path: string;
7
- locale: I18nLocale;
8
- data: {
9
- [key: string]: any;
10
- };
11
- };
12
- export type I18nIndexedLocale = {
13
- path: string;
14
- code: I18nLocale;
15
- };
16
2
  type MergeDictionaries<T, K> = Omit<T, keyof K> & K;
17
3
  type Join<A, Sep extends string = "", R extends string = ""> = A extends [
18
4
  infer First,
@@ -60,9 +46,10 @@ export type TranslationOptions = undefined | TranslationShortcut | {
60
46
  default?: string;
61
47
  };
62
48
  export type Translate<TNamespace extends TranslateNamespace | undefined = TranslateNamespace> = TNamespace extends TranslateNamespace ? TranslateNamespaced<TNamespace> : TranslateDefault;
63
- export type TranslateDefault = <TPath extends TranslationsAllPaths>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TranslationAtPath<TPath>;
64
- export type TranslateNamespaced<TNamespace extends TranslateNamespace> = <TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TranslationAtPathFromNamespace<TNamespace, TPath>;
65
- export type TranslateLoose = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => string;
49
+ export type TranslateDefault = <TPath extends TranslationsAllPaths, TReturn = TranslationAtPath<TPath>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
50
+ export type TranslateNamespaced<TNamespace extends TranslateNamespace> = <TPath extends TranslationsPaths<TranslationsDictionary[TNamespace]>, TReturn = TranslationAtPathFromNamespace<TNamespace, TPath>>(s: TPath, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
51
+ export type TranslateLoose<TReturn = string> = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
52
+ export type TranslateLoosest<TReturn = any> = (s?: any, q?: TranslationQuery, o?: TranslationOptions) => TReturn;
66
53
  export type TranslatedRoute = TranslationsPaths<TranslationsDictionary["~"], false>;
67
54
  export type TranslatedRoutesChildrenOf<TStarts extends string, T extends string = TranslatedRoute> = T extends `${TStarts}.${infer First}.${infer Second}` ? First | `${First}.${Second}` : T extends `${TStarts}.${infer First}` ? First : never;
68
55
  type OnlyStatic<T extends string> = T extends `${string}.[${string}].${string}` | `${string}.[${string}]` | `[${string}].${string}` | `[${string}]` ? never : T;