ui-strings 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/dist/cli.js +43 -11
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -95,6 +95,16 @@ var URLISH = /^(https?:\/\/|mailto:|tel:|www\.|[./#~@])/;
95
95
  var HEX_COLOR = /^#[0-9a-fA-F]{3,8}$/;
96
96
  var IDENTIFIER_TOKEN = /^[A-Za-z0-9]+([-_][A-Za-z0-9\[\]%./:#]+)+$/;
97
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
+ };
98
108
  var hasNonLatinLetter = (text) => {
99
109
  for (const ch of text) {
100
110
  const code = ch.codePointAt(0) ?? 0;
@@ -142,6 +152,9 @@ var withoutPlaceholders = (text) => text.replace(/\{[^{}]*\}/g, "");
142
152
  var lexical = (text) => hasNonLatinLetter(text) || looksLikeEnglishCopy(text);
143
153
  var isCopyEn = (text, context) => {
144
154
  const { kind, attr, callee, key } = context;
155
+ if (looksLikeCode(text)) {
156
+ return false;
157
+ }
145
158
  if (hasNonLatinLetter(text)) {
146
159
  return true;
147
160
  }
@@ -490,17 +503,30 @@ var surfaceFor = (classified, file) => {
490
503
  }
491
504
  return "visible";
492
505
  };
493
- var groupFor = (relativeFile, hasAppDir) => {
494
- const parts = relativeFile.split(sep);
495
- const appIndex = parts.indexOf("app");
496
- if (hasAppDir && parts[0] === "src" && appIndex === 1) {
497
- const segments = parts.slice(2, -1).filter((segment) => segment !== "_dependencies" && !(segment.startsWith("(") && segment.endsWith(")")));
498
- return `/${segments.join("/")}`;
506
+ var sharedPrefixLength = (files) => {
507
+ const first = files[0];
508
+ if (first === undefined) {
509
+ return 0;
510
+ }
511
+ let shared = first.length - 1;
512
+ for (const parts of files) {
513
+ const limit = Math.min(shared, parts.length - 1);
514
+ let i = 0;
515
+ while (i < limit && parts[i] === first[i]) {
516
+ i += 1;
517
+ }
518
+ shared = i;
499
519
  }
500
- const dirs = parts.slice(0, -1);
501
- if (dirs[0] === "src") {
502
- dirs.shift();
520
+ const boundary = first.slice(0, shared).findIndex((segment) => segment === "src" || segment === "app");
521
+ return boundary === -1 ? shared : boundary;
522
+ };
523
+ var groupFor = (parts, hasAppDir) => {
524
+ const rest = parts[0] === "src" ? parts.slice(1) : parts;
525
+ if (hasAppDir && rest[0] === "app") {
526
+ const segments = rest.slice(1, -1).filter((segment) => segment !== "_dependencies" && !(segment.startsWith("(") && segment.endsWith(")")));
527
+ return `/${segments.slice(0, 2).join("/")}`;
503
528
  }
529
+ const dirs = rest.slice(0, -1);
504
530
  return dirs.slice(0, 2).join("/") || "(root)";
505
531
  };
506
532
  var DEFAULT_EXCLUDES = [
@@ -523,7 +549,13 @@ var scanProject = (options) => {
523
549
  `${projectDir}/${srcGlob}`,
524
550
  ...excludes.map((glob) => `!${projectDir}/${glob}`)
525
551
  ]);
526
- const hasAppDir = sourceFiles.some((file) => relative(projectDir, file.getFilePath()).startsWith(`src${sep}app${sep}`));
552
+ const relativeParts = sourceFiles.map((file) => relative(projectDir, file.getFilePath()).split(sep));
553
+ const prefixLength = sharedPrefixLength(relativeParts);
554
+ const hasAppDir = relativeParts.some((parts) => {
555
+ const stripped = parts.slice(prefixLength);
556
+ const rest = stripped[0] === "src" ? stripped.slice(1) : stripped;
557
+ return rest[0] === "app" && rest.length > 1;
558
+ });
527
559
  const renderSites = new Map;
528
560
  for (const sourceFile of sourceFiles) {
529
561
  const relativeFile = relative(projectDir, sourceFile.getFilePath());
@@ -559,7 +591,7 @@ var scanProject = (options) => {
559
591
  const entries = [];
560
592
  for (const sourceFile of sourceFiles) {
561
593
  const relativeFile = relative(projectDir, sourceFile.getFilePath());
562
- const group = groupFor(relativeFile, hasAppDir);
594
+ const group = groupFor(relativeFile.split(sep).slice(prefixLength), hasAppDir);
563
595
  const consumed = new Set;
564
596
  const nodeKey = (node) => `${node.getPos()}:${node.getEnd()}`;
565
597
  const push = (text, node, classified) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-strings",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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": {