MCPcopy Create free account
hub / github.com/svg/svgo / stringifySvg

Function stringifySvg

lib/stringifier.js:66–98  ·  view source on GitHub ↗
(data, userOptions = {})

Source from the content-addressed store, hash-verified

64 * @returns {string}
65 */
66export const stringifySvg = (data, userOptions = {}) => {
67 /** @type {Options} */
68 const config = { ...defaults, ...userOptions };
69 const indent = config.indent;
70 let newIndent = ' ';
71 if (typeof indent === 'number' && Number.isNaN(indent) === false) {
72 newIndent = indent < 0 ? '\t' : ' '.repeat(indent);
73 } else if (typeof indent === 'string') {
74 newIndent = indent;
75 }
76 /** @type {State} */
77 const state = {
78 indent: newIndent,
79 textContext: null,
80 indentLevel: 0,
81 };
82 const eol = config.eol === 'crlf' ? '\r\n' : '\n';
83 if (config.pretty) {
84 config.doctypeEnd += eol;
85 config.procInstEnd += eol;
86 config.commentEnd += eol;
87 config.cdataEnd += eol;
88 config.tagShortEnd += eol;
89 config.tagOpenEnd += eol;
90 config.tagCloseEnd += eol;
91 config.textEnd += eol;
92 }
93 let svg = stringifyNode(data, config, state);
94 if (config.finalNewline && svg.length > 0 && !svg.endsWith('\n')) {
95 svg += eol;
96 }
97 return svg;
98};
99
100/**
101 * @param {import('./types.js').XastParent} data

Callers 2

optimizeFunction · 0.90
parser.test.jsFile · 0.90

Calls 1

stringifyNodeFunction · 0.85

Tested by

no test coverage detected