// ███████╗███████╗███████╗███████╗██╗ ██████╗ ███╗ ██╗ ██████╗ █████╗ ████████╗██╗ ██╗███████╗ // ██╔════╝██╔════╝██╔════╝██╔════╝██║██╔═══██╗████╗ ██║ ██╔══██╗██╔══██╗╚══██╔══╝██║ ██║██╔════╝ // ███████╗█████╗ ███████╗███████╗██║██║ ██║██╔██╗ ██║█████╗██████╔╝███████║ ██║ ███████║███████╗ // ╚════██║██╔══╝ ╚════██║╚════██║██║██║ ██║██║╚██╗██║╚════╝██╔═══╝ ██╔══██║ ██║ ██╔══██║╚════██║ // ███████║███████╗███████║███████║██║╚██████╔╝██║ ╚████║ ██║ ██║ ██║ ██║ ██║ ██║███████║ // ╚══════╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝ // MIT License (c) 2020–present Cezar Augusto & the Extension.js authors, presence implies inheritance const MSG_REFERENCE = /__MSG_([A-Za-z0-9_@]+?)__/g export function collectMsgReferences(value: unknown): string[] { const found: string[] = [] const seen = new Set() const visit = (node: unknown) => { if (typeof node === 'string') { MSG_REFERENCE.lastIndex = 0 let match: RegExpExecArray | null = MSG_REFERENCE.exec(node) while (match !== null) { const name = match[1] if (name && !name.startsWith('@@') && !seen.has(name)) { seen.add(name) found.push(name) } match = MSG_REFERENCE.exec(node) } return } if (Array.isArray(node)) { for (const item of node) visit(item) return } if (node && typeof node === 'object') { for (const item of Object.values(node as Record)) { visit(item) } } } visit(value) return found } // References with no catalog entry, spelled the way the author wrote them. export function findUndefinedMsgReferences( value: unknown, catalogKeys: Iterable ): string[] { const lower = new Set() for (const key of catalogKeys) lower.add(String(key).toLowerCase()) return collectMsgReferences(value).filter( (name) => !lower.has(name.toLowerCase()) ) }