js.beautify
Format JavaScript code for readability and analysis during security testing, helping identify vulnerabilities by standardizing code structure.
Instructions
Beautify and format JavaScript source code
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | JavaScript source code | |
| indentSize | No | Indentation size |
Implementation Reference
- src/tools/js.ts:59-75 (handler)The asynchronous handler function for the 'js.beautify' tool. It takes JavaScript source code and optional indent size, uses the 'js-beautify' library to format it, and returns the beautified code along with length information or an error.async ({ source, indentSize = 2 }: any): Promise<ToolResult> => { try { const beautified = beautify.js(source, { indent_size: indentSize, space_in_empty_paren: true, preserve_newlines: true, }); return formatToolResult(true, { beautified, originalLength: source.length, beautifiedLength: beautified.length, }); } catch (error: any) { return formatToolResult(false, null, error.message); } }
- src/tools/js.ts:49-57 (schema)Input schema definition for the 'js.beautify' tool, specifying required 'source' parameter and optional 'indentSize'.description: 'Beautify and format JavaScript source code', inputSchema: { type: 'object', properties: { source: { type: 'string', description: 'JavaScript source code' }, indentSize: { type: 'number', description: 'Indentation size', default: 2 }, }, required: ['source'], },
- src/tools/js.ts:47-76 (registration)Registration of the 'js.beautify' tool using server.tool(), including schema and handler function.'js.beautify', { description: 'Beautify and format JavaScript source code', inputSchema: { type: 'object', properties: { source: { type: 'string', description: 'JavaScript source code' }, indentSize: { type: 'number', description: 'Indentation size', default: 2 }, }, required: ['source'], }, }, async ({ source, indentSize = 2 }: any): Promise<ToolResult> => { try { const beautified = beautify.js(source, { indent_size: indentSize, space_in_empty_paren: true, preserve_newlines: true, }); return formatToolResult(true, { beautified, originalLength: source.length, beautifiedLength: beautified.length, }); } catch (error: any) { return formatToolResult(false, null, error.message); } } );
- src/tools/js.ts:3-3 (helper)Import of the 'js-beautify' library, which is used as the core formatting utility in the tool handler.import beautify from 'js-beautify';