@uxf/scripts 10.0.0-beta.47 → 10.0.0-beta.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/scripts",
3
- "version": "10.0.0-beta.47",
3
+ "version": "10.0.0-beta.49",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -3,6 +3,8 @@ const madge = require("madge");
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const { readFileSync, readdirSync, writeFileSync } = require("fs");
6
+ const { findTFunctionNamespaces } = require("./utils/find-t-function-namespaces");
7
+ const { findTransComponentNamespaces } = require("./utils/find-trans-component-namespaces");
6
8
  const join = require("node:path").join;
7
9
 
8
10
  const INCLUDE = ["src"];
@@ -29,40 +31,6 @@ const walk = (dirPath) => {
29
31
  });
30
32
  };
31
33
 
32
- const findTFunctionNamespaces = (pageContent) => {
33
- const regex = /\bt\("([^:]+):[^"]+"\)/g;
34
- const matches = pageContent.matchAll(regex);
35
- const namespaces = new Set();
36
-
37
- for (const match of matches) {
38
- const translationKey = match[0];
39
- const separatorIndex = translationKey.indexOf(":");
40
- if (separatorIndex !== -1) {
41
- const namespace = translationKey.substring(3, separatorIndex);
42
- namespaces.add(namespace);
43
- }
44
- }
45
-
46
- return Array.from(namespaces);
47
- };
48
-
49
- const findTransComponentNamespaces = (pageContent) => {
50
- const regex = /<Trans[^>]*?i18nKey=(['"])(.*?)\1[^>]*\/>/g;
51
- const matches = pageContent.matchAll(regex);
52
- const namespaces = new Set();
53
-
54
- for (const match of matches) {
55
- const [, , translationKey] = match;
56
- const separatorIndex = translationKey.indexOf(":");
57
- if (separatorIndex !== -1) {
58
- const namespace = translationKey.substring(0, separatorIndex);
59
- namespaces.add(namespace);
60
- }
61
- }
62
-
63
- return Array.from(namespaces);
64
- };
65
-
66
34
  const findNamespaces = (pageContent) => {
67
35
  const namespaces = [...findTFunctionNamespaces(pageContent), ...findTransComponentNamespaces(pageContent)];
68
36
 
@@ -0,0 +1,20 @@
1
+ function findTFunctionNamespaces(pageContent) {
2
+ const regex = /\bt\("([^:]+):[^"]+"/g;
3
+ const matches = pageContent.matchAll(regex);
4
+ const namespaces = new Set();
5
+
6
+ for (const match of matches) {
7
+ const translationKey = match[0];
8
+ const separatorIndex = translationKey.indexOf(":");
9
+ if (separatorIndex !== -1) {
10
+ const namespace = translationKey.substring(3, separatorIndex);
11
+ namespaces.add(namespace);
12
+ }
13
+ }
14
+
15
+ return Array.from(namespaces);
16
+ }
17
+
18
+ module.exports = {
19
+ findTFunctionNamespaces,
20
+ };
@@ -0,0 +1,28 @@
1
+ const { findTFunctionNamespaces } = require("./find-t-function-namespaces");
2
+
3
+ const content = `
4
+ <div>
5
+ <div>
6
+ {t("basic:title")}
7
+ </div>
8
+ <div title={
9
+ condition
10
+ ? 'title'
11
+ : t("multiline-with-parameters:title", {
12
+ param: 1
13
+ })
14
+ }/>
15
+ {t("with-parameters:title", {a: t("in-translation-parameter:title")})}
16
+ </div>
17
+ `;
18
+
19
+ describe("find namespaces in t functions", function () {
20
+ it("should find namespaces", function () {
21
+ expect(findTFunctionNamespaces(content)).toStrictEqual([
22
+ "basic",
23
+ "multiline-with-parameters",
24
+ "with-parameters",
25
+ "in-translation-parameter",
26
+ ]);
27
+ });
28
+ });
@@ -0,0 +1,18 @@
1
+ function findTransComponentNamespaces(pageContent) {
2
+ const regex = /<Trans[^>]*?i18nKey=(['"])(.*?)\1[^>]*\/>/g;
3
+ const matches = pageContent.matchAll(regex);
4
+ const namespaces = new Set();
5
+
6
+ for (const match of matches) {
7
+ const [, , translationKey] = match;
8
+ const separatorIndex = translationKey.indexOf(":");
9
+ if (separatorIndex !== -1) {
10
+ const namespace = translationKey.substring(0, separatorIndex);
11
+ namespaces.add(namespace);
12
+ }
13
+ }
14
+
15
+ return Array.from(namespaces);
16
+ }
17
+
18
+ module.exports = { findTransComponentNamespaces };
@@ -0,0 +1,13 @@
1
+ const { findTransComponentNamespaces } = require("./find-trans-component-namespaces");
2
+
3
+ const content = `
4
+ <div>
5
+ <Trans i18nKey="basic:title" />
6
+ </div>
7
+ `;
8
+
9
+ describe("find namespaces in trans component", function () {
10
+ it("should find namespaces", function () {
11
+ expect(findTransComponentNamespaces(content)).toStrictEqual(["basic"]);
12
+ });
13
+ });