UNPKG

express-image-validator

Version:

Validator of various image parameters in Express.js applications

39 lines (38 loc) 981 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isSvg = isSvg; const fast_xml_parser_1 = require("fast-xml-parser"); /** * Copyright (c) 2025 [sindresorhus](https://github.com/sindresorhus). * * Licensed under the MIT License. * @see https://github.com/sindresorhus/is-svg */ function isSvg(input) { const xml = input.toString().trim(); if (xml === undefined || xml === null) { return false; } if (xml.length === 0) { return false; } // Has to be `!==` as it can also return an object with error info. if (fast_xml_parser_1.XMLValidator.validate(xml) !== true) { return false; } let jsonObject; const parser = new fast_xml_parser_1.XMLParser(); try { jsonObject = parser.parse(input); } catch { return false; } if (!jsonObject) { return false; } if (!('svg' in jsonObject)) { return false; } return true; }