@dev-pi2pie/word-counter 0.0.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.mjs","names":["frontmatter","wordCounter","pc","resolve","resolvePath","wordCounter"],"sources":["../../src/utils/show-singular-or-plural-word.ts","../../src/wc/segmenter.ts","../../src/wc/analyze.ts","../../src/wc/locale-detect.ts","../../src/wc/segment.ts","../../src/wc/wc.ts","../../src/wc/index.ts","../../src/markdown/toml/arrays.ts","../../src/markdown/toml/keys.ts","../../src/markdown/toml/strings.ts","../../src/markdown/toml/values.ts","../../src/markdown/toml/parse-frontmatter.ts","../../src/markdown/parse-markdown.ts","../../src/markdown/section-count.ts","../../node_modules/picocolors/picocolors.js","../../src/command.ts","../../src/bin.ts"],"sourcesContent":["export function showSingularOrPluralWord(count: number, word: string): string {\n return `${count} ${word}${count === 1 ? \"\" : \"s\"}`;\n}\n","const segmenterCache = new Map<string, Intl.Segmenter>();\n\nexport function getSegmenter(locale: string): Intl.Segmenter {\n const cached = segmenterCache.get(locale);\n if (cached) {\n return cached;\n }\n const segmenter = new Intl.Segmenter(locale, { granularity: \"word\" });\n segmenterCache.set(locale, segmenter);\n return segmenter;\n}\n\nexport function countWordsForLocale(text: string, locale: string): number {\n const segmenter = getSegmenter(locale);\n let count = 0;\n for (const segment of segmenter.segment(text)) {\n if (segment.isWordLike) {\n count++;\n }\n }\n return count;\n}\n","import { getSegmenter } from \"./segmenter\";\nimport type { ChunkAnalysis, CollectorBreakdown, LocaleChunk } from \"./types\";\n\nexport function analyzeChunk(chunk: LocaleChunk): ChunkAnalysis {\n const segmenter = getSegmenter(chunk.locale);\n const segments: string[] = [];\n for (const part of segmenter.segment(chunk.text)) {\n if (part.isWordLike) {\n segments.push(part.segment);\n }\n }\n return {\n locale: chunk.locale,\n text: chunk.text,\n segments,\n words: segments.length,\n };\n}\n\nexport function aggregateByLocale(\n chunks: ChunkAnalysis[]\n): CollectorBreakdown[] {\n const order: string[] = [];\n const map = new Map<string, CollectorBreakdown>();\n\n for (const chunk of chunks) {\n const existing = map.get(chunk.locale);\n if (existing) {\n existing.words += chunk.words;\n existing.segments.push(...chunk.segments);\n continue;\n }\n\n order.push(chunk.locale);\n map.set(chunk.locale, {\n locale: chunk.locale,\n words: chunk.words,\n segments: [...chunk.segments],\n });\n }\n\n return order.map((locale) => map.get(locale)!);\n}\n","export const DEFAULT_LOCALE = \"und-Latn\";\n\nconst regex = {\n hiragana: /\\p{Script=Hiragana}/u,\n katakana: /\\p{Script=Katakana}/u,\n hangul: /\\p{Script=Hangul}/u,\n han: /\\p{Script=Han}/u,\n latin: /\\p{Script=Latin}/u,\n arabic: /\\p{Script=Arabic}/u,\n cyrillic: /\\p{Script=Cyrillic}/u,\n devanagari: /\\p{Script=Devanagari}/u,\n thai: /\\p{Script=Thai}/u,\n};\n\nconst latinLocaleHints: Array<{ locale: string; regex: RegExp }> = [\n { locale: \"de\", regex: /[äöüÄÖÜß]/ },\n { locale: \"es\", regex: /[ñÑ¿¡]/ },\n { locale: \"pt\", regex: /[ãõÃÕ]/ },\n { locale: \"fr\", regex: /[œŒæÆ]/ },\n];\n\nconst latinLocales = new Set<string>([\n DEFAULT_LOCALE,\n ...latinLocaleHints.map((hint) => hint.locale),\n]);\n\nexport function isLatinLocale(locale: string): boolean {\n return latinLocales.has(locale);\n}\n\nfunction detectLatinLocale(char: string): string {\n for (const hint of latinLocaleHints) {\n if (hint.regex.test(char)) {\n return hint.locale;\n }\n }\n return DEFAULT_LOCALE;\n}\n\nexport function detectLocaleForChar(\n char: string,\n previousLocale?: string | null\n): string | null {\n if (regex.hiragana.test(char) || regex.katakana.test(char)) {\n return \"ja\";\n }\n if (regex.hangul.test(char)) {\n return \"ko\";\n }\n if (regex.arabic.test(char)) {\n return \"ar\";\n }\n if (regex.cyrillic.test(char)) {\n return \"ru\";\n }\n if (regex.devanagari.test(char)) {\n return \"hi\";\n }\n if (regex.thai.test(char)) {\n return \"th\";\n }\n\n if (regex.han.test(char)) {\n if (previousLocale && previousLocale.startsWith(\"ja\")) {\n return previousLocale;\n }\n return \"zh-Hans\";\n }\n\n if (regex.latin.test(char)) {\n const hintedLocale = detectLatinLocale(char);\n if (hintedLocale !== DEFAULT_LOCALE) {\n return hintedLocale;\n }\n if (previousLocale && isLatinLocale(previousLocale)) {\n return previousLocale;\n }\n return DEFAULT_LOCALE;\n }\n\n return null;\n}\n","import { DEFAULT_LOCALE, detectLocaleForChar, isLatinLocale } from \"./locale-detect\";\nimport type { LocaleChunk } from \"./types\";\n\nexport function segmentTextByLocale(text: string): LocaleChunk[] {\n const chunks: LocaleChunk[] = [];\n // Keep currentLocale as a non-null string to simplify type-narrowing.\n let currentLocale: string = DEFAULT_LOCALE;\n let buffer = \"\";\n\n for (const char of text) {\n const detected = detectLocaleForChar(char, currentLocale);\n const targetLocale = detected ?? currentLocale;\n\n // If buffer is empty, this is the first character for a new chunk.\n if (buffer === \"\") {\n currentLocale = targetLocale;\n buffer = char;\n continue;\n }\n\n if (targetLocale !== currentLocale && detected !== null) {\n if (currentLocale === DEFAULT_LOCALE && isLatinLocale(targetLocale)) {\n currentLocale = targetLocale;\n buffer += char;\n continue;\n }\n // currentLocale is guaranteed to be a string here.\n chunks.push({ locale: currentLocale, text: buffer });\n currentLocale = targetLocale;\n buffer = char;\n continue;\n }\n\n buffer += char;\n }\n\n if (buffer.length > 0) {\n chunks.push({ locale: currentLocale, text: buffer });\n }\n\n return mergeAdjacentChunks(chunks);\n}\n\nfunction mergeAdjacentChunks(chunks: LocaleChunk[]): LocaleChunk[] {\n if (chunks.length === 0) {\n return chunks;\n }\n\n const merged: LocaleChunk[] = [];\n // We already returned for empty arrays above, so the first element is present.\n let last = chunks[0]!;\n\n for (let i = 1; i < chunks.length; i++) {\n const chunk = chunks[i]!;\n if (chunk.locale === last.locale) {\n last = { locale: last.locale, text: last.text + chunk.text };\n } else {\n merged.push(last);\n last = chunk;\n }\n }\n\n merged.push(last);\n return merged;\n}\n","import { analyzeChunk, aggregateByLocale } from \"./analyze\";\nimport { segmentTextByLocale } from \"./segment\";\nimport { countWordsForLocale } from \"./segmenter\";\nimport type {\n ChunkBreakdown,\n ChunkWithSegments,\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n} from \"./types\";\n\nexport type {\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./types\";\n\nexport { countWordsForLocale, segmentTextByLocale };\n\nexport function wordCounter(\n text: string,\n options: WordCounterOptions = {}\n): WordCounterResult {\n const mode: WordCounterMode = options.mode ?? \"chunk\";\n const chunks = segmentTextByLocale(text);\n const analyzed = chunks.map(analyzeChunk);\n const total = analyzed.reduce((sum, chunk) => sum + chunk.words, 0);\n\n if (mode === \"segments\") {\n const items: ChunkWithSegments[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n segments: chunk.segments,\n }));\n return {\n total,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n if (mode === \"collector\") {\n const items = aggregateByLocale(analyzed);\n return {\n total,\n breakdown: {\n mode,\n items,\n },\n };\n }\n\n const items: ChunkBreakdown[] = analyzed.map((chunk) => ({\n locale: chunk.locale,\n text: chunk.text,\n words: chunk.words,\n }));\n\n return {\n total,\n breakdown: {\n mode,\n items,\n },\n };\n}\n","import { wordCounter } from \"./wc\";\n\nexport default wordCounter;\nexport { countWordsForLocale, segmentTextByLocale } from \"./wc\";\nexport type {\n WordCounterMode,\n WordCounterOptions,\n WordCounterResult,\n WordCounterBreakdown,\n} from \"./wc\";\n","export function ensureArrayContainer(\n result: Record<string, unknown>,\n key: string,\n): Record<string, unknown>[] {\n const existing = result[key];\n if (Array.isArray(existing)) {\n return existing as Record<string, unknown>[];\n }\n const list: Record<string, unknown>[] = [];\n result[key] = list;\n return list;\n}\n\nexport function flattenArrayTables(result: Record<string, unknown>): void {\n for (const [key, value] of Object.entries(result)) {\n if (!Array.isArray(value)) {\n continue;\n }\n const flattened = value\n .map((entry) =>\n Object.entries(entry)\n .map(([entryKey, entryValue]) => `${entryKey}=${entryValue}`)\n .join(\", \"),\n )\n .join(\" | \");\n result[key] = flattened;\n }\n}\n","function stripKeyQuotes(key: string): string {\n const trimmed = key.trim();\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n return trimmed;\n}\n\nexport function normalizeKeyPath(key: string): string | null {\n const trimmed = key.trim();\n if (!trimmed) {\n return null;\n }\n\n if (\n (trimmed.startsWith(\"\\\"\") && trimmed.endsWith(\"\\\"\")) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n const unquoted = stripKeyQuotes(trimmed);\n return unquoted ? unquoted : null;\n }\n\n const segments = trimmed.split(\".\").map((segment) => segment.trim());\n if (segments.some((segment) => !segment)) {\n return null;\n }\n return segments.join(\".\");\n}\n","export function stripInlineComment(line: string): string {\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < line.length; i += 1) {\n const char = line[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n continue;\n }\n\n if (inString === \"single\" && char === \"'\") {\n inString = null;\n continue;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n continue;\n }\n\n if (char === \"#\") {\n return line.slice(0, i).trimEnd();\n }\n }\n\n return line;\n}\n\nfunction unescapeBasic(input: string): string {\n return input\n .replace(/\\\\\\\\/g, \"\\\\\")\n .replace(/\\\\\"/g, \"\\\"\")\n .replace(/\\\\n/g, \"\\n\")\n .replace(/\\\\t/g, \"\\t\")\n .replace(/\\\\r/g, \"\\r\");\n}\n\nexport function parseStringLiteral(value: string): string | null {\n if (value.startsWith('\"\"\"') && value.endsWith('\"\"\"')) {\n const inner = value.slice(3, -3);\n return unescapeBasic(inner);\n }\n\n if (value.startsWith(\"'''\") && value.endsWith(\"'''\")) {\n return value.slice(3, -3);\n }\n\n if (value.startsWith(\"\\\"\") && value.endsWith(\"\\\"\")) {\n return unescapeBasic(value.slice(1, -1));\n }\n\n if (value.startsWith(\"'\") && value.endsWith(\"'\")) {\n return value.slice(1, -1);\n }\n\n return null;\n}\n","import { normalizeKeyPath } from \"./keys\";\nimport { parseStringLiteral } from \"./strings\";\nimport type { TomlValue } from \"./types\";\n\nfunction parsePrimitive(raw: string): string | number | boolean | null {\n const value = raw.trim();\n if (!value) {\n return null;\n }\n\n const stringLiteral = parseStringLiteral(value);\n if (stringLiteral !== null) {\n return stringLiteral;\n }\n\n if (value === \"true\") {\n return true;\n }\n\n if (value === \"false\") {\n return false;\n }\n\n if (/^[+-]?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/.test(value)) {\n return Number(value);\n }\n\n if (/^\\d{4}-\\d{2}-\\d{2}/.test(value)) {\n return value;\n }\n\n return value;\n}\n\nfunction parseArray(raw: string): Array<string | number | boolean> | null {\n const value = raw.trim();\n if (!value.startsWith(\"[\") || !value.endsWith(\"]\")) {\n return null;\n }\n\n const inner = value.slice(1, -1).trim();\n if (!inner) {\n return [];\n }\n\n const items: Array<string | number | boolean> = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \",\") {\n const item = parsePrimitive(current);\n if (item === null) {\n return null;\n }\n items.push(item);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n const finalItem = parsePrimitive(current);\n if (finalItem === null) {\n return null;\n }\n items.push(finalItem);\n\n return items;\n}\n\nfunction parseInlineTable(raw: string): Record<string, TomlValue> | null {\n const trimmed = raw.trim();\n if (!trimmed.startsWith(\"{\") || !trimmed.endsWith(\"}\")) {\n return null;\n }\n\n const inner = trimmed.slice(1, -1).trim();\n if (!inner) {\n return {};\n }\n\n const pairs: string[] = [];\n let current = \"\";\n let inString: \"single\" | \"double\" | null = null;\n let escaped = false;\n let bracketDepth = 0;\n let braceDepth = 0;\n\n for (let i = 0; i < inner.length; i += 1) {\n const char = inner[i] ?? \"\";\n\n if (inString) {\n current += char;\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\" && inString === \"double\") {\n escaped = true;\n continue;\n }\n\n if (inString === \"double\" && char === \"\\\"\") {\n inString = null;\n } else if (inString === \"single\" && char === \"'\") {\n inString = null;\n }\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = \"double\";\n current += char;\n continue;\n }\n\n if (char === \"'\") {\n inString = \"single\";\n current += char;\n continue;\n }\n\n if (char === \"[\") {\n bracketDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"]\") {\n if (bracketDepth > 0) {\n bracketDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \"{\") {\n braceDepth += 1;\n current += char;\n continue;\n }\n\n if (char === \"}\") {\n if (braceDepth > 0) {\n braceDepth -= 1;\n }\n current += char;\n continue;\n }\n\n if (char === \",\" && bracketDepth === 0 && braceDepth === 0) {\n pairs.push(current);\n current = \"\";\n continue;\n }\n\n current += char;\n }\n\n if (current.trim()) {\n pairs.push(current);\n }\n\n const output: Record<string, TomlValue> = {};\n for (const pair of pairs) {\n const separatorIndex = pair.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n const key = normalizeKeyPath(pair.slice(0, separatorIndex));\n if (!key) {\n return null;\n }\n const valueRaw = pair.slice(separatorIndex + 1).trim();\n if (!valueRaw) {\n return null;\n }\n if (valueRaw.startsWith(\"{\")) {\n return null;\n }\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n return null;\n }\n output[key] = normalized;\n }\n\n return output;\n}\n\nexport function normalizeValue(value: string): TomlValue | null {\n if (!value) {\n return null;\n }\n\n const trimmed = value.trim();\n if (trimmed.startsWith(\"{\") && trimmed.endsWith(\"}\")) {\n return parseInlineTable(trimmed);\n }\n\n const array = parseArray(trimmed);\n if (array) {\n return array;\n }\n\n if (trimmed.startsWith(\"[\") && trimmed.endsWith(\"]\")) {\n return null;\n }\n\n return parsePrimitive(trimmed);\n}\n\nexport function toPlainText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (Array.isArray(value)) {\n return value.map((item) => String(item)).join(\", \");\n }\n return String(value);\n}\n","import { ensureArrayContainer, flattenArrayTables } from \"./arrays\";\nimport { normalizeKeyPath } from \"./keys\";\nimport { stripInlineComment } from \"./strings\";\nimport { normalizeValue, toPlainText } from \"./values\";\n\nexport function parseTomlFrontmatter(frontmatter: string): Record<string, unknown> | null {\n const result: Record<string, unknown> = {};\n const lines = frontmatter.split(\"\\n\");\n let tablePrefix = \"\";\n let tableTarget: Record<string, unknown> | null = null;\n let tablePrefixInList = false;\n\n for (let index = 0; index < lines.length; index += 1) {\n const rawLine = lines[index] ?? \"\";\n const trimmedLine = rawLine.trim();\n if (!trimmedLine || trimmedLine.startsWith(\"#\")) {\n continue;\n }\n\n if (trimmedLine.startsWith(\"[[\")) {\n const match = trimmedLine.match(/^\\[\\[([^\\]]+)]]$/);\n if (!match) {\n return null;\n }\n const normalizedTable = normalizeKeyPath(match[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n const list = ensureArrayContainer(result, normalizedTable);\n const newEntry: Record<string, unknown> = {};\n list.push(newEntry);\n tableTarget = newEntry;\n tablePrefix = normalizedTable;\n tablePrefixInList = true;\n continue;\n }\n\n const tableMatch = trimmedLine.match(/^\\[([^\\]]+)]$/);\n if (tableMatch) {\n const normalizedTable = normalizeKeyPath(tableMatch[1] ?? \"\");\n if (!normalizedTable) {\n return null;\n }\n tablePrefix = normalizedTable;\n tablePrefixInList = false;\n tableTarget = null;\n continue;\n }\n\n const lineForParsing = /(\"\"\"|''')/.test(rawLine) ? rawLine : stripInlineComment(rawLine);\n const separatorIndex = lineForParsing.indexOf(\"=\");\n if (separatorIndex === -1) {\n return null;\n }\n\n const keyRaw = lineForParsing.slice(0, separatorIndex);\n const key = normalizeKeyPath(keyRaw);\n let valueRaw = lineForParsing.slice(separatorIndex + 1).trim();\n if (!key) {\n return null;\n }\n\n const tripleDelimiter = valueRaw.startsWith('\"\"\"') ? '\"\"\"' : valueRaw.startsWith(\"'''\") ? \"'''\" : null;\n if (tripleDelimiter) {\n const closingIndex = valueRaw.indexOf(tripleDelimiter, tripleDelimiter.length);\n if (closingIndex !== -1) {\n const after = valueRaw.slice(closingIndex + tripleDelimiter.length);\n const strippedAfter = stripInlineComment(after);\n valueRaw = `${valueRaw.slice(0, closingIndex + tripleDelimiter.length)}${strippedAfter}`;\n } else {\n const delimiter = tripleDelimiter;\n let combined = valueRaw;\n let closed = false;\n while (index + 1 < lines.length) {\n index += 1;\n const nextLine = lines[index] ?? \"\";\n combined += `\\n${nextLine}`;\n if (new RegExp(`${delimiter}\\\\s*$`).test(nextLine)) {\n closed = true;\n break;\n }\n }\n if (!closed) {\n return null;\n }\n valueRaw = combined;\n }\n }\n\n const normalized = normalizeValue(valueRaw);\n if (normalized === null) {\n return null;\n }\n\n const fullKey = tablePrefix ? `${tablePrefix}.${key}` : key;\n if (typeof normalized === \"object\" && !Array.isArray(normalized)) {\n for (const [inlineKey, inlineValue] of Object.entries(normalized)) {\n const entryKey = tablePrefixInList ? `${key}.${inlineKey}` : `${fullKey}.${inlineKey}`;\n if (tablePrefixInList && tableTarget) {\n tableTarget[entryKey] = toPlainText(inlineValue);\n } else {\n result[entryKey] = toPlainText(inlineValue);\n }\n }\n continue;\n }\n\n if (tablePrefixInList && tableTarget) {\n tableTarget[key] = toPlainText(normalized);\n continue;\n }\n\n result[fullKey] = toPlainText(normalized);\n }\n\n flattenArrayTables(result);\n\n return result;\n}\n","import { parseDocument } from \"yaml\";\nimport { parseTomlFrontmatter } from \"./toml-simple\";\nimport type { FrontmatterType, ParsedMarkdown } from \"./types\";\n\nconst FENCE_TO_TYPE: Record<string, FrontmatterType> = {\n \"---\": \"yaml\",\n \"+++\": \"toml\",\n \";;;\": \"json\",\n};\n\nfunction normalizeNewlines(input: string): string {\n return input.replace(/\\r\\n/g, \"\\n\");\n}\n\nfunction stripBom(line: string): string {\n return line.startsWith(\"\\uFEFF\") ? line.slice(1) : line;\n}\n\nfunction getFenceType(line: string): FrontmatterType | null {\n const match = line.match(/^[\\t ]*(---|\\+\\+\\+|;;;)[\\t ]*$/);\n if (!match) {\n return null;\n }\n return FENCE_TO_TYPE[match[1] ?? \"\"] ?? null;\n}\n\nfunction parseFrontmatter(frontmatter: string, type: FrontmatterType | null): Record<string, unknown> | null {\n if (!type) {\n return null;\n }\n\n if (type === \"json\") {\n try {\n return JSON.parse(frontmatter) as Record<string, unknown>;\n } catch {\n return null;\n }\n }\n\n if (type === \"yaml\") {\n const doc = parseDocument(frontmatter, { prettyErrors: false });\n if (doc.errors.length > 0) {\n return null;\n }\n const data = doc.toJSON();\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return null;\n }\n return data as Record<string, unknown>;\n }\n\n if (type === \"toml\") {\n return parseTomlFrontmatter(frontmatter);\n }\n\n return null;\n}\n\nfunction extractJsonBlock(text: string, startIndex: number): { jsonText: string; endIndex: number } | null {\n let depth = 0;\n let inString = false;\n let escaped = false;\n\n for (let i = startIndex; i < text.length; i += 1) {\n const char = text[i] ?? \"\";\n\n if (inString) {\n if (escaped) {\n escaped = false;\n continue;\n }\n\n if (char === \"\\\\\") {\n escaped = true;\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = false;\n }\n\n continue;\n }\n\n if (char === \"\\\"\") {\n inString = true;\n continue;\n }\n\n if (char === \"{\") {\n depth += 1;\n continue;\n }\n\n if (char === \"}\") {\n depth -= 1;\n if (depth === 0) {\n const jsonText = text.slice(startIndex, i + 1);\n return { jsonText, endIndex: i };\n }\n }\n }\n\n return null;\n}\n\nexport function parseMarkdown(input: string): ParsedMarkdown {\n const normalized = normalizeNewlines(input);\n const lines = normalized.split(\"\\n\");\n if (lines.length === 0) {\n return { frontmatter: null, content: normalized, data: null, frontmatterType: null };\n }\n\n lines[0] = stripBom(lines[0] ?? \"\");\n const normalizedWithoutBom = lines.join(\"\\n\");\n\n const openingType = getFenceType(lines[0] ?? \"\");\n if (!openingType) {\n const leadingWhitespace = normalizedWithoutBom.match(/^[\\t \\n]*/)?.[0] ?? \"\";\n const jsonStart = leadingWhitespace.length;\n if (normalizedWithoutBom[jsonStart] !== \"{\") {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const jsonBlock = extractJsonBlock(normalizedWithoutBom, jsonStart);\n if (!jsonBlock) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = jsonBlock.jsonText;\n let content = normalizedWithoutBom.slice(jsonBlock.endIndex + 1);\n if (content.startsWith(\"\\n\")) {\n content = content.slice(1);\n }\n const data = parseFrontmatter(frontmatter, \"json\");\n if (!data) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: \"json\",\n };\n }\n\n let closingIndex = -1;\n for (let i = 1; i < lines.length; i += 1) {\n if (getFenceType(lines[i] ?? \"\") === openingType) {\n closingIndex = i;\n break;\n }\n }\n\n if (closingIndex === -1) {\n return { frontmatter: null, content: normalizedWithoutBom, data: null, frontmatterType: null };\n }\n\n const frontmatter = lines.slice(1, closingIndex).join(\"\\n\");\n const content = lines.slice(closingIndex + 1).join(\"\\n\");\n const data = parseFrontmatter(frontmatter, openingType);\n\n return {\n frontmatter,\n content,\n data,\n frontmatterType: openingType,\n };\n}\n","import type { WordCounterMode, WordCounterResult } from \"../wc/types\";\nimport wordCounter from \"../wc\";\nimport { parseMarkdown } from \"./parse-markdown\";\nimport type { SectionMode, SectionedResult } from \"./types\";\n\nfunction normalizeText(value: unknown): string {\n if (value == null) {\n return \"\";\n }\n if (typeof value === \"string\") {\n return value;\n }\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction buildPerKeyItems(\n data: Record<string, unknown> | null,\n mode: WordCounterMode,\n): Array<{ name: string; source: \"frontmatter\"; result: WordCounterResult }> {\n if (!data || typeof data !== \"object\" || Array.isArray(data)) {\n return [];\n }\n\n return Object.entries(data).map(([key, value]) => {\n const valueText = normalizeText(value);\n const text = valueText ? `${key}: ${valueText}` : key;\n return {\n name: key,\n source: \"frontmatter\",\n result: wordCounter(text, { mode }),\n };\n });\n}\n\nfunction buildSingleItem(\n name: string,\n text: string,\n mode: WordCounterMode,\n source: \"frontmatter\" | \"content\",\n) {\n return [{ name, source, result: wordCounter(text, { mode }) }];\n}\n\nfunction sumTotals(items: Array<{ result: WordCounterResult }>): number {\n return items.reduce((sum, item) => sum + item.result.total, 0);\n}\n\nexport function countSections(\n input: string,\n section: SectionMode,\n mode: WordCounterMode,\n): SectionedResult {\n if (section === \"all\") {\n const result = wordCounter(input, { mode });\n return {\n section,\n total: result.total,\n frontmatterType: null,\n items: [{ name: \"all\", source: \"content\", result }],\n };\n }\n\n const parsed = parseMarkdown(input);\n const frontmatterText = parsed.frontmatter ?? \"\";\n const contentText = parsed.content ?? \"\";\n\n let items: Array<{ name: string; source: \"frontmatter\" | \"content\"; result: WordCounterResult }> = [];\n\n if (section === \"frontmatter\") {\n items = buildSingleItem(\"frontmatter\", frontmatterText, mode, \"frontmatter\");\n } else if (section === \"content\") {\n items = buildSingleItem(\"content\", contentText, mode, \"content\");\n } else if (section === \"split\") {\n items = [\n ...buildSingleItem(\"frontmatter\", frontmatterText, mode, \"frontmatter\"),\n ...buildSingleItem(\"content\", contentText, mode, \"content\"),\n ];\n } else if (section === \"per-key\") {\n items = buildPerKeyItems(parsed.data, mode);\n } else if (section === \"split-per-key\") {\n items = [\n ...buildPerKeyItems(parsed.data, mode),\n ...buildSingleItem(\"content\", contentText, mode, \"content\"),\n ];\n }\n\n return {\n section,\n total: sumTotals(items),\n frontmatterType: parsed.frontmatterType,\n items,\n };\n}\n","let p = process || {}, argv = p.argv || [], env = p.env || {}\nlet isColorSupported =\n\t!(!!env.NO_COLOR || argv.includes(\"--no-color\")) &&\n\t(!!env.FORCE_COLOR || argv.includes(\"--color\") || p.platform === \"win32\" || ((p.stdout || {}).isTTY && env.TERM !== \"dumb\") || !!env.CI)\n\nlet formatter = (open, close, replace = open) =>\n\tinput => {\n\t\tlet string = \"\" + input, index = string.indexOf(close, open.length)\n\t\treturn ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close\n\t}\n\nlet replaceClose = (string, close, replace, index) => {\n\tlet result = \"\", cursor = 0\n\tdo {\n\t\tresult += string.substring(cursor, index) + replace\n\t\tcursor = index + close.length\n\t\tindex = string.indexOf(close, cursor)\n\t} while (~index)\n\treturn result + string.substring(cursor)\n}\n\nlet createColors = (enabled = isColorSupported) => {\n\tlet f = enabled ? formatter : () => String\n\treturn {\n\t\tisColorSupported: enabled,\n\t\treset: f(\"\\x1b[0m\", \"\\x1b[0m\"),\n\t\tbold: f(\"\\x1b[1m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[1m\"),\n\t\tdim: f(\"\\x1b[2m\", \"\\x1b[22m\", \"\\x1b[22m\\x1b[2m\"),\n\t\titalic: f(\"\\x1b[3m\", \"\\x1b[23m\"),\n\t\tunderline: f(\"\\x1b[4m\", \"\\x1b[24m\"),\n\t\tinverse: f(\"\\x1b[7m\", \"\\x1b[27m\"),\n\t\thidden: f(\"\\x1b[8m\", \"\\x1b[28m\"),\n\t\tstrikethrough: f(\"\\x1b[9m\", \"\\x1b[29m\"),\n\n\t\tblack: f(\"\\x1b[30m\", \"\\x1b[39m\"),\n\t\tred: f(\"\\x1b[31m\", \"\\x1b[39m\"),\n\t\tgreen: f(\"\\x1b[32m\", \"\\x1b[39m\"),\n\t\tyellow: f(\"\\x1b[33m\", \"\\x1b[39m\"),\n\t\tblue: f(\"\\x1b[34m\", \"\\x1b[39m\"),\n\t\tmagenta: f(\"\\x1b[35m\", \"\\x1b[39m\"),\n\t\tcyan: f(\"\\x1b[36m\", \"\\x1b[39m\"),\n\t\twhite: f(\"\\x1b[37m\", \"\\x1b[39m\"),\n\t\tgray: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\n\t\tbgBlack: f(\"\\x1b[40m\", \"\\x1b[49m\"),\n\t\tbgRed: f(\"\\x1b[41m\", \"\\x1b[49m\"),\n\t\tbgGreen: f(\"\\x1b[42m\", \"\\x1b[49m\"),\n\t\tbgYellow: f(\"\\x1b[43m\", \"\\x1b[49m\"),\n\t\tbgBlue: f(\"\\x1b[44m\", \"\\x1b[49m\"),\n\t\tbgMagenta: f(\"\\x1b[45m\", \"\\x1b[49m\"),\n\t\tbgCyan: f(\"\\x1b[46m\", \"\\x1b[49m\"),\n\t\tbgWhite: f(\"\\x1b[47m\", \"\\x1b[49m\"),\n\n\t\tblackBright: f(\"\\x1b[90m\", \"\\x1b[39m\"),\n\t\tredBright: f(\"\\x1b[91m\", \"\\x1b[39m\"),\n\t\tgreenBright: f(\"\\x1b[92m\", \"\\x1b[39m\"),\n\t\tyellowBright: f(\"\\x1b[93m\", \"\\x1b[39m\"),\n\t\tblueBright: f(\"\\x1b[94m\", \"\\x1b[39m\"),\n\t\tmagentaBright: f(\"\\x1b[95m\", \"\\x1b[39m\"),\n\t\tcyanBright: f(\"\\x1b[96m\", \"\\x1b[39m\"),\n\t\twhiteBright: f(\"\\x1b[97m\", \"\\x1b[39m\"),\n\n\t\tbgBlackBright: f(\"\\x1b[100m\", \"\\x1b[49m\"),\n\t\tbgRedBright: f(\"\\x1b[101m\", \"\\x1b[49m\"),\n\t\tbgGreenBright: f(\"\\x1b[102m\", \"\\x1b[49m\"),\n\t\tbgYellowBright: f(\"\\x1b[103m\", \"\\x1b[49m\"),\n\t\tbgBlueBright: f(\"\\x1b[104m\", \"\\x1b[49m\"),\n\t\tbgMagentaBright: f(\"\\x1b[105m\", \"\\x1b[49m\"),\n\t\tbgCyanBright: f(\"\\x1b[106m\", \"\\x1b[49m\"),\n\t\tbgWhiteBright: f(\"\\x1b[107m\", \"\\x1b[49m\"),\n\t}\n}\n\nmodule.exports = createColors()\nmodule.exports.createColors = createColors\n","import { Command, Option } from \"commander\";\nimport { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve as resolvePath } from \"node:path\";\nimport { showSingularOrPluralWord } from \"./utils\";\nimport wordCounter, { type WordCounterMode, type WordCounterResult } from \"./wc\";\nimport { countSections } from \"./markdown\";\nimport type { SectionMode, SectionedResult } from \"./markdown\";\nimport pc from \"picocolors\";\n\ntype OutputFormat = \"standard\" | \"raw\" | \"json\";\n\nconst MODE_CHOICES: WordCounterMode[] = [\"chunk\", \"segments\", \"collector\"];\nconst FORMAT_CHOICES: OutputFormat[] = [\"standard\", \"raw\", \"json\"];\nconst SECTION_CHOICES: SectionMode[] = [\n \"all\",\n \"split\",\n \"frontmatter\",\n \"content\",\n \"per-key\",\n \"split-per-key\",\n];\n\nfunction getPackageVersion(): string {\n const packageUrl = new URL(\"../../package.json\", import.meta.url);\n const raw = readFileSync(packageUrl, \"utf8\");\n const data = JSON.parse(raw) as { version?: string };\n const version = data.version ?? \"0.0.0\";\n return pc.bgBlack(pc.bold(pc.italic(` word-counter ${pc.cyanBright(`ver.${version}`)} `)));\n}\n\nfunction renderChunkBreakdown(items: Array<{ locale: string; words: number }>): void {\n for (const item of items) {\n console.log(`Locale ${item.locale}: ${showSingularOrPluralWord(item.words, \"word\")}`);\n }\n}\n\nfunction renderSegmentBreakdown(\n items: Array<{ locale: string; words: number; segments: string[] }>,\n): void {\n for (const item of items) {\n console.log(\n `Locale ${item.locale}: ${JSON.stringify(item.segments)} (${showSingularOrPluralWord(item.words, \"word\")})`,\n );\n }\n}\n\nfunction renderCollectorBreakdown(items: Array<{ locale: string; words: number }>): void {\n for (const item of items) {\n console.log(`Locale ${item.locale}: ${showSingularOrPluralWord(item.words, \"word\")}`);\n }\n}\n\nfunction renderStandardResult(result: WordCounterResult): void {\n console.log(`Total words: ${result.total}`);\n\n if (result.breakdown.mode === \"segments\") {\n renderSegmentBreakdown(result.breakdown.items);\n return;\n }\n\n if (result.breakdown.mode === \"collector\") {\n renderCollectorBreakdown(result.breakdown.items);\n return;\n }\n\n renderChunkBreakdown(result.breakdown.items);\n}\n\nfunction buildSectionLabel(\n sectionName: string,\n sectionMode: SectionMode,\n source: \"frontmatter\" | \"content\",\n): string {\n if (sectionMode === \"frontmatter\") {\n return `[Frontmatter] (total)`;\n }\n\n if (sectionMode === \"content\") {\n return `[Content] (total)`;\n }\n\n if (sectionMode === \"split\") {\n if (source === \"frontmatter\") {\n return `[Frontmatter] (total)`;\n }\n return `[Content] (total)`;\n }\n\n if (sectionMode === \"per-key\") {\n return `[Frontmatter] ${sectionName} (total)`;\n }\n\n if (sectionMode === \"split-per-key\") {\n if (source === \"content\") {\n return `[Content] (total)`;\n }\n return `[Frontmatter] ${sectionName} (total)`;\n }\n\n return `[Section] ${sectionName} (total)`;\n}\n\nfunction renderStandardSectionedResult(result: SectionedResult): void {\n console.log(`Total words: ${result.total}`);\n\n for (const item of result.items) {\n const label = buildSectionLabel(item.name, result.section, item.source);\n console.log(pc.cyan(pc.bold(`${label}: ${showSingularOrPluralWord(item.result.total, \"word\")}`)));\n\n if (item.result.breakdown.mode === \"segments\") {\n renderSegmentBreakdown(item.result.breakdown.items);\n continue;\n }\n\n if (item.result.breakdown.mode === \"collector\") {\n renderCollectorBreakdown(item.result.breakdown.items);\n continue;\n }\n\n renderChunkBreakdown(item.result.breakdown.items);\n }\n}\n\nfunction isSectionedResult(\n result: WordCounterResult | SectionedResult,\n): result is SectionedResult {\n return \"section\" in result;\n}\n\nasync function readStdin(): Promise<string> {\n if (process.stdin.isTTY) {\n return \"\";\n }\n\n return new Promise<string>((resolve, reject) => {\n const chunks: string[] = [];\n process.stdin.setEncoding(\"utf8\");\n process.stdin.on(\"data\", (chunk) => chunks.push(String(chunk)));\n process.stdin.on(\"end\", () => resolve(chunks.join(\"\")));\n process.stdin.on(\"error\", (error) => reject(error));\n process.stdin.resume();\n });\n}\n\nasync function resolveInput(textTokens: string[], pathInput?: string): Promise<string> {\n if (pathInput) {\n const resolved = resolvePath(pathInput);\n return readFile(resolved, \"utf8\");\n }\n\n if (textTokens.length > 0) {\n return textTokens.join(\" \");\n }\n\n return readStdin();\n}\n\nexport async function runCli(argv: string[] = process.argv): Promise<void> {\n const program = new Command();\n\n program\n .name(\"word-counter\")\n .description(\"Locale-aware word counting powered by Intl.Segmenter.\")\n .version(getPackageVersion(), \"-v, --version\", \"output the version number\")\n .addOption(\n new Option(\"-m, --mode <mode>\", \"breakdown mode\").choices(MODE_CHOICES).default(\"chunk\"),\n )\n .addOption(\n new Option(\"-f, --format <format>\", \"output format\")\n .choices(FORMAT_CHOICES)\n .default(\"standard\"),\n )\n .addOption(\n new Option(\"--section <section>\", \"document section mode\")\n .choices(SECTION_CHOICES)\n .default(\"all\"),\n )\n .option(\"--pretty\", \"pretty print JSON output\", false)\n .option(\"-p, --path <file>\", \"read input from a text file\")\n .argument(\"[text...]\", \"text to count\")\n .showHelpAfterError();\n\n program.action(\n async (\n textTokens: string[],\n options: {\n mode: WordCounterMode;\n format: OutputFormat;\n pretty: boolean;\n section: SectionMode;\n path?: string;\n },\n ) => {\n let input: string;\n try {\n input = await resolveInput(textTokens, options.path);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n program.error(`Failed to read input: ${message}`);\n return;\n }\n\n const trimmed = input.trim();\n if (!trimmed) {\n program.error(pc.red(\"No input provided. Pass text, pipe stdin, or use --path.\"));\n return;\n }\n\n const useSection = options.section !== \"all\";\n const result: WordCounterResult | SectionedResult = useSection\n ? countSections(trimmed, options.section, options.mode)\n : wordCounter(trimmed, { mode: options.mode });\n\n if (options.format === \"raw\") {\n console.log(result.total);\n return;\n }\n\n if (options.format === \"json\") {\n const spacing = options.pretty ? 2 : 0;\n console.log(JSON.stringify(result, null, spacing));\n return;\n }\n\n if (isSectionedResult(result)) {\n renderStandardSectionedResult(result);\n return;\n }\n\n renderStandardResult(result);\n },\n );\n\n await program.parseAsync(argv);\n}\n","import { runCli } from \"./command\";\n\nrunCli().catch((error) => {\n const message = error instanceof Error ? error.message : String(error);\n console.error(\"Failed to run CLI:\", message);\n process.exitCode = 1;\n});\n"],"x_google_ignoreList":[14],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAgB,yBAAyB,OAAe,MAAsB;AAC5E,QAAO,GAAG,MAAM,GAAG,OAAO,UAAU,IAAI,KAAK;;;;;ACD/C,MAAM,iCAAiB,IAAI,KAA6B;AAExD,SAAgB,aAAa,QAAgC;CAC3D,MAAM,SAAS,eAAe,IAAI,OAAO;AACzC,KAAI,OACF,QAAO;CAET,MAAM,YAAY,IAAI,KAAK,UAAU,QAAQ,EAAE,aAAa,QAAQ,CAAC;AACrE,gBAAe,IAAI,QAAQ,UAAU;AACrC,QAAO;;;;;ACNT,SAAgB,aAAa,OAAmC;CAC9D,MAAM,YAAY,aAAa,MAAM,OAAO;CAC5C,MAAM,WAAqB,EAAE;AAC7B,MAAK,MAAM,QAAQ,UAAU,QAAQ,MAAM,KAAK,CAC9C,KAAI,KAAK,WACP,UAAS,KAAK,KAAK,Q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U,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,WAAQ,MAAM,yBAAyB,UAAU;AACjD;;EAGF,MAAM,UAAU,MAAM,MAAM;AAC5B,MAAI,CAAC,SAAS;AACZ,WAAQ,MAAMF,0BAAG,IAAI,2DAA2D,CAAC;AACjF;;EAIF,MAAM,SADa,QAAQ,YAAY,QAEnC,cAAc,SAAS,QAAQ,SAAS,QAAQ,KAAK,GACrDG,WAAY,SAAS,EAAE,MAAM,QAAQ,MAAM,CAAC;AAEhD,MAAI,QAAQ,WAAW,OAAO;AAC5B,WAAQ,IAAI,OAAO,MAAM;AACzB;;AAGF,MAAI,QAAQ,WAAW,QAAQ;GAC7B,MAAM,UAAU,QAAQ,SAAS,IAAI;AACrC,WAAQ,IAAI,KAAK,UAAU,QAAQ,MAAM,QAAQ,CAAC;AAClD;;AAGF,MAAI,kBAAkB,OAAO,EAAE;AAC7B,iCAA8B,OAAO;AACrC;;AAGF,uBAAqB,OAAO;GAE/B;AAED,OAAM,QAAQ,WAAW,KAAK;;;;;ACxOhC,QAAQ,CAAC,OAAO,UAAU;CACxB,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AACtE,SAAQ,MAAM,sBAAsB,QAAQ;AAC5C,SAAQ,WAAW;EACnB"}
@@ -0,0 +1,75 @@
1
+ //#region src/wc/types.d.ts
2
+ interface LocaleChunk {
3
+ locale: string;
4
+ text: string;
5
+ }
6
+ interface ChunkBreakdown extends LocaleChunk {
7
+ words: number;
8
+ }
9
+ interface ChunkWithSegments extends ChunkBreakdown {
10
+ segments: string[];
11
+ }
12
+ interface CollectorBreakdown {
13
+ locale: string;
14
+ words: number;
15
+ segments: string[];
16
+ }
17
+ type WordCounterMode = "chunk" | "segments" | "collector";
18
+ interface WordCounterOptions {
19
+ mode?: WordCounterMode;
20
+ }
21
+ type WordCounterBreakdown = {
22
+ mode: "chunk";
23
+ items: ChunkBreakdown[];
24
+ } | {
25
+ mode: "segments";
26
+ items: ChunkWithSegments[];
27
+ } | {
28
+ mode: "collector";
29
+ items: CollectorBreakdown[];
30
+ };
31
+ interface WordCounterResult {
32
+ total: number;
33
+ breakdown: WordCounterBreakdown;
34
+ }
35
+ //#endregion
36
+ //#region src/wc/segment.d.ts
37
+ declare function segmentTextByLocale(text: string): LocaleChunk[];
38
+ //#endregion
39
+ //#region src/wc/segmenter.d.ts
40
+ declare function countWordsForLocale(text: string, locale: string): number;
41
+ //#endregion
42
+ //#region src/wc/wc.d.ts
43
+ declare function wordCounter(text: string, options?: WordCounterOptions): WordCounterResult;
44
+ //#endregion
45
+ //#region src/utils/show-singular-or-plural-word.d.ts
46
+ declare function showSingularOrPluralWord(count: number, word: string): string;
47
+ //#endregion
48
+ //#region src/markdown/types.d.ts
49
+ type FrontmatterType = "yaml" | "toml" | "json";
50
+ interface ParsedMarkdown {
51
+ frontmatter: string | null;
52
+ content: string;
53
+ data: Record<string, unknown> | null;
54
+ frontmatterType: FrontmatterType | null;
55
+ }
56
+ type SectionMode = "all" | "split" | "frontmatter" | "content" | "per-key" | "split-per-key";
57
+ interface SectionedResult {
58
+ section: SectionMode;
59
+ total: number;
60
+ frontmatterType: FrontmatterType | null;
61
+ items: Array<{
62
+ name: string;
63
+ source: "frontmatter" | "content";
64
+ result: WordCounterResult;
65
+ }>;
66
+ }
67
+ //#endregion
68
+ //#region src/markdown/parse-markdown.d.ts
69
+ declare function parseMarkdown(input: string): ParsedMarkdown;
70
+ //#endregion
71
+ //#region src/markdown/section-count.d.ts
72
+ declare function countSections(input: string, section: SectionMode, mode: WordCounterMode): SectionedResult;
73
+ //#endregion
74
+ export { FrontmatterType, ParsedMarkdown, SectionMode, SectionedResult, type WordCounterBreakdown, type WordCounterMode, type WordCounterOptions, type WordCounterResult, countSections, countWordsForLocale, wordCounter as default, wordCounter, parseMarkdown, segmentTextByLocale, showSingularOrPluralWord };
75
+ //# sourceMappingURL=index.d.mts.map