@orderly.network/i18n 2.10.2 → 3.0.0-beta.0

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 (49) hide show
  1. package/README.md +193 -34
  2. package/bin/cli.js +92 -37
  3. package/dist/{constant-UZhfXyyb.d.mts → constant-BeXwHrGj.d.mts} +27 -0
  4. package/dist/{constant-UZhfXyyb.d.ts → constant-BeXwHrGj.d.ts} +27 -0
  5. package/dist/constant.d.mts +1 -1
  6. package/dist/constant.d.ts +1 -1
  7. package/dist/index.d.mts +34 -9
  8. package/dist/index.d.ts +34 -9
  9. package/dist/index.js +80 -17
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +79 -19
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/locale.csv +30 -3
  14. package/dist/locales/de.json +30 -3
  15. package/dist/locales/en.json +30 -3
  16. package/dist/locales/es.json +30 -3
  17. package/dist/locales/fr.json +30 -3
  18. package/dist/locales/id.json +30 -3
  19. package/dist/locales/it.json +30 -3
  20. package/dist/locales/ja.json +30 -3
  21. package/dist/locales/ko.json +30 -3
  22. package/dist/locales/nl.json +30 -3
  23. package/dist/locales/pl.json +30 -3
  24. package/dist/locales/pt.json +30 -3
  25. package/dist/locales/ru.json +30 -3
  26. package/dist/locales/tc.json +30 -3
  27. package/dist/locales/tr.json +30 -3
  28. package/dist/locales/uk.json +30 -3
  29. package/dist/locales/vi.json +30 -3
  30. package/dist/locales/zh.json +30 -3
  31. package/dist/utils.d.mts +1 -1
  32. package/dist/utils.d.ts +1 -1
  33. package/dist/utils.js +46 -12
  34. package/dist/utils.js.map +1 -1
  35. package/dist/utils.mjs +46 -12
  36. package/dist/utils.mjs.map +1 -1
  37. package/package.json +7 -7
  38. package/script/copyLocales.js +0 -11
  39. package/script/csv2json.js +0 -28
  40. package/script/diffCsv.js +0 -175
  41. package/script/fillJson.js +0 -33
  42. package/script/generateCsv.js +0 -36
  43. package/script/generateEnJson.js +0 -11
  44. package/script/generateMissingKeys.js +0 -49
  45. package/script/json-csv-converter.js +0 -286
  46. package/script/json2csv.js +0 -38
  47. package/script/mergeJson.js +0 -67
  48. package/script/separateJson.js +0 -50
  49. package/script/utils.js +0 -88
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orderly.network/i18n",
3
- "version": "2.10.2",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Internationalization for orderly sdk",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -48,7 +48,7 @@
48
48
  "tsup": "^8.5.1",
49
49
  "typescript": "^5.1.6",
50
50
  "yargs": "^17.7.2",
51
- "tsconfig": "0.13.2"
51
+ "tsconfig": "1.0.0-beta.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "react": ">=18",
@@ -61,15 +61,15 @@
61
61
  "cli": "node ./bin/cli.js",
62
62
  "csv2json": "pnpm cli csv2json ./dist/locale.csv ./dist/locales",
63
63
  "json2csv": "pnpm cli json2csv ./dist/locales ./dist/locale.csv",
64
- "generateCsv": "pnpm cli generateCsv ./dist/locale.csv",
64
+ "generateCsv": "pnpm cli generateCsv ./locales ./dist/locale.csv",
65
65
  "diffcsv": "pnpm cli diffcsv ./dist/locale1.csv ./dist/locale2.csv",
66
66
  "fillJson": "pnpm cli fillJson ./src/locale/zh.json ./dist/locale/zh.json",
67
67
  "separateJson": "pnpm cli separateJson ./locales ./dist/locales extend",
68
68
  "mergeJson": "pnpm cli mergeJson ./locales ./dist/locales",
69
69
  "mergeExtendJson": "pnpm cli mergeJson ./locales ./locales",
70
- "_generateEnJson": "node ./script/generateEnJson.js",
71
- "generateEnJson": "pnpm tsup && node ./script/generateEnJson.js",
72
- "copyLocales": "node ./script/copyLocales.js",
73
- "generateMissingKeys": "pnpm tsup && pnpm _generateEnJson && node ./script/generateMissingKeys.js"
70
+ "_generateEnJson": "node ./scripts/generateEnJson.js",
71
+ "generateEnJson": "pnpm tsup && node ./scripts/generateEnJson.js",
72
+ "copyLocales": "node ./scripts/copyLocales.js",
73
+ "generateMissingKeys": "pnpm tsup && pnpm _generateEnJson && node ./scripts/generateMissingKeys.js"
74
74
  }
75
75
  }
@@ -1,11 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
-
4
- async function copyLocales() {
5
- await fs.copy(
6
- path.resolve(__dirname, "../locales"),
7
- path.resolve(__dirname, "../dist/locales")
8
- );
9
- }
10
-
11
- copyLocales();
@@ -1,28 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { csv2multiJson } = require("./json-csv-converter");
4
- const { checkFileExists } = require("./utils");
5
-
6
- /** Convert locale CSV to multiple locale JSON files */
7
- async function csv2json(inputPath, outputDir) {
8
- const csv = fs.readFileSync(inputPath, { encoding: "utf8" });
9
-
10
- const json = csv2multiJson(csv);
11
-
12
- const files = [];
13
-
14
- for (const key of Object.keys(json)) {
15
- const filePath = path.resolve(outputDir, `${key}.json`);
16
- await checkFileExists(filePath);
17
- await fs.outputFile(filePath, JSON.stringify(json[key], undefined, 4), {
18
- encoding: "utf8",
19
- });
20
- files.push(filePath);
21
- }
22
-
23
- console.log("csv2json success =>", files);
24
- }
25
-
26
- module.exports = {
27
- csv2json,
28
- };
package/script/diffCsv.js DELETED
@@ -1,175 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { csv2multiJson } = require("./json-csv-converter");
4
- const packageJson = require("../package.json");
5
-
6
- /**
7
- * https://www.jsdelivr.com/package/npm/@orderly.network/i18n?tab=files&path=dist
8
- * Compare two locale CSV files
9
- */
10
- async function diffCsv(oldFile, newFile) {
11
- const oldCsv = await fs.readFile(oldFile, { encoding: "utf8" });
12
- const newCsv = await fs.readFile(newFile, { encoding: "utf8" });
13
-
14
- const oldJson = csv2multiJson(oldCsv);
15
- const newJson = csv2multiJson(newCsv);
16
- const diffResult = compareJsonFiles(oldJson, newJson);
17
- console.log("CSV diff result:", JSON.stringify(diffResult, null, 2));
18
-
19
- const filepath = path.resolve("LOCALE_CHANGELOG.md");
20
-
21
- // generate .md file
22
- let markdownContent = generateMarkdown(diffResult);
23
-
24
- if (!(await fs.exists(filepath))) {
25
- const title = `# Locale Changelog`;
26
- markdownContent = `${title}\n\n${markdownContent}`;
27
-
28
- await fs.writeFile(filepath, markdownContent, {
29
- encoding: "utf8",
30
- });
31
- console.log("LOCALE_CHANGELOG.md created");
32
- } else {
33
- // Read existing content
34
- const existingContent = await fs.readFile(filepath, { encoding: "utf8" });
35
-
36
- // Find the position after "# Locale Changelog"
37
- const titleIndex = existingContent.indexOf("# Locale Changelog");
38
- if (titleIndex === -1) {
39
- console.error("Could not find '# Locale Changelog' title in the file");
40
- return;
41
- }
42
-
43
- const titleEndIndex = titleIndex + "# Locale Changelog".length;
44
-
45
- // Split content and insert new content after the title
46
- const beforeTitle = existingContent.slice(0, titleEndIndex);
47
- const afterTitle = existingContent.slice(titleEndIndex);
48
-
49
- // Combine all parts
50
- const newContent = `${beforeTitle}\n\n${markdownContent}${afterTitle}`;
51
-
52
- // Write back to file
53
- await fs.writeFile(filepath, newContent, {
54
- encoding: "utf8",
55
- });
56
- console.log("LOCALE_CHANGELOG.md updated");
57
- }
58
- }
59
-
60
- // Compare function
61
- function compareJsonFiles(oldJson, newJson) {
62
- const result = {
63
- added: {},
64
- removed: {},
65
- updated: {},
66
- };
67
-
68
- Object.keys(newJson).forEach((lang) => {
69
- result.added[lang] = {};
70
- result.removed[lang] = {};
71
- result.updated[lang] = {};
72
-
73
- const oldKeys = oldJson[lang] || {};
74
- const newKeys = newJson[lang];
75
-
76
- // Find added keys
77
- Object.keys(newKeys).forEach((key) => {
78
- if (!(key in oldKeys)) {
79
- result.added[lang][key] = newKeys[key];
80
- }
81
- });
82
-
83
- // Find removed keys
84
- Object.keys(oldKeys).forEach((key) => {
85
- if (!(key in newKeys)) {
86
- result.removed[lang][key] = oldKeys[key];
87
- }
88
- });
89
-
90
- // Find updated keys (same key, different value)
91
- Object.keys(newKeys).forEach((key) => {
92
- if (key in oldKeys && oldKeys[key] !== newKeys[key]) {
93
- result.updated[lang][key] = {
94
- old: oldKeys[key],
95
- new: newKeys[key],
96
- };
97
- }
98
- });
99
- });
100
-
101
- return result;
102
- }
103
-
104
- // generate Markdown conent
105
- function generateMarkdown(diff) {
106
- let mdContent = `## ${packageJson.version}\n\n`;
107
-
108
- const addedKeysEmpty = Object.keys(diff.added).every((lang) => {
109
- return Object.keys(diff.added[lang]).length === 0;
110
- });
111
- const removedKeysEmpty = Object.keys(diff.removed).every((lang) => {
112
- return Object.keys(diff.removed[lang]).length === 0;
113
- });
114
- const updatedKeysEmpty = Object.keys(diff.updated).every((lang) => {
115
- return Object.keys(diff.updated[lang]).length === 0;
116
- });
117
-
118
- if (addedKeysEmpty && removedKeysEmpty && updatedKeysEmpty) {
119
- return `${mdContent}### No locale changes`;
120
- }
121
-
122
- // handle added content
123
- if (!addedKeysEmpty) {
124
- mdContent += `### Added Keys\n`;
125
- Object.keys(diff.added).forEach((lang) => {
126
- if (Object.keys(diff.added[lang]).length === 0) {
127
- mdContent += `\n#### Language: **${lang}**\n> No added keys.\n`;
128
- } else {
129
- mdContent += `\n#### Language: **${lang}**\n`;
130
- mdContent += `| Key | Value |\n| --- | --- |\n`;
131
- Object.entries(diff.added[lang]).forEach(([key, value]) => {
132
- mdContent += `| ${key} | ${value} |\n`;
133
- });
134
- }
135
- });
136
- }
137
-
138
- // handle removed content
139
- if (!removedKeysEmpty) {
140
- mdContent += `\n### Removed Keys\n`;
141
- Object.keys(diff.removed).forEach((lang) => {
142
- if (Object.keys(diff.removed[lang]).length === 0) {
143
- mdContent += `\n#### Language: **${lang}**\n> No removed keys.\n`;
144
- } else {
145
- mdContent += `\n#### Language: **${lang}**\n`;
146
- mdContent += `| Key | Value |\n| --- | --- |\n`;
147
- Object.entries(diff.removed[lang]).forEach(([key, value]) => {
148
- mdContent += `| ${key} | ${value} |\n`;
149
- });
150
- }
151
- });
152
- }
153
-
154
- // handle updated content
155
- if (!updatedKeysEmpty) {
156
- mdContent += `\n### Updated Keys\n`;
157
- Object.keys(diff.updated).forEach((lang) => {
158
- if (Object.keys(diff.updated[lang]).length === 0) {
159
- mdContent += `\n#### Language: **${lang}**\n> No updates found.\n`;
160
- } else {
161
- mdContent += `\n#### Language: **${lang}**\n`;
162
- mdContent += `| Key | Old Value | New Value |\n| --- | --- | --- |\n`;
163
- Object.entries(diff.updated[lang]).forEach(([key, values]) => {
164
- mdContent += `| ${key} | ${values.old} | ${values.new} |\n`;
165
- });
166
- }
167
- });
168
- }
169
-
170
- return mdContent;
171
- }
172
-
173
- module.exports = {
174
- diffCsv,
175
- };
@@ -1,33 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { checkFileExists } = require("./utils");
4
- const { en } = require("../dist");
5
-
6
- /** Fill values from the input locale JSON file and generate a new locale JSON file */
7
- async function fillJson(inputPath, outputPath) {
8
- const inputJson = await fs.readJSON(inputPath, { encoding: "utf8" });
9
-
10
- const newJson = {};
11
- const missingValues = {};
12
- Object.keys(en).forEach((key) => {
13
- const value = inputJson[key] || "";
14
- if (!value) {
15
- missingValues[key] = en[key];
16
- }
17
- newJson[key] = value;
18
- });
19
- console.log("missingValues", missingValues);
20
-
21
- const jsonPath = path.resolve(outputPath);
22
- await checkFileExists(jsonPath);
23
-
24
- await fs.outputFile(jsonPath, JSON.stringify(newJson, null, 4), {
25
- encoding: "utf8",
26
- });
27
-
28
- console.log("fillJson success =>", jsonPath);
29
- }
30
-
31
- module.exports = {
32
- fillJson,
33
- };
@@ -1,36 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { checkFileExists } = require("./utils");
4
- const { multiJson2Csv } = require("./json-csv-converter");
5
- const { defaultLanguages } = require("../dist");
6
-
7
- /** Generate a locale CSV file */
8
- async function generateCsv(outputPath) {
9
- const headers = [""];
10
- const jsonList = [];
11
-
12
- for (const item of defaultLanguages) {
13
- headers.push(item.localCode);
14
- const json = await fs.readJSON(
15
- path.resolve(__dirname, `../locales/${item.localCode}.json`),
16
- {
17
- encoding: "utf8",
18
- }
19
- );
20
- jsonList.push(json);
21
- }
22
-
23
- const csv = multiJson2Csv(jsonList, headers);
24
-
25
- const csvPath = path.resolve(outputPath);
26
-
27
- await checkFileExists(outputPath);
28
-
29
- await fs.outputFile(outputPath, csv, { encoding: "utf8" });
30
-
31
- console.log("generateCsv success =>", csvPath);
32
- }
33
-
34
- module.exports = {
35
- generateCsv,
36
- };
@@ -1,11 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { en } = require("../dist");
4
-
5
- async function generateEnJson() {
6
- const outPath = path.resolve(__dirname, "../locales/en.json");
7
- const jsonData = JSON.stringify(en, null, 2);
8
- await fs.outputFile(outPath, jsonData, { encoding: "utf8" });
9
- }
10
-
11
- generateEnJson();
@@ -1,49 +0,0 @@
1
- const fs = require("fs-extra");
2
- const path = require("path");
3
- const { getMissingKeys } = require("./json-csv-converter");
4
- const { checkFileExists, findJsonFiles } = require("./utils");
5
- const { LocaleEnum } = require("../dist");
6
-
7
- async function generateMissingKeys() {
8
- const inputDir = path.resolve(__dirname, "../locales");
9
- const jsonFiles = await findJsonFiles(inputDir);
10
-
11
- // Sort input files by locale
12
- jsonFiles.sort((a, b) => (b.startsWith(LocaleEnum.en) ? 1 : -1));
13
-
14
- const jsonList = [];
15
- const headers = [""];
16
-
17
- for (const file of jsonFiles) {
18
- const jsonPath = path.resolve(inputDir, file);
19
-
20
- const json = await fs.readJSON(jsonPath, {
21
- encoding: "utf8",
22
- });
23
-
24
- jsonList.push(json);
25
-
26
- const fileName = path.basename(file, path.extname(file));
27
- headers.push(fileName);
28
- }
29
-
30
- const errors = getMissingKeys(jsonList, headers);
31
-
32
- const missingJson = {};
33
- for (const locale of Object.values(errors)) {
34
- for (const [key, value] of Object.entries(locale)) {
35
- missingJson[key] = value;
36
- }
37
- }
38
-
39
- const outputPath = path.resolve(inputDir, "extend/en.json");
40
-
41
- // don't check file exists
42
- // await checkFileExists(outputPath);
43
-
44
- await fs.outputFile(outputPath, JSON.stringify(missingJson, null, 2), {
45
- encoding: "utf8",
46
- });
47
- }
48
-
49
- generateMissingKeys();
@@ -1,286 +0,0 @@
1
- const { validateI18nValue } = require("./utils");
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- const separator = ".";
6
-
7
- function multiJson2Csv(jsonList, header) {
8
- if (!Array.isArray(jsonList) || jsonList.length === 0) {
9
- throw "Object array please.";
10
- }
11
-
12
- const ignoreKeys = loadIgnoreKeys();
13
- const baseJson = jsonList[0];
14
- const baseKeys = Object.keys(baseJson);
15
- const errors = {};
16
- let result = header.length ? [header] : [];
17
- for (const key of baseKeys) {
18
- const values = [];
19
- for (const [index, json] of jsonList.entries()) {
20
- const val = json[key] || "";
21
- values.push(val);
22
- // Skip validation if key is in ignore list
23
- if (!shouldIgnoreKey(key, ignoreKeys)) {
24
- const bool = validateI18nValue(val);
25
- if (!bool.valid) {
26
- const locale = header[index + 1];
27
- if (!errors[locale]) {
28
- errors[locale] = {};
29
- }
30
- errors[locale][key] = baseJson[key];
31
- }
32
- }
33
- }
34
- result.push(stringsToCsvLine([key, ...values]));
35
- }
36
- if (Object.keys(errors).length > 0) {
37
- throw new Error(
38
- "valid i18n value failed, please check the value of the following values: " +
39
- JSON.stringify(errors, null, 4),
40
- );
41
- }
42
- return result.join("\n");
43
- }
44
-
45
- function csv2multiJson(csv) {
46
- if (typeof csv !== "string") throw "String please.";
47
- const json = {};
48
-
49
- const ignoreKeys = loadIgnoreKeys();
50
- const lines = csvToLines(csv);
51
- const csvLines = lines.filter(Boolean).map(parseCsvLine);
52
-
53
- const headers = csvLines.shift();
54
-
55
- const errors = {};
56
- for (const [index, header] of headers.entries()) {
57
- json[header] = {};
58
- for (const line of csvLines) {
59
- const [key, ...values] = line;
60
- if (!key) {
61
- continue;
62
- }
63
- const val = values[index];
64
- json[header][key] = val;
65
- // Skip validation if key is in ignore list
66
- if (!shouldIgnoreKey(key, ignoreKeys)) {
67
- const bool = validateI18nValue(val);
68
- if (!bool.valid) {
69
- if (!errors[header]) {
70
- errors[header] = {};
71
- }
72
- errors[header][key] = values[0];
73
- }
74
- }
75
- }
76
-
77
- if (Object.values(json[header]).every((value) => !value)) {
78
- delete json[header];
79
- }
80
- }
81
-
82
- if (Object.keys(errors).length > 0) {
83
- throw new Error(
84
- "valid i18n value failed, please check the value of the following values: " +
85
- JSON.stringify(errors, null, 4),
86
- );
87
- }
88
-
89
- return json;
90
- }
91
-
92
- function json2Csv(json) {
93
- if (typeof json !== "object" || !json) throw "Object please.";
94
- return findKeyValues(json).join("\n");
95
- }
96
-
97
- function csv2Json(csv) {
98
- if (typeof csv !== "string") throw "String please.";
99
- const json = {};
100
- parseCsvLines(csv).forEach((line) => {
101
- const [path, value] = line;
102
- const pathSplit = path.split(separator);
103
- deepSet(json, pathSplit, value);
104
- });
105
- return json;
106
- }
107
-
108
- function findKeyValues(o, prefix, l = 0) {
109
- let result = [];
110
- for (const key of Object.keys(o)) {
111
- const fullKey = prefix ? prefix + separator + key : key;
112
- const value = o[key];
113
- if (typeof value === "string") {
114
- result.push(stringsToCsvLine([fullKey, value]));
115
- } else if (typeof value === "object" && value) {
116
- result = result.concat(findKeyValues(value, fullKey, l + 1));
117
- }
118
- }
119
- return result;
120
- }
121
-
122
- function stringsToCsvLine(line) {
123
- return line.map((s) => `"${s.replace(/"/g, '""')}"`).join(",");
124
- }
125
-
126
- function deepSet(o, path, value) {
127
- if (path.length > 1) {
128
- const key = path[0];
129
- if (!o[key]) {
130
- o[key] = {};
131
- }
132
- deepSet(o[key], path.slice(1), value);
133
- } else {
134
- o[path[0]] = value;
135
- }
136
- }
137
-
138
- function parseCsvLines(csv) {
139
- const lines = csvToLines(csv);
140
- return lines.filter(Boolean).map(parseCsvLine);
141
- }
142
-
143
- function csvToLines(csv) {
144
- return csv.split(/[\r\n]+/);
145
- }
146
-
147
- function parseCsvLine(line) {
148
- const result = [];
149
- for (let i = 0; i < line.length; i++) {
150
- const char = line[i];
151
- switch (char) {
152
- case ",":
153
- continue;
154
- case '"': {
155
- i++;
156
- const [str, i2] = parseCsvString(line, i);
157
- i = i2;
158
- result.push(str);
159
- break;
160
- }
161
- default: {
162
- const [str, i2] = parseUnquotedField(line, i);
163
- i = i2;
164
- result.push(str);
165
- break;
166
- }
167
- }
168
- }
169
- return result;
170
- }
171
-
172
- /** Parses one field until the next comma or end of line (for unquoted CSV). */
173
- function parseUnquotedField(line, i) {
174
- let result = "";
175
- for (; i < line.length; i++) {
176
- if (line[i] === ",") break;
177
- result += line[i];
178
- }
179
- return [result, i];
180
- }
181
-
182
- function parseCsvString(line, i) {
183
- let result = "";
184
- loop: for (; i < line.length; i++) {
185
- const char = line[i];
186
- switch (char) {
187
- case '"':
188
- i++;
189
- if (line[i] === '"') {
190
- result += '"';
191
- } else {
192
- break loop;
193
- }
194
- break;
195
- default:
196
- result += char;
197
- }
198
- }
199
- return [result, i];
200
- }
201
-
202
- function getMissingKeys(jsonList, header) {
203
- if (!Array.isArray(jsonList) || jsonList.length === 0) {
204
- throw "Object array please.";
205
- }
206
-
207
- const baseJson = jsonList[0];
208
- const baseKeys = Object.keys(baseJson);
209
- const errors = {};
210
- for (const key of baseKeys) {
211
- for (const [index, json] of jsonList.entries()) {
212
- const val = json[key] || "";
213
- const bool = validateI18nValue(val);
214
- if (!bool.valid) {
215
- const locale = header[index + 1];
216
- if (!errors[locale]) {
217
- errors[locale] = {};
218
- }
219
- errors[locale][key] = baseJson[key];
220
- }
221
- }
222
- }
223
- return errors;
224
- }
225
-
226
- // Load ignore validation keys configuration
227
- function loadIgnoreKeys() {
228
- const configPath = path.join(__dirname, "../validation-ignore.json");
229
- try {
230
- if (fs.existsSync(configPath)) {
231
- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
232
- const ignoreKeys = config.ignoreKeys || [];
233
- // Convert config to matcher array: string or regex
234
- return ignoreKeys
235
- .map((item) => {
236
- if (typeof item === "string") {
237
- // If string starts and ends with /, treat as regex pattern
238
- if (item.startsWith("/") && item.endsWith("/") && item.length > 2) {
239
- try {
240
- const pattern = item.slice(1, -1); // Remove leading and trailing /
241
- return new RegExp(pattern);
242
- } catch (error) {
243
- console.warn(
244
- `Warning: Invalid regex pattern "${item}": ${error.message}`,
245
- );
246
- return item;
247
- }
248
- }
249
- return item;
250
- }
251
- return item;
252
- })
253
- .filter(Boolean);
254
- }
255
- } catch (error) {
256
- console.warn(
257
- `Warning: Failed to load validation-ignore.json: ${error.message}`,
258
- );
259
- }
260
- return [];
261
- }
262
-
263
- // Check if key should be ignored
264
- function shouldIgnoreKey(key, ignoreKeys) {
265
- for (const matcher of ignoreKeys) {
266
- if (matcher instanceof RegExp) {
267
- if (matcher.test(key)) {
268
- return true;
269
- }
270
- } else if (typeof matcher === "string") {
271
- if (matcher === key) {
272
- return true;
273
- }
274
- }
275
- }
276
- return false;
277
- }
278
-
279
- module.exports = {
280
- separator,
281
- json2Csv,
282
- csv2Json,
283
- multiJson2Csv,
284
- csv2multiJson,
285
- getMissingKeys,
286
- };