Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/is-svg
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d01521d9a12327a7e0e4f670ed8401710dc7f191
Choose a base ref
...
head repository: sindresorhus/is-svg
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 35aeafd2b0c8f119a7b2130e6f67172baa1c2fa5
Choose a head ref
  • 2 commits
  • 2 files changed
  • 2 contributors

Commits on Feb 28, 2023

  1. Copy the full SHA
    98725ee View commit details
  2. 4.4.0

    sindresorhus committed Feb 28, 2023
    Copy the full SHA
    35aeafd View commit details
Showing with 7 additions and 6 deletions.
  1. +5 −4 index.js
  2. +2 −2 package.json
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
'use strict';
const parser = require('fast-xml-parser');
const {XMLParser, XMLValidator} = require('fast-xml-parser');

const isSvg = input => {
if (input === undefined || input === null) {
return false;
}

// TODO: Remove the `.replace` call when using `fast-xml-parser@4` which has fixed the bug.
input = input.toString().trim().replace(/\n/g, ' ');
input = input.toString().trim();

if (input.length === 0) {
return false;
}

// Has to be `!==` as it can also return an object with error info.
if (parser.validate(input) !== true) {
if (XMLValidator.validate(input) !== true) {
return false;
}

let jsonObject;
const parser = new XMLParser();

try {
jsonObject = parser.parse(input);
} catch (_) {
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "is-svg",
"version": "4.3.2",
"version": "4.4.0",
"description": "Check if a string or buffer is SVG",
"license": "MIT",
"repository": "sindresorhus/is-svg",
@@ -37,7 +37,7 @@
"buffer"
],
"dependencies": {
"fast-xml-parser": "^3.19.0"
"fast-xml-parser": "^4.1.3"
},
"devDependencies": {
"@types/node": "^11.13.0",