FLUJOS/VISUALIZACION/node_modules/htmlnano/lib/modules/minifyJson.js
2025-11-07 00:06:12 +01:00

27 lines
No EOL
650 B
JavaScript
Executable file

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = minifyJson;
/* Minify JSON inside <script> tags */
function minifyJson(tree) {
// Match all <script> tags which have JSON mime type
tree.match({ tag: 'script', attrs: { type: /(\/|\+)json/ } }, function (node) {
var content = (node.content || []).join('');
if (!content) {
return node;
}
try {
content = JSON.stringify(JSON.parse(content));
} catch (error) {
return node;
}
node.content = [content];
return node;
});
return tree;
}