MCPcopy Create free account
hub / github.com/bytebase/bytebase / findSingleBracePlaceholders

Function findSingleBracePlaceholders

frontend/scripts/check-react-i18n.mjs:310–324  ·  view source on GitHub ↗
(obj, path = "")

Source from the content-addressed store, hash-verified

308const SINGLE_BRACE_RE = /(?<!\{)\{([a-zA-Z_][a-zA-Z0-9_]*)\}(?!\})/g;
309
310function findSingleBracePlaceholders(obj, path = "") {
311 const issues = [];
312 if (obj && typeof obj === "object" && !Array.isArray(obj)) {
313 for (const [k, v] of Object.entries(obj)) {
314 issues.push(...findSingleBracePlaceholders(v, path ? `${path}.${k}` : k));
315 }
316 } else if (typeof obj === "string") {
317 SINGLE_BRACE_RE.lastIndex = 0;
318 const names = [];
319 let m;
320 while ((m = SINGLE_BRACE_RE.exec(obj))) names.push(m[1]);
321 if (names.length > 0) issues.push({ key: path, value: obj, names });
322 }
323 return issues;
324}
325
326for (const locale of LOCALES) {
327 const main = JSON.parse(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected