UNPKG

@pnp/spfx-property-controls

Version:

Reusable property pane controls for SharePoint Framework solutions

61 lines 1.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CodeFormatter = void 0; const CSSFormatter_1 = require("./CSSFormatter"); const ScriptFormatter_1 = require("./ScriptFormatter"); /** * Helper class to format the code. */ class CodeFormatter { /** * Formats CSS code * @param rawCSS */ formatCSS(rawCSS) { const cssFormatter = new CSSFormatter_1.CSSFormatter(); return cssFormatter.css_beautify(rawCSS, null); } /** * Formats JavaScript code * @param rawScript */ formatScript(rawScript) { const scriptFormatter = new ScriptFormatter_1.ScriptFormatter(); return scriptFormatter.js_beautify(rawScript, null); } /** * Formats XML code * @param rawXML */ formatXML(rawXML) { const tab = '\t'; let result = ''; let indent = ''; rawXML.split(/>\s*</).forEach(element => { if (element.match(/^\/\w/)) { indent = indent.substring(tab.length); } result += indent + '<' + element + '>\r\n'; if (element.match(/^<?\w[^>]*[^/]$/)) { indent += tab; } }); return result.substring(1, result.length - 3); } /** * Formats HTML code * @param rawHTML */ formatHTML(rawHTML) { return this.formatXML(rawHTML); } /** * Formats JSON code * @param rawJSON */ formatJSON(rawJSON) { return JSON.stringify(JSON.parse(rawJSON), null, 2); } } exports.CodeFormatter = CodeFormatter; //# sourceMappingURL=CodeFormatter.js.map