i18n-sharpen 0.2.3 → 0.2.4
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/README.md +9 -0
- package/dist/cli.js +9 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -132,6 +132,15 @@ npx i18n-sharpen prune --force
|
|
|
132
132
|
> [!WARNING]
|
|
133
133
|
> **JS/TS locale files are Read-Only.** `extract` and `prune` will throw an error if asked to write to a `.js`, `.cjs`, `.mjs`, `.ts`, or `.tsx` file. This prevents the tool from destroying imports, JSDoc, type annotations, or custom wrapping code. If you want `i18n-sharpen` to automatically manage and mutate your locale files, convert them to `.json` or `.yaml`.
|
|
134
134
|
|
|
135
|
+
### Format Trade-offs (`.json` vs. `.ts` / `.js`)
|
|
136
|
+
|
|
137
|
+
* **Using `.ts` / `.tsx` (or JS modules):**
|
|
138
|
+
* *Requirement:* You must install `jiti` as a `devDependency`.
|
|
139
|
+
* *Capability:* Supported for **`validate` only**. Automatic `extract` and `prune` are disabled.
|
|
140
|
+
* **Using `.json` / `.yaml`:**
|
|
141
|
+
* *Capability:* Full support for **all features** (`validate`, `extract`, and `prune`).
|
|
142
|
+
* *Note:* Vite and TypeScript natively resolve types for `.json` imports (by enabling `"resolveJsonModule": true` in your `tsconfig.json`), guaranteeing compile-time type safety with zero runtime overhead.
|
|
143
|
+
|
|
135
144
|
---
|
|
136
145
|
|
|
137
146
|
## Locale Layouts
|
package/dist/cli.js
CHANGED
|
@@ -23,6 +23,9 @@ function escapeRegex(input) {
|
|
|
23
23
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24
24
|
}
|
|
25
25
|
function buildKeyRegex(matchFunctions) {
|
|
26
|
+
if (matchFunctions.length === 0) {
|
|
27
|
+
return /(?!)/g;
|
|
28
|
+
}
|
|
26
29
|
const functionsJoined = matchFunctions.map(escapeRegex).join("|");
|
|
27
30
|
return new RegExp(
|
|
28
31
|
"\\b(?:" + functionsJoined + ")\\s*\\(\\s*(['\"`])([a-zA-Z0-9_\\-.:]+)\\1",
|
|
@@ -30,6 +33,9 @@ function buildKeyRegex(matchFunctions) {
|
|
|
30
33
|
);
|
|
31
34
|
}
|
|
32
35
|
function buildAttrRegex(matchAttributes) {
|
|
36
|
+
if (matchAttributes.length === 0) {
|
|
37
|
+
return /(?!)/g;
|
|
38
|
+
}
|
|
33
39
|
const attrsJoined = matchAttributes.map(escapeRegex).join("|");
|
|
34
40
|
return new RegExp(
|
|
35
41
|
"(?:^|[\\s/{(>])(?:" + attrsJoined + ")\\s*=\\s*(['\"`])([a-zA-Z0-9_\\-.:]+)\\1",
|
|
@@ -37,6 +43,9 @@ function buildAttrRegex(matchAttributes) {
|
|
|
37
43
|
);
|
|
38
44
|
}
|
|
39
45
|
function buildDynamicCallRegex(matchFunctions) {
|
|
46
|
+
if (matchFunctions.length === 0) {
|
|
47
|
+
return /(?!)/g;
|
|
48
|
+
}
|
|
40
49
|
const functionsJoined = matchFunctions.map(escapeRegex).join("|");
|
|
41
50
|
return new RegExp("\\b(?:" + functionsJoined + ")\\s*\\(\\s*([^)]*)\\)", "g");
|
|
42
51
|
}
|