ui-strings 0.1.1 → 0.1.3

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 (2) hide show
  1. package/dist/cli.js +23 -1
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -77,7 +77,8 @@ var TECHNICAL_KEYS = new Set([
77
77
  "slug",
78
78
  "locale",
79
79
  "format",
80
- "testId"
80
+ "testId",
81
+ "__html"
81
82
  ]);
82
83
  var CLASSNAME_CALLEES = new Set([
83
84
  "cn",
@@ -94,6 +95,16 @@ var URLISH = /^(https?:\/\/|mailto:|tel:|www\.|[./#~@])/;
94
95
  var HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
95
96
  var IDENTIFIER_TOKEN = /^[A-Za-z0-9]+([-_][A-Za-z0-9\[\]%./:#]+)+$/;
96
97
  var CONSTANT_TOKEN = /^[A-Z0-9_]+$/;
98
+ var CODE_LINE = /^(import|export|const|let|var|function|return|type|interface|if|for|while|switch)\b|^["']use (client|server)["']|[{};]$|^[})\]]|=>/;
99
+ var looksLikeCode = (text) => {
100
+ const lines = text.split(`
101
+ `).map((line) => line.trim()).filter((line) => line !== "");
102
+ if (lines.length < 3) {
103
+ return false;
104
+ }
105
+ const codeLines = lines.filter((line) => CODE_LINE.test(line)).length;
106
+ return codeLines / lines.length >= 0.5;
107
+ };
97
108
  var hasNonLatinLetter = (text) => {
98
109
  for (const ch of text) {
99
110
  const code = ch.codePointAt(0) ?? 0;
@@ -141,6 +152,9 @@ var withoutPlaceholders = (text) => text.replace(/\{[^{}]*\}/g, "");
141
152
  var lexical = (text) => hasNonLatinLetter(text) || looksLikeEnglishCopy(text);
142
153
  var isCopyEn = (text, context) => {
143
154
  const { kind, attr, callee, key } = context;
155
+ if (looksLikeCode(text)) {
156
+ return false;
157
+ }
144
158
  if (hasNonLatinLetter(text)) {
145
159
  return true;
146
160
  }
@@ -203,6 +217,7 @@ var INLINE_TAGS = new Set([
203
217
  "rt"
204
218
  ]);
205
219
  var BREAK_TAGS = new Set(["br", "wbr"]);
220
+ var RAW_TEXT_TAGS = new Set(["script", "style"]);
206
221
  var INTERACTIVE_KEY_PATTERN = /^(message|error|success|warning|status)|(message|error)$/i;
207
222
  var INTERACTIVE_FILE_PATTERN = /(^|\/)(actions|route)\.tsx?$/;
208
223
  var collapseWhitespace = (text) => text.replace(/\s+/g, " ").trim();
@@ -586,6 +601,13 @@ var scanProject = (options) => {
586
601
  return;
587
602
  }
588
603
  if (Node.isJsxElement(node) || Node.isJsxFragment(node)) {
604
+ const tag = tagNameOf(node);
605
+ if (tag !== undefined && RAW_TEXT_TAGS.has(tag)) {
606
+ node.forEachDescendant((descendant) => {
607
+ consumed.add(nodeKey(descendant));
608
+ });
609
+ return;
610
+ }
589
611
  const runs = mergeRuns(node, detector.hasCopyText);
590
612
  const coversAll = runs.length === 1 && runs[0]?.nodes.length === node.getJsxChildren().length;
591
613
  for (const run of runs) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-strings",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Extract user-reachable UI strings from React (TS/TSX) codebases and generate JSON / Markdown / HTML reports",
5
5
  "type": "module",
6
6
  "bin": {