MCPcopy Index your code
hub / github.com/zxlie/FeHelper / formatSync

Function formatSync

apps/json-format/format-lib.js:1749–1800  ·  view source on GitHub ↗
(jsonStr, skin, escapeJsonString)

Source from the content-addressed store, hash-verified

1747
1748 // 同步的方式格式化
1749 let formatSync = function (jsonStr, skin, escapeJsonString) {
1750 if (!_canRenderFormattedResult()) {
1751 _clearOptionBar();
1752 return;
1753 }
1754 _initElements();
1755
1756 // 设置转义功能标志
1757 if (escapeJsonString !== undefined) {
1758 escapeJsonStringEnabled = escapeJsonString;
1759 }
1760
1761 // 显示格式化进度
1762 formattingMsg.show();
1763
1764 try {
1765 // 先验证JSON是否有效(使用与worker一致的BigInt安全解析)
1766 let parsedJson = _parseWithBigInt(jsonStr);
1767 cachedJsonString = _safeStringify(parsedJson, 4);
1768
1769 // 保留原始 JSON 内容,供旧 DOM 节点复用。
1770 jfPre.html(htmlspecialchars(cachedJsonString));
1771
1772 // 使用完整的JSON美化功能
1773 let formattedHtml = formatJsonToHtml(parsedJson, skin);
1774
1775 // 创建正确的HTML结构:jfContent > formattedJson
1776 let formattedJsonDiv = $('<div id="formattedJson"></div>');
1777 formattedJsonDiv.html(formattedHtml);
1778 jfContent.html(formattedJsonDiv);
1779
1780 // 隐藏进度提示
1781 formattingMsg.hide();
1782
1783 // 构建操作栏
1784 _buildOptionBar();
1785 // 事件绑定
1786 _addEvents();
1787 // 支持文件下载
1788 _downloadSupport(cachedJsonString);
1789 _clearJsonSearch();
1790 _emitFormatReady();
1791
1792 return;
1793 } catch (e) {
1794 console.error('JSON格式化失败:', e);
1795 jfContent.html(`<div class="error">JSON格式化失败: ${e.message}</div>`);
1796
1797 // 隐藏进度提示
1798 formattingMsg.hide();
1799 }
1800 };
1801
1802 // 与 worker 保持一致的 BigInt 安全解析:
1803 // 1) 给可能的大整数加标记;2) 使用reviver还原为原生BigInt

Callers 2

workerErrorHandlerFunction · 0.85
formatFunction · 0.85

Calls 15

_clearOptionBarFunction · 0.85
_initElementsFunction · 0.85
_parseWithBigIntFunction · 0.85
_safeStringifyFunction · 0.85
_buildOptionBarFunction · 0.85
_addEventsFunction · 0.85
_downloadSupportFunction · 0.85
_clearJsonSearchFunction · 0.85
_emitFormatReadyFunction · 0.85
showMethod · 0.80
hideMethod · 0.80

Tested by

no test coverage detected