json-term 1.0.0
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.
- package/LICENSE +21 -0
- package/README.md +176 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +718 -0
- package/dist/cli.js.map +1 -0
- package/dist/cli.mjs +695 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +111 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +638 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +592 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/formatter.ts","../src/differ.ts","../src/interactive.ts","../src/utils/clipboard.ts"],"sourcesContent":["export * from \"./types.js\";\nexport * from \"./formatter.js\";\nexport * from \"./differ.js\";\nexport * from \"./interactive.js\";\nexport * from \"./utils/clipboard.js\";\n","import pc from \"picocolors\";\nimport { JSONValueType, TreeNode } from \"./types.js\";\n\n/**\n * Determine the JSON value type.\n */\nexport function getValueType(value: any): JSONValueType {\n if (value === null || value === undefined) return \"null\";\n if (Array.isArray(value)) return \"array\";\n const t = typeof value;\n if (t === \"object\") return \"object\";\n if (t === \"string\") return \"string\";\n if (t === \"number\") return \"number\";\n if (t === \"boolean\") return \"boolean\";\n return \"string\";\n}\n\n/**\n * Colorize and format a single JSON value according to its type.\n */\nexport function formatValue(value: any, truncateLen = 80): string {\n const type = getValueType(value);\n\n switch (type) {\n case \"string\": {\n const str = JSON.stringify(value);\n const truncated = str.length > truncateLen ? str.slice(0, truncateLen - 3) + '...\"' : str;\n return pc.green(truncated);\n }\n case \"number\":\n return pc.yellow(String(value));\n case \"boolean\":\n return pc.magenta(String(value));\n case \"null\":\n return pc.dim(\"null\");\n case \"array\":\n return pc.dim(`[${value.length} items]`);\n case \"object\":\n return pc.dim(`{${Object.keys(value).length} keys}`);\n default:\n return String(value);\n }\n}\n\n/**\n * Format an object key with bold coloring.\n */\nexport function formatKey(key: string): string {\n return pc.bold(pc.cyan(key));\n}\n\n/**\n * Build a flat or nested TreeNode hierarchy from any JavaScript/JSON data.\n */\nexport function buildTree(\n data: any,\n key?: string,\n path = \"$\",\n depth = 0,\n maxInitialDepth = 2,\n parentId?: string\n): TreeNode {\n const type = getValueType(data);\n const id = `${path}-${key || \"root\"}-${depth}`;\n const collapsed = depth >= maxInitialDepth;\n\n const node: TreeNode = {\n id,\n key,\n value: data,\n type,\n depth,\n path,\n collapsed,\n parentId,\n };\n\n if (type === \"object\" && data !== null) {\n const keys = Object.keys(data);\n node.itemCount = keys.length;\n node.children = keys.map((k) =>\n buildTree(\n data[k],\n k,\n path === \"$\" ? k : `${path}.${k}`,\n depth + 1,\n maxInitialDepth,\n id\n )\n );\n } else if (type === \"array\") {\n node.itemCount = data.length;\n node.children = data.map((item: any, idx: number) =>\n buildTree(\n item,\n `[${idx}]`,\n `${path}[${idx}]`,\n depth + 1,\n maxInitialDepth,\n id\n )\n );\n }\n\n return node;\n}\n\n/**\n * Pretty-print JSON tree structure to terminal string.\n */\nexport function prettyPrintTree(node: TreeNode, indent = \"\", isLast = true): string {\n const isRoot = node.depth === 0;\n const marker = node.type === \"object\" || node.type === \"array\" ? (node.collapsed ? pc.cyan(\"▶ \") : pc.cyan(\"▼ \")) : pc.dim(\"• \");\n\n let line = \"\";\n if (!isRoot) {\n const branch = isLast ? \"└── \" : \"├── \";\n line += pc.dim(indent + branch) + marker;\n if (node.key) {\n line += formatKey(node.key) + pc.dim(\": \");\n }\n } else {\n line += marker + (node.key ? formatKey(node.key) + pc.dim(\": \") : pc.bold(pc.white(\"root: \")));\n }\n\n if (node.type === \"object\") {\n line += pc.dim(`{ ${node.itemCount} keys }`);\n } else if (node.type === \"array\") {\n line += pc.dim(`[ ${node.itemCount} items ]`);\n } else {\n line += formatValue(node.value);\n }\n\n const lines = [line];\n\n if (!node.collapsed && node.children && node.children.length > 0) {\n const nextIndent = isRoot ? \"\" : indent + (isLast ? \" \" : \"│ \");\n node.children.forEach((child, index) => {\n const childIsLast = index === node.children!.length - 1;\n lines.push(prettyPrintTree(child, nextIndent, childIsLast));\n });\n }\n\n return lines.join(\"\\n\");\n}\n","import pc from \"picocolors\";\nimport { DiffNode, DiffStatus, JSONValueType } from \"./types.js\";\nimport { getValueType, formatValue, formatKey } from \"./formatter.js\";\n\nexport interface DiffStats {\n added: number;\n removed: number;\n modified: number;\n unchanged: number;\n}\n\n/**\n * Compare two JSON values structurally and return a recursive DiffNode tree.\n */\nexport function diffJSON(\n a: any,\n b: any,\n key?: string,\n path = \"$\",\n depth = 0,\n maxInitialDepth = 3\n): DiffNode {\n const typeA = getValueType(a);\n const typeB = getValueType(b);\n const id = `${path}-${key || \"diff\"}-${depth}`;\n const collapsed = depth >= maxInitialDepth;\n\n // Case 1: Value added (a is undefined, b exists)\n if (a === undefined && b !== undefined) {\n const node: DiffNode = {\n id,\n key,\n path,\n depth,\n status: \"added\",\n newValue: b,\n type: typeB,\n collapsed: false,\n };\n if (typeB === \"object\" && b !== null) {\n node.itemCount = Object.keys(b).length;\n node.children = Object.keys(b).map((k) =>\n diffJSON(undefined, b[k], k, path === \"$\" ? k : `${path}.${k}`, depth + 1, maxInitialDepth)\n );\n } else if (typeB === \"array\") {\n node.itemCount = b.length;\n node.children = b.map((item: any, idx: number) =>\n diffJSON(undefined, item, `[${idx}]`, `${path}[${idx}]`, depth + 1, maxInitialDepth)\n );\n }\n return node;\n }\n\n // Case 2: Value removed (a exists, b is undefined)\n if (a !== undefined && b === undefined) {\n const node: DiffNode = {\n id,\n key,\n path,\n depth,\n status: \"removed\",\n oldValue: a,\n type: typeA,\n collapsed: false,\n };\n if (typeA === \"object\" && a !== null) {\n node.itemCount = Object.keys(a).length;\n node.children = Object.keys(a).map((k) =>\n diffJSON(a[k], undefined, k, path === \"$\" ? k : `${path}.${k}`, depth + 1, maxInitialDepth)\n );\n } else if (typeA === \"array\") {\n node.itemCount = a.length;\n node.children = a.map((item: any, idx: number) =>\n diffJSON(item, undefined, `[${idx}]`, `${path}[${idx}]`, depth + 1, maxInitialDepth)\n );\n }\n return node;\n }\n\n // Case 3: Type changed (e.g. from string to number or object to array)\n if (typeA !== typeB) {\n return {\n id,\n key,\n path,\n depth,\n status: \"modified\",\n oldValue: a,\n newValue: b,\n type: typeB,\n collapsed: false,\n };\n }\n\n // Case 4: Both are Objects\n if (typeA === \"object\" && a !== null && b !== null) {\n const allKeys = Array.from(new Set([...Object.keys(a), ...Object.keys(b)]));\n const children: DiffNode[] = [];\n let hasModifications = false;\n\n for (const k of allKeys) {\n const child = diffJSON(\n a[k],\n b[k],\n k,\n path === \"$\" ? k : `${path}.${k}`,\n depth + 1,\n maxInitialDepth\n );\n if (child.status !== \"unchanged\") hasModifications = true;\n children.push(child);\n }\n\n return {\n id,\n key,\n path,\n depth,\n status: hasModifications ? \"modified\" : \"unchanged\",\n oldValue: a,\n newValue: b,\n type: \"object\",\n itemCount: allKeys.length,\n collapsed,\n children,\n };\n }\n\n // Case 5: Both are Arrays\n if (typeA === \"array\") {\n const maxLen = Math.max(a.length, b.length);\n const children: DiffNode[] = [];\n let hasModifications = false;\n\n for (let i = 0; i < maxLen; i++) {\n const child = diffJSON(\n a[i],\n b[i],\n `[${i}]`,\n `${path}[${i}]`,\n depth + 1,\n maxInitialDepth\n );\n if (child.status !== \"unchanged\") hasModifications = true;\n children.push(child);\n }\n\n return {\n id,\n key,\n path,\n depth,\n status: hasModifications ? \"modified\" : \"unchanged\",\n oldValue: a,\n newValue: b,\n type: \"array\",\n itemCount: maxLen,\n collapsed,\n children,\n };\n }\n\n // Case 6: Primitive values comparison\n if (a !== b) {\n return {\n id,\n key,\n path,\n depth,\n status: \"modified\",\n oldValue: a,\n newValue: b,\n type: typeB,\n collapsed: false,\n };\n }\n\n // Unchanged primitive\n return {\n id,\n key,\n path,\n depth,\n status: \"unchanged\",\n oldValue: a,\n newValue: b,\n type: typeA,\n collapsed,\n };\n}\n\n/**\n * Calculate summary metrics for the diff.\n */\nexport function calculateDiffStats(node: DiffNode): DiffStats {\n const stats: DiffStats = { added: 0, removed: 0, modified: 0, unchanged: 0 };\n\n function traverse(n: DiffNode) {\n if (n.children && n.children.length > 0) {\n n.children.forEach(traverse);\n } else {\n stats[n.status]++;\n }\n }\n\n traverse(node);\n return stats;\n}\n\n/**\n * Pretty-print structural diff to terminal string.\n */\nexport function prettyPrintDiff(\n node: DiffNode,\n options: { showUnchanged?: boolean } = {},\n indent = \"\",\n isLast = true\n): string {\n const showUnchanged = options.showUnchanged ?? true;\n\n if (!showUnchanged && node.status === \"unchanged\" && (!node.children || node.children.length === 0)) {\n return \"\";\n }\n\n const isRoot = node.depth === 0;\n let prefix = \" \";\n let statusColor = pc.dim;\n\n if (node.status === \"added\") {\n prefix = pc.green(\"+ \");\n statusColor = pc.green;\n } else if (node.status === \"removed\") {\n prefix = pc.red(\"- \");\n statusColor = pc.red;\n } else if (node.status === \"modified\") {\n prefix = pc.yellow(\"~ \");\n statusColor = pc.yellow;\n }\n\n let line = prefix;\n if (!isRoot) {\n const branch = isLast ? \"└── \" : \"├── \";\n line += pc.dim(indent + branch);\n if (node.key) {\n line += formatKey(node.key) + pc.dim(\": \");\n }\n } else {\n line += node.key ? formatKey(node.key) + pc.dim(\": \") : pc.bold(\"diff: \");\n }\n\n if (node.status === \"added\") {\n line += statusColor(formatValue(node.newValue));\n } else if (node.status === \"removed\") {\n line += statusColor(formatValue(node.oldValue));\n } else if (node.status === \"modified\") {\n if (node.type === \"object\" || node.type === \"array\") {\n line += statusColor(`{ ${node.itemCount} items modified }`);\n } else {\n line += `${pc.red(formatValue(node.oldValue))} ${pc.dim(\"->\")} ${pc.green(formatValue(node.newValue))}`;\n }\n } else {\n // Unchanged\n line += pc.dim(formatValue(node.newValue));\n }\n\n const lines = [line];\n\n if (!node.collapsed && node.children && node.children.length > 0) {\n const nextIndent = isRoot ? \"\" : indent + (isLast ? \" \" : \"│ \");\n node.children.forEach((child, index) => {\n const childIsLast = index === node.children!.length - 1;\n const childStr = prettyPrintDiff(child, options, nextIndent, childIsLast);\n if (childStr) lines.push(childStr);\n });\n }\n\n return lines.join(\"\\n\");\n}\n","import readline from \"readline\";\nimport pc from \"picocolors\";\nimport { TreeNode, DiffNode } from \"./types.js\";\nimport { formatKey, formatValue } from \"./formatter.js\";\nimport { copyToClipboard } from \"./utils/clipboard.js\";\n\ntype AnyNode = TreeNode | DiffNode;\n\ninterface FlatItem {\n node: AnyNode;\n depth: number;\n isDiff: boolean;\n}\n\n/**\n * Interactive Terminal Tree Explorer for JSON data and Diffs.\n */\nexport class InteractiveViewer {\n private root: AnyNode;\n private flatList: FlatItem[] = [];\n private selectedIndex = 0;\n private searchQuery = \"\";\n private isSearching = false;\n private searchInput = \"\";\n private notification = \"\";\n private notificationTimer: NodeJS.Timeout | null = null;\n private isDiff: boolean;\n\n constructor(root: AnyNode, isDiff = false) {\n this.root = root;\n this.isDiff = isDiff;\n this.rebuildFlatList();\n }\n\n private isDiffNode(node: AnyNode): node is DiffNode {\n return this.isDiff && \"status\" in node;\n }\n\n private rebuildFlatList(): void {\n const list: FlatItem[] = [];\n\n const traverse = (node: AnyNode, currentDepth: number) => {\n // If search query is active, filter matching nodes or their parents\n if (this.searchQuery) {\n const query = this.searchQuery.toLowerCase();\n const keyMatch = node.key && node.key.toLowerCase().includes(query);\n const pathMatch = node.path && node.path.toLowerCase().includes(query);\n const valMatch =\n \"value\" in node\n ? JSON.stringify(node.value).toLowerCase().includes(query)\n : \"newValue\" in node\n ? JSON.stringify(node.newValue).toLowerCase().includes(query)\n : false;\n\n if (!keyMatch && !pathMatch && !valMatch && (!node.children || node.children.length === 0)) {\n return;\n }\n }\n\n list.push({ node, depth: currentDepth, isDiff: this.isDiff });\n\n if (!node.collapsed && node.children && node.children.length > 0) {\n for (const child of node.children) {\n traverse(child, currentDepth + 1);\n }\n }\n };\n\n traverse(this.root, 0);\n this.flatList = list;\n\n if (this.selectedIndex >= this.flatList.length) {\n this.selectedIndex = Math.max(0, this.flatList.length - 1);\n }\n }\n\n private setNotification(msg: string): void {\n this.notification = msg;\n if (this.notificationTimer) clearTimeout(this.notificationTimer);\n this.notificationTimer = setTimeout(() => {\n this.notification = \"\";\n this.render();\n }, 2500);\n }\n\n private render(): void {\n const rows = process.stdout.rows || 24;\n const maxVisibleRows = Math.max(5, rows - 5);\n\n // Calculate window scroll offset\n let startIdx = 0;\n if (this.selectedIndex >= maxVisibleRows) {\n startIdx = this.selectedIndex - maxVisibleRows + 1;\n }\n const endIdx = Math.min(this.flatList.length, startIdx + maxVisibleRows);\n\n // Clear terminal screen\n process.stdout.write(\"\\x1b[2J\\x1b[3J\\x1b[H\\x1b[?25l\"); // hide cursor\n\n // 1. Header Bar\n const title = this.isDiff ? \" JSON Structural Diff Explorer \" : \" Interactive JSON Tree Explorer \";\n console.log(pc.bgCyan(pc.black(pc.bold(` ${title} `)) + pc.dim(` [Total items: ${this.flatList.length}]`)));\n\n // 2. Render visible items\n for (let i = startIdx; i < endIdx; i++) {\n const { node, depth } = this.flatList[i];\n const isSelected = i === this.selectedIndex;\n const indent = \" \".repeat(depth);\n\n let marker = \"• \";\n if (node.children && node.children.length > 0) {\n marker = node.collapsed ? \"▶ \" : \"▼ \";\n }\n\n let lineContent = \"\";\n\n if (this.isDiffNode(node)) {\n let diffPrefix = \" \";\n if (node.status === \"added\") diffPrefix = pc.green(\"+ \");\n else if (node.status === \"removed\") diffPrefix = pc.red(\"- \");\n else if (node.status === \"modified\") diffPrefix = pc.yellow(\"~ \");\n\n lineContent = diffPrefix + indent + marker;\n if (node.key) lineContent += formatKey(node.key) + pc.dim(\": \");\n\n if (node.status === \"added\") {\n lineContent += pc.green(formatValue(node.newValue, 50));\n } else if (node.status === \"removed\") {\n lineContent += pc.red(formatValue(node.oldValue, 50));\n } else if (node.status === \"modified\") {\n if (node.type === \"object\" || node.type === \"array\") {\n lineContent += pc.yellow(`{ ${node.itemCount} modified }`);\n } else {\n lineContent += `${pc.red(formatValue(node.oldValue, 25))} -> ${pc.green(formatValue(node.newValue, 25))}`;\n }\n } else {\n lineContent += pc.dim(formatValue(node.newValue, 50));\n }\n } else {\n const treeNode = node as TreeNode;\n lineContent = indent + marker;\n if (treeNode.key) lineContent += formatKey(treeNode.key) + pc.dim(\": \");\n\n if (treeNode.type === \"object\") {\n lineContent += pc.dim(`{ ${treeNode.itemCount} keys }`);\n } else if (treeNode.type === \"array\") {\n lineContent += pc.dim(`[ ${treeNode.itemCount} items ]`);\n } else {\n lineContent += formatValue(treeNode.value, 60);\n }\n }\n\n if (isSelected) {\n console.log(pc.bgBlue(pc.white(pc.bold(`> ${lineContent}`))));\n } else {\n console.log(` ${lineContent}`);\n }\n }\n\n // 3. Status Bar & Footer\n const selectedItem = this.flatList[this.selectedIndex];\n const currentPath = selectedItem ? selectedItem.node.path : \"$\";\n\n console.log(\"\\n\" + pc.dim(\"─\".repeat(Math.min(process.stdout.columns || 80, 80))));\n if (this.notification) {\n console.log(pc.green(pc.bold(` ${this.notification}`)));\n } else if (this.isSearching) {\n console.log(pc.yellow(pc.bold(` Search: /${this.searchInput}█`)));\n } else {\n console.log(pc.bold(pc.cyan(` Path: ${currentPath}`)));\n console.log(\n pc.dim(\" [↑/↓] Move [Enter/Space] Toggle [e] Expand All [c] Collapse All [p] Copy Path [y] Copy Val [/] Search [q] Exit\")\n );\n }\n }\n\n private expandAll(node: AnyNode): void {\n node.collapsed = false;\n if (node.children) node.children.forEach((c) => this.expandAll(c));\n }\n\n private collapseAll(node: AnyNode): void {\n if (node.depth > 0) node.collapsed = true;\n if (node.children) node.children.forEach((c) => this.collapseAll(c));\n }\n\n public async start(): Promise<void> {\n if (!process.stdin.isTTY) {\n return;\n }\n\n readline.emitKeypressEvents(process.stdin);\n process.stdin.setRawMode(true);\n process.stdin.resume();\n\n this.render();\n\n return new Promise((resolve) => {\n const onKeypress = async (str: string, key: readline.Key) => {\n if (this.isSearching) {\n if (key.name === \"return\") {\n this.searchQuery = this.searchInput;\n this.isSearching = false;\n this.rebuildFlatList();\n this.render();\n return;\n }\n if (key.name === \"escape\") {\n this.isSearching = false;\n this.searchInput = \"\";\n this.render();\n return;\n }\n if (key.name === \"backspace\") {\n this.searchInput = this.searchInput.slice(0, -1);\n this.render();\n return;\n }\n if (str && str.length === 1) {\n this.searchInput += str;\n this.render();\n return;\n }\n }\n\n // Navigation\n if (key.name === \"up\" || key.name === \"k\") {\n if (this.selectedIndex > 0) {\n this.selectedIndex--;\n this.render();\n }\n } else if (key.name === \"down\" || key.name === \"j\") {\n if (this.selectedIndex < this.flatList.length - 1) {\n this.selectedIndex++;\n this.render();\n }\n } else if (key.name === \"return\" || key.name === \"space\" || key.name === \"right\" || key.name === \"left\") {\n const item = this.flatList[this.selectedIndex];\n if (item && item.node.children && item.node.children.length > 0) {\n item.node.collapsed = !item.node.collapsed;\n this.rebuildFlatList();\n this.render();\n }\n } else if (str === \"e\" || str === \"E\") {\n this.expandAll(this.root);\n this.rebuildFlatList();\n this.render();\n } else if (str === \"c\" || str === \"C\") {\n this.collapseAll(this.root);\n this.rebuildFlatList();\n this.render();\n } else if (str === \"p\" || str === \"P\") {\n const item = this.flatList[this.selectedIndex];\n if (item) {\n await copyToClipboard(item.node.path);\n this.setNotification(`✔ Copied JSONPath: ${item.node.path}`);\n }\n } else if (str === \"y\" || str === \"Y\") {\n const item = this.flatList[this.selectedIndex];\n if (item) {\n const val = \"value\" in item.node ? item.node.value : (item.node as DiffNode).newValue;\n const textToCopy = typeof val === \"object\" ? JSON.stringify(val, null, 2) : String(val);\n await copyToClipboard(textToCopy);\n this.setNotification(`✔ Copied value to clipboard!`);\n }\n } else if (str === \"/\") {\n this.isSearching = true;\n this.searchInput = \"\";\n this.render();\n } else if (key.ctrl && key.name === \"c\" || key.name === \"escape\" || str === \"q\" || str === \"Q\") {\n // Cleanup & Exit\n process.stdin.removeListener(\"keypress\", onKeypress);\n process.stdin.setRawMode(false);\n process.stdin.pause();\n process.stdout.write(\"\\x1b[?25h\\n\"); // show cursor\n resolve();\n }\n };\n\n process.stdin.on(\"keypress\", onKeypress);\n });\n }\n}\n","import { exec } from \"child_process\";\nimport os from \"os\";\n\n/**\n * Copy text to system clipboard across macOS, Linux, and Windows.\n */\nexport async function copyToClipboard(text: string): Promise<boolean> {\n const platform = os.platform();\n\n return new Promise((resolve) => {\n let proc;\n if (platform === \"darwin\") {\n proc = exec(\"pbcopy\", (err) => resolve(!err));\n } else if (platform === \"win32\") {\n proc = exec(\"clip\", (err) => resolve(!err));\n } else {\n // Linux: Try wl-copy then xclip\n proc = exec(\"wl-copy 2>/dev/null || xclip -selection clipboard 2>/dev/null || xsel --clipboard --input\", (err) => {\n resolve(!err);\n });\n }\n\n if (proc.stdin) {\n proc.stdin.write(text);\n proc.stdin.end();\n } else {\n resolve(false);\n }\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,wBAAe;AAMR,SAAS,aAAa,OAA2B;AACtD,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI,MAAM,QAAQ,KAAK,EAAG,QAAO;AACjC,QAAM,IAAI,OAAO;AACjB,MAAI,MAAM,SAAU,QAAO;AAC3B,MAAI,MAAM,SAAU,QAAO;AAC3B,MAAI,MAAM,SAAU,QAAO;AAC3B,MAAI,MAAM,UAAW,QAAO;AAC5B,SAAO;AACT;AAKO,SAAS,YAAY,OAAY,cAAc,IAAY;AAChE,QAAM,OAAO,aAAa,KAAK;AAE/B,UAAQ,MAAM;AAAA,IACZ,KAAK,UAAU;AACb,YAAM,MAAM,KAAK,UAAU,KAAK;AAChC,YAAM,YAAY,IAAI,SAAS,cAAc,IAAI,MAAM,GAAG,cAAc,CAAC,IAAI,SAAS;AACtF,aAAO,kBAAAA,QAAG,MAAM,SAAS;AAAA,IAC3B;AA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Q,KAAK;AAE9F,kBAAQ,MAAM,eAAe,YAAY,UAAU;AACnD,kBAAQ,MAAM,WAAW,KAAK;AAC9B,kBAAQ,MAAM,MAAM;AACpB,kBAAQ,OAAO,MAAM,aAAa;AAClC,kBAAQ;AAAA,QACV;AAAA,MACF;AAEA,cAAQ,MAAM,GAAG,YAAY,UAAU;AAAA,IACzC,CAAC;AAAA,EACH;AACF;","names":["pc","import_picocolors","pc","import_picocolors","os","pc","readline"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
// src/formatter.ts
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
function getValueType(value) {
|
|
4
|
+
if (value === null || value === void 0) return "null";
|
|
5
|
+
if (Array.isArray(value)) return "array";
|
|
6
|
+
const t = typeof value;
|
|
7
|
+
if (t === "object") return "object";
|
|
8
|
+
if (t === "string") return "string";
|
|
9
|
+
if (t === "number") return "number";
|
|
10
|
+
if (t === "boolean") return "boolean";
|
|
11
|
+
return "string";
|
|
12
|
+
}
|
|
13
|
+
function formatValue(value, truncateLen = 80) {
|
|
14
|
+
const type = getValueType(value);
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "string": {
|
|
17
|
+
const str = JSON.stringify(value);
|
|
18
|
+
const truncated = str.length > truncateLen ? str.slice(0, truncateLen - 3) + '..."' : str;
|
|
19
|
+
return pc.green(truncated);
|
|
20
|
+
}
|
|
21
|
+
case "number":
|
|
22
|
+
return pc.yellow(String(value));
|
|
23
|
+
case "boolean":
|
|
24
|
+
return pc.magenta(String(value));
|
|
25
|
+
case "null":
|
|
26
|
+
return pc.dim("null");
|
|
27
|
+
case "array":
|
|
28
|
+
return pc.dim(`[${value.length} items]`);
|
|
29
|
+
case "object":
|
|
30
|
+
return pc.dim(`{${Object.keys(value).length} keys}`);
|
|
31
|
+
default:
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function formatKey(key) {
|
|
36
|
+
return pc.bold(pc.cyan(key));
|
|
37
|
+
}
|
|
38
|
+
function buildTree(data, key, path = "$", depth = 0, maxInitialDepth = 2, parentId) {
|
|
39
|
+
const type = getValueType(data);
|
|
40
|
+
const id = `${path}-${key || "root"}-${depth}`;
|
|
41
|
+
const collapsed = depth >= maxInitialDepth;
|
|
42
|
+
const node = {
|
|
43
|
+
id,
|
|
44
|
+
key,
|
|
45
|
+
value: data,
|
|
46
|
+
type,
|
|
47
|
+
depth,
|
|
48
|
+
path,
|
|
49
|
+
collapsed,
|
|
50
|
+
parentId
|
|
51
|
+
};
|
|
52
|
+
if (type === "object" && data !== null) {
|
|
53
|
+
const keys = Object.keys(data);
|
|
54
|
+
node.itemCount = keys.length;
|
|
55
|
+
node.children = keys.map(
|
|
56
|
+
(k) => buildTree(
|
|
57
|
+
data[k],
|
|
58
|
+
k,
|
|
59
|
+
path === "$" ? k : `${path}.${k}`,
|
|
60
|
+
depth + 1,
|
|
61
|
+
maxInitialDepth,
|
|
62
|
+
id
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
} else if (type === "array") {
|
|
66
|
+
node.itemCount = data.length;
|
|
67
|
+
node.children = data.map(
|
|
68
|
+
(item, idx) => buildTree(
|
|
69
|
+
item,
|
|
70
|
+
`[${idx}]`,
|
|
71
|
+
`${path}[${idx}]`,
|
|
72
|
+
depth + 1,
|
|
73
|
+
maxInitialDepth,
|
|
74
|
+
id
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return node;
|
|
79
|
+
}
|
|
80
|
+
function prettyPrintTree(node, indent = "", isLast = true) {
|
|
81
|
+
const isRoot = node.depth === 0;
|
|
82
|
+
const marker = node.type === "object" || node.type === "array" ? node.collapsed ? pc.cyan("\u25B6 ") : pc.cyan("\u25BC ") : pc.dim("\u2022 ");
|
|
83
|
+
let line = "";
|
|
84
|
+
if (!isRoot) {
|
|
85
|
+
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
86
|
+
line += pc.dim(indent + branch) + marker;
|
|
87
|
+
if (node.key) {
|
|
88
|
+
line += formatKey(node.key) + pc.dim(": ");
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
line += marker + (node.key ? formatKey(node.key) + pc.dim(": ") : pc.bold(pc.white("root: ")));
|
|
92
|
+
}
|
|
93
|
+
if (node.type === "object") {
|
|
94
|
+
line += pc.dim(`{ ${node.itemCount} keys }`);
|
|
95
|
+
} else if (node.type === "array") {
|
|
96
|
+
line += pc.dim(`[ ${node.itemCount} items ]`);
|
|
97
|
+
} else {
|
|
98
|
+
line += formatValue(node.value);
|
|
99
|
+
}
|
|
100
|
+
const lines = [line];
|
|
101
|
+
if (!node.collapsed && node.children && node.children.length > 0) {
|
|
102
|
+
const nextIndent = isRoot ? "" : indent + (isLast ? " " : "\u2502 ");
|
|
103
|
+
node.children.forEach((child, index) => {
|
|
104
|
+
const childIsLast = index === node.children.length - 1;
|
|
105
|
+
lines.push(prettyPrintTree(child, nextIndent, childIsLast));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/differ.ts
|
|
112
|
+
import pc2 from "picocolors";
|
|
113
|
+
function diffJSON(a, b, key, path = "$", depth = 0, maxInitialDepth = 3) {
|
|
114
|
+
const typeA = getValueType(a);
|
|
115
|
+
const typeB = getValueType(b);
|
|
116
|
+
const id = `${path}-${key || "diff"}-${depth}`;
|
|
117
|
+
const collapsed = depth >= maxInitialDepth;
|
|
118
|
+
if (a === void 0 && b !== void 0) {
|
|
119
|
+
const node = {
|
|
120
|
+
id,
|
|
121
|
+
key,
|
|
122
|
+
path,
|
|
123
|
+
depth,
|
|
124
|
+
status: "added",
|
|
125
|
+
newValue: b,
|
|
126
|
+
type: typeB,
|
|
127
|
+
collapsed: false
|
|
128
|
+
};
|
|
129
|
+
if (typeB === "object" && b !== null) {
|
|
130
|
+
node.itemCount = Object.keys(b).length;
|
|
131
|
+
node.children = Object.keys(b).map(
|
|
132
|
+
(k) => diffJSON(void 0, b[k], k, path === "$" ? k : `${path}.${k}`, depth + 1, maxInitialDepth)
|
|
133
|
+
);
|
|
134
|
+
} else if (typeB === "array") {
|
|
135
|
+
node.itemCount = b.length;
|
|
136
|
+
node.children = b.map(
|
|
137
|
+
(item, idx) => diffJSON(void 0, item, `[${idx}]`, `${path}[${idx}]`, depth + 1, maxInitialDepth)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
if (a !== void 0 && b === void 0) {
|
|
143
|
+
const node = {
|
|
144
|
+
id,
|
|
145
|
+
key,
|
|
146
|
+
path,
|
|
147
|
+
depth,
|
|
148
|
+
status: "removed",
|
|
149
|
+
oldValue: a,
|
|
150
|
+
type: typeA,
|
|
151
|
+
collapsed: false
|
|
152
|
+
};
|
|
153
|
+
if (typeA === "object" && a !== null) {
|
|
154
|
+
node.itemCount = Object.keys(a).length;
|
|
155
|
+
node.children = Object.keys(a).map(
|
|
156
|
+
(k) => diffJSON(a[k], void 0, k, path === "$" ? k : `${path}.${k}`, depth + 1, maxInitialDepth)
|
|
157
|
+
);
|
|
158
|
+
} else if (typeA === "array") {
|
|
159
|
+
node.itemCount = a.length;
|
|
160
|
+
node.children = a.map(
|
|
161
|
+
(item, idx) => diffJSON(item, void 0, `[${idx}]`, `${path}[${idx}]`, depth + 1, maxInitialDepth)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
return node;
|
|
165
|
+
}
|
|
166
|
+
if (typeA !== typeB) {
|
|
167
|
+
return {
|
|
168
|
+
id,
|
|
169
|
+
key,
|
|
170
|
+
path,
|
|
171
|
+
depth,
|
|
172
|
+
status: "modified",
|
|
173
|
+
oldValue: a,
|
|
174
|
+
newValue: b,
|
|
175
|
+
type: typeB,
|
|
176
|
+
collapsed: false
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (typeA === "object" && a !== null && b !== null) {
|
|
180
|
+
const allKeys = Array.from(/* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]));
|
|
181
|
+
const children = [];
|
|
182
|
+
let hasModifications = false;
|
|
183
|
+
for (const k of allKeys) {
|
|
184
|
+
const child = diffJSON(
|
|
185
|
+
a[k],
|
|
186
|
+
b[k],
|
|
187
|
+
k,
|
|
188
|
+
path === "$" ? k : `${path}.${k}`,
|
|
189
|
+
depth + 1,
|
|
190
|
+
maxInitialDepth
|
|
191
|
+
);
|
|
192
|
+
if (child.status !== "unchanged") hasModifications = true;
|
|
193
|
+
children.push(child);
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
id,
|
|
197
|
+
key,
|
|
198
|
+
path,
|
|
199
|
+
depth,
|
|
200
|
+
status: hasModifications ? "modified" : "unchanged",
|
|
201
|
+
oldValue: a,
|
|
202
|
+
newValue: b,
|
|
203
|
+
type: "object",
|
|
204
|
+
itemCount: allKeys.length,
|
|
205
|
+
collapsed,
|
|
206
|
+
children
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (typeA === "array") {
|
|
210
|
+
const maxLen = Math.max(a.length, b.length);
|
|
211
|
+
const children = [];
|
|
212
|
+
let hasModifications = false;
|
|
213
|
+
for (let i = 0; i < maxLen; i++) {
|
|
214
|
+
const child = diffJSON(
|
|
215
|
+
a[i],
|
|
216
|
+
b[i],
|
|
217
|
+
`[${i}]`,
|
|
218
|
+
`${path}[${i}]`,
|
|
219
|
+
depth + 1,
|
|
220
|
+
maxInitialDepth
|
|
221
|
+
);
|
|
222
|
+
if (child.status !== "unchanged") hasModifications = true;
|
|
223
|
+
children.push(child);
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
id,
|
|
227
|
+
key,
|
|
228
|
+
path,
|
|
229
|
+
depth,
|
|
230
|
+
status: hasModifications ? "modified" : "unchanged",
|
|
231
|
+
oldValue: a,
|
|
232
|
+
newValue: b,
|
|
233
|
+
type: "array",
|
|
234
|
+
itemCount: maxLen,
|
|
235
|
+
collapsed,
|
|
236
|
+
children
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (a !== b) {
|
|
240
|
+
return {
|
|
241
|
+
id,
|
|
242
|
+
key,
|
|
243
|
+
path,
|
|
244
|
+
depth,
|
|
245
|
+
status: "modified",
|
|
246
|
+
oldValue: a,
|
|
247
|
+
newValue: b,
|
|
248
|
+
type: typeB,
|
|
249
|
+
collapsed: false
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
id,
|
|
254
|
+
key,
|
|
255
|
+
path,
|
|
256
|
+
depth,
|
|
257
|
+
status: "unchanged",
|
|
258
|
+
oldValue: a,
|
|
259
|
+
newValue: b,
|
|
260
|
+
type: typeA,
|
|
261
|
+
collapsed
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
function calculateDiffStats(node) {
|
|
265
|
+
const stats = { added: 0, removed: 0, modified: 0, unchanged: 0 };
|
|
266
|
+
function traverse(n) {
|
|
267
|
+
if (n.children && n.children.length > 0) {
|
|
268
|
+
n.children.forEach(traverse);
|
|
269
|
+
} else {
|
|
270
|
+
stats[n.status]++;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
traverse(node);
|
|
274
|
+
return stats;
|
|
275
|
+
}
|
|
276
|
+
function prettyPrintDiff(node, options = {}, indent = "", isLast = true) {
|
|
277
|
+
const showUnchanged = options.showUnchanged ?? true;
|
|
278
|
+
if (!showUnchanged && node.status === "unchanged" && (!node.children || node.children.length === 0)) {
|
|
279
|
+
return "";
|
|
280
|
+
}
|
|
281
|
+
const isRoot = node.depth === 0;
|
|
282
|
+
let prefix = " ";
|
|
283
|
+
let statusColor = pc2.dim;
|
|
284
|
+
if (node.status === "added") {
|
|
285
|
+
prefix = pc2.green("+ ");
|
|
286
|
+
statusColor = pc2.green;
|
|
287
|
+
} else if (node.status === "removed") {
|
|
288
|
+
prefix = pc2.red("- ");
|
|
289
|
+
statusColor = pc2.red;
|
|
290
|
+
} else if (node.status === "modified") {
|
|
291
|
+
prefix = pc2.yellow("~ ");
|
|
292
|
+
statusColor = pc2.yellow;
|
|
293
|
+
}
|
|
294
|
+
let line = prefix;
|
|
295
|
+
if (!isRoot) {
|
|
296
|
+
const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
|
|
297
|
+
line += pc2.dim(indent + branch);
|
|
298
|
+
if (node.key) {
|
|
299
|
+
line += formatKey(node.key) + pc2.dim(": ");
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
line += node.key ? formatKey(node.key) + pc2.dim(": ") : pc2.bold("diff: ");
|
|
303
|
+
}
|
|
304
|
+
if (node.status === "added") {
|
|
305
|
+
line += statusColor(formatValue(node.newValue));
|
|
306
|
+
} else if (node.status === "removed") {
|
|
307
|
+
line += statusColor(formatValue(node.oldValue));
|
|
308
|
+
} else if (node.status === "modified") {
|
|
309
|
+
if (node.type === "object" || node.type === "array") {
|
|
310
|
+
line += statusColor(`{ ${node.itemCount} items modified }`);
|
|
311
|
+
} else {
|
|
312
|
+
line += `${pc2.red(formatValue(node.oldValue))} ${pc2.dim("->")} ${pc2.green(formatValue(node.newValue))}`;
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
line += pc2.dim(formatValue(node.newValue));
|
|
316
|
+
}
|
|
317
|
+
const lines = [line];
|
|
318
|
+
if (!node.collapsed && node.children && node.children.length > 0) {
|
|
319
|
+
const nextIndent = isRoot ? "" : indent + (isLast ? " " : "\u2502 ");
|
|
320
|
+
node.children.forEach((child, index) => {
|
|
321
|
+
const childIsLast = index === node.children.length - 1;
|
|
322
|
+
const childStr = prettyPrintDiff(child, options, nextIndent, childIsLast);
|
|
323
|
+
if (childStr) lines.push(childStr);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return lines.join("\n");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/interactive.ts
|
|
330
|
+
import readline from "readline";
|
|
331
|
+
import pc3 from "picocolors";
|
|
332
|
+
|
|
333
|
+
// src/utils/clipboard.ts
|
|
334
|
+
import { exec } from "child_process";
|
|
335
|
+
import os from "os";
|
|
336
|
+
async function copyToClipboard(text) {
|
|
337
|
+
const platform = os.platform();
|
|
338
|
+
return new Promise((resolve) => {
|
|
339
|
+
let proc;
|
|
340
|
+
if (platform === "darwin") {
|
|
341
|
+
proc = exec("pbcopy", (err) => resolve(!err));
|
|
342
|
+
} else if (platform === "win32") {
|
|
343
|
+
proc = exec("clip", (err) => resolve(!err));
|
|
344
|
+
} else {
|
|
345
|
+
proc = exec("wl-copy 2>/dev/null || xclip -selection clipboard 2>/dev/null || xsel --clipboard --input", (err) => {
|
|
346
|
+
resolve(!err);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
if (proc.stdin) {
|
|
350
|
+
proc.stdin.write(text);
|
|
351
|
+
proc.stdin.end();
|
|
352
|
+
} else {
|
|
353
|
+
resolve(false);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/interactive.ts
|
|
359
|
+
var InteractiveViewer = class {
|
|
360
|
+
root;
|
|
361
|
+
flatList = [];
|
|
362
|
+
selectedIndex = 0;
|
|
363
|
+
searchQuery = "";
|
|
364
|
+
isSearching = false;
|
|
365
|
+
searchInput = "";
|
|
366
|
+
notification = "";
|
|
367
|
+
notificationTimer = null;
|
|
368
|
+
isDiff;
|
|
369
|
+
constructor(root, isDiff = false) {
|
|
370
|
+
this.root = root;
|
|
371
|
+
this.isDiff = isDiff;
|
|
372
|
+
this.rebuildFlatList();
|
|
373
|
+
}
|
|
374
|
+
isDiffNode(node) {
|
|
375
|
+
return this.isDiff && "status" in node;
|
|
376
|
+
}
|
|
377
|
+
rebuildFlatList() {
|
|
378
|
+
const list = [];
|
|
379
|
+
const traverse = (node, currentDepth) => {
|
|
380
|
+
if (this.searchQuery) {
|
|
381
|
+
const query = this.searchQuery.toLowerCase();
|
|
382
|
+
const keyMatch = node.key && node.key.toLowerCase().includes(query);
|
|
383
|
+
const pathMatch = node.path && node.path.toLowerCase().includes(query);
|
|
384
|
+
const valMatch = "value" in node ? JSON.stringify(node.value).toLowerCase().includes(query) : "newValue" in node ? JSON.stringify(node.newValue).toLowerCase().includes(query) : false;
|
|
385
|
+
if (!keyMatch && !pathMatch && !valMatch && (!node.children || node.children.length === 0)) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
list.push({ node, depth: currentDepth, isDiff: this.isDiff });
|
|
390
|
+
if (!node.collapsed && node.children && node.children.length > 0) {
|
|
391
|
+
for (const child of node.children) {
|
|
392
|
+
traverse(child, currentDepth + 1);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
};
|
|
396
|
+
traverse(this.root, 0);
|
|
397
|
+
this.flatList = list;
|
|
398
|
+
if (this.selectedIndex >= this.flatList.length) {
|
|
399
|
+
this.selectedIndex = Math.max(0, this.flatList.length - 1);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
setNotification(msg) {
|
|
403
|
+
this.notification = msg;
|
|
404
|
+
if (this.notificationTimer) clearTimeout(this.notificationTimer);
|
|
405
|
+
this.notificationTimer = setTimeout(() => {
|
|
406
|
+
this.notification = "";
|
|
407
|
+
this.render();
|
|
408
|
+
}, 2500);
|
|
409
|
+
}
|
|
410
|
+
render() {
|
|
411
|
+
const rows = process.stdout.rows || 24;
|
|
412
|
+
const maxVisibleRows = Math.max(5, rows - 5);
|
|
413
|
+
let startIdx = 0;
|
|
414
|
+
if (this.selectedIndex >= maxVisibleRows) {
|
|
415
|
+
startIdx = this.selectedIndex - maxVisibleRows + 1;
|
|
416
|
+
}
|
|
417
|
+
const endIdx = Math.min(this.flatList.length, startIdx + maxVisibleRows);
|
|
418
|
+
process.stdout.write("\x1B[2J\x1B[3J\x1B[H\x1B[?25l");
|
|
419
|
+
const title = this.isDiff ? " JSON Structural Diff Explorer " : " Interactive JSON Tree Explorer ";
|
|
420
|
+
console.log(pc3.bgCyan(pc3.black(pc3.bold(` ${title} `)) + pc3.dim(` [Total items: ${this.flatList.length}]`)));
|
|
421
|
+
for (let i = startIdx; i < endIdx; i++) {
|
|
422
|
+
const { node, depth } = this.flatList[i];
|
|
423
|
+
const isSelected = i === this.selectedIndex;
|
|
424
|
+
const indent = " ".repeat(depth);
|
|
425
|
+
let marker = "\u2022 ";
|
|
426
|
+
if (node.children && node.children.length > 0) {
|
|
427
|
+
marker = node.collapsed ? "\u25B6 " : "\u25BC ";
|
|
428
|
+
}
|
|
429
|
+
let lineContent = "";
|
|
430
|
+
if (this.isDiffNode(node)) {
|
|
431
|
+
let diffPrefix = " ";
|
|
432
|
+
if (node.status === "added") diffPrefix = pc3.green("+ ");
|
|
433
|
+
else if (node.status === "removed") diffPrefix = pc3.red("- ");
|
|
434
|
+
else if (node.status === "modified") diffPrefix = pc3.yellow("~ ");
|
|
435
|
+
lineContent = diffPrefix + indent + marker;
|
|
436
|
+
if (node.key) lineContent += formatKey(node.key) + pc3.dim(": ");
|
|
437
|
+
if (node.status === "added") {
|
|
438
|
+
lineContent += pc3.green(formatValue(node.newValue, 50));
|
|
439
|
+
} else if (node.status === "removed") {
|
|
440
|
+
lineContent += pc3.red(formatValue(node.oldValue, 50));
|
|
441
|
+
} else if (node.status === "modified") {
|
|
442
|
+
if (node.type === "object" || node.type === "array") {
|
|
443
|
+
lineContent += pc3.yellow(`{ ${node.itemCount} modified }`);
|
|
444
|
+
} else {
|
|
445
|
+
lineContent += `${pc3.red(formatValue(node.oldValue, 25))} -> ${pc3.green(formatValue(node.newValue, 25))}`;
|
|
446
|
+
}
|
|
447
|
+
} else {
|
|
448
|
+
lineContent += pc3.dim(formatValue(node.newValue, 50));
|
|
449
|
+
}
|
|
450
|
+
} else {
|
|
451
|
+
const treeNode = node;
|
|
452
|
+
lineContent = indent + marker;
|
|
453
|
+
if (treeNode.key) lineContent += formatKey(treeNode.key) + pc3.dim(": ");
|
|
454
|
+
if (treeNode.type === "object") {
|
|
455
|
+
lineContent += pc3.dim(`{ ${treeNode.itemCount} keys }`);
|
|
456
|
+
} else if (treeNode.type === "array") {
|
|
457
|
+
lineContent += pc3.dim(`[ ${treeNode.itemCount} items ]`);
|
|
458
|
+
} else {
|
|
459
|
+
lineContent += formatValue(treeNode.value, 60);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (isSelected) {
|
|
463
|
+
console.log(pc3.bgBlue(pc3.white(pc3.bold(`> ${lineContent}`))));
|
|
464
|
+
} else {
|
|
465
|
+
console.log(` ${lineContent}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
const selectedItem = this.flatList[this.selectedIndex];
|
|
469
|
+
const currentPath = selectedItem ? selectedItem.node.path : "$";
|
|
470
|
+
console.log("\n" + pc3.dim("\u2500".repeat(Math.min(process.stdout.columns || 80, 80))));
|
|
471
|
+
if (this.notification) {
|
|
472
|
+
console.log(pc3.green(pc3.bold(` ${this.notification}`)));
|
|
473
|
+
} else if (this.isSearching) {
|
|
474
|
+
console.log(pc3.yellow(pc3.bold(` Search: /${this.searchInput}\u2588`)));
|
|
475
|
+
} else {
|
|
476
|
+
console.log(pc3.bold(pc3.cyan(` Path: ${currentPath}`)));
|
|
477
|
+
console.log(
|
|
478
|
+
pc3.dim(" [\u2191/\u2193] Move [Enter/Space] Toggle [e] Expand All [c] Collapse All [p] Copy Path [y] Copy Val [/] Search [q] Exit")
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
expandAll(node) {
|
|
483
|
+
node.collapsed = false;
|
|
484
|
+
if (node.children) node.children.forEach((c) => this.expandAll(c));
|
|
485
|
+
}
|
|
486
|
+
collapseAll(node) {
|
|
487
|
+
if (node.depth > 0) node.collapsed = true;
|
|
488
|
+
if (node.children) node.children.forEach((c) => this.collapseAll(c));
|
|
489
|
+
}
|
|
490
|
+
async start() {
|
|
491
|
+
if (!process.stdin.isTTY) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
readline.emitKeypressEvents(process.stdin);
|
|
495
|
+
process.stdin.setRawMode(true);
|
|
496
|
+
process.stdin.resume();
|
|
497
|
+
this.render();
|
|
498
|
+
return new Promise((resolve) => {
|
|
499
|
+
const onKeypress = async (str, key) => {
|
|
500
|
+
if (this.isSearching) {
|
|
501
|
+
if (key.name === "return") {
|
|
502
|
+
this.searchQuery = this.searchInput;
|
|
503
|
+
this.isSearching = false;
|
|
504
|
+
this.rebuildFlatList();
|
|
505
|
+
this.render();
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (key.name === "escape") {
|
|
509
|
+
this.isSearching = false;
|
|
510
|
+
this.searchInput = "";
|
|
511
|
+
this.render();
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
if (key.name === "backspace") {
|
|
515
|
+
this.searchInput = this.searchInput.slice(0, -1);
|
|
516
|
+
this.render();
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
if (str && str.length === 1) {
|
|
520
|
+
this.searchInput += str;
|
|
521
|
+
this.render();
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (key.name === "up" || key.name === "k") {
|
|
526
|
+
if (this.selectedIndex > 0) {
|
|
527
|
+
this.selectedIndex--;
|
|
528
|
+
this.render();
|
|
529
|
+
}
|
|
530
|
+
} else if (key.name === "down" || key.name === "j") {
|
|
531
|
+
if (this.selectedIndex < this.flatList.length - 1) {
|
|
532
|
+
this.selectedIndex++;
|
|
533
|
+
this.render();
|
|
534
|
+
}
|
|
535
|
+
} else if (key.name === "return" || key.name === "space" || key.name === "right" || key.name === "left") {
|
|
536
|
+
const item = this.flatList[this.selectedIndex];
|
|
537
|
+
if (item && item.node.children && item.node.children.length > 0) {
|
|
538
|
+
item.node.collapsed = !item.node.collapsed;
|
|
539
|
+
this.rebuildFlatList();
|
|
540
|
+
this.render();
|
|
541
|
+
}
|
|
542
|
+
} else if (str === "e" || str === "E") {
|
|
543
|
+
this.expandAll(this.root);
|
|
544
|
+
this.rebuildFlatList();
|
|
545
|
+
this.render();
|
|
546
|
+
} else if (str === "c" || str === "C") {
|
|
547
|
+
this.collapseAll(this.root);
|
|
548
|
+
this.rebuildFlatList();
|
|
549
|
+
this.render();
|
|
550
|
+
} else if (str === "p" || str === "P") {
|
|
551
|
+
const item = this.flatList[this.selectedIndex];
|
|
552
|
+
if (item) {
|
|
553
|
+
await copyToClipboard(item.node.path);
|
|
554
|
+
this.setNotification(`\u2714 Copied JSONPath: ${item.node.path}`);
|
|
555
|
+
}
|
|
556
|
+
} else if (str === "y" || str === "Y") {
|
|
557
|
+
const item = this.flatList[this.selectedIndex];
|
|
558
|
+
if (item) {
|
|
559
|
+
const val = "value" in item.node ? item.node.value : item.node.newValue;
|
|
560
|
+
const textToCopy = typeof val === "object" ? JSON.stringify(val, null, 2) : String(val);
|
|
561
|
+
await copyToClipboard(textToCopy);
|
|
562
|
+
this.setNotification(`\u2714 Copied value to clipboard!`);
|
|
563
|
+
}
|
|
564
|
+
} else if (str === "/") {
|
|
565
|
+
this.isSearching = true;
|
|
566
|
+
this.searchInput = "";
|
|
567
|
+
this.render();
|
|
568
|
+
} else if (key.ctrl && key.name === "c" || key.name === "escape" || str === "q" || str === "Q") {
|
|
569
|
+
process.stdin.removeListener("keypress", onKeypress);
|
|
570
|
+
process.stdin.setRawMode(false);
|
|
571
|
+
process.stdin.pause();
|
|
572
|
+
process.stdout.write("\x1B[?25h\n");
|
|
573
|
+
resolve();
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
process.stdin.on("keypress", onKeypress);
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
export {
|
|
581
|
+
InteractiveViewer,
|
|
582
|
+
buildTree,
|
|
583
|
+
calculateDiffStats,
|
|
584
|
+
copyToClipboard,
|
|
585
|
+
diffJSON,
|
|
586
|
+
formatKey,
|
|
587
|
+
formatValue,
|
|
588
|
+
getValueType,
|
|
589
|
+
prettyPrintDiff,
|
|
590
|
+
prettyPrintTree
|
|
591
|
+
};
|
|
592
|
+
//# sourceMappingURL=index.mjs.map
|