diff --git a/lib/index.ts b/lib/index.ts index 61af8f91..99e899f2 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,4 @@ import { Buffer } from 'buffer' -import isSvg from 'is-svg' const readAsText = (svg: File | Buffer) => new Promise((resolve) => { @@ -30,6 +29,8 @@ export const sanitizeSVG = async (svg: Buffer | File | string | null) => { svgText = svg } + // dynamic import to support CommonJS (package is ESM only) + const isSvg = (await import('is-svg')).default if (!isSvg(svgText)) { throw new Error('Not an svg') } diff --git a/package-lock.json b/package-lock.json index ddb74930..361b82f3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.2", "license": "MIT", "dependencies": { - "is-svg": "^4.3.2" + "is-svg": "^5.0.0" }, "devDependencies": { "@babel/cli": "^7.17.10", @@ -3618,14 +3618,14 @@ "dev": true }, "node_modules/fast-xml-parser": { - "version": "3.21.1", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz", - "integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.1.3.tgz", + "integrity": "sha512-LsNDahCiCcJPe8NO7HijcnukHB24tKbfDDA5IILx9dmW3Frb52lhbeX6MPNUSvyGNfav2VTYpJ/OqkRoVLrh2Q==", "dependencies": { - "strnum": "^1.0.4" + "strnum": "^1.0.5" }, "bin": { - "xml2js": "cli.js" + "fxparser": "src/cli/cli.js" }, "funding": { "type": "paypal", @@ -4047,14 +4047,14 @@ } }, "node_modules/is-svg": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/is-svg/-/is-svg-4.3.2.tgz", - "integrity": "sha512-mM90duy00JGMyjqIVHu9gNTjywdZV+8qNasX8cm/EEYZ53PHDgajvbBwNVvty5dwSAxLUD3p3bdo+7sR/UMrpw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-svg/-/is-svg-5.0.0.tgz", + "integrity": "sha512-sRl7J0oX9yUNamSdc8cwgzh9KBLnQXNzGmW0RVHwg/jEYjGNYHC6UvnYD8+hAeut9WwxRvhG9biK7g/wDGxcMw==", "dependencies": { - "fast-xml-parser": "^3.19.0" + "fast-xml-parser": "^4.1.3" }, "engines": { - "node": ">=6" + "node": ">=14.16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -9131,11 +9131,11 @@ "dev": true }, "fast-xml-parser": { - "version": "3.21.1", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz", - "integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==", + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.1.3.tgz", + "integrity": "sha512-LsNDahCiCcJPe8NO7HijcnukHB24tKbfDDA5IILx9dmW3Frb52lhbeX6MPNUSvyGNfav2VTYpJ/OqkRoVLrh2Q==", "requires": { - "strnum": "^1.0.4" + "strnum": "^1.0.5" } }, "fb-watchman": { @@ -9447,11 +9447,11 @@ "dev": true }, "is-svg": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/is-svg/-/is-svg-4.3.2.tgz", - "integrity": "sha512-mM90duy00JGMyjqIVHu9gNTjywdZV+8qNasX8cm/EEYZ53PHDgajvbBwNVvty5dwSAxLUD3p3bdo+7sR/UMrpw==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-svg/-/is-svg-5.0.0.tgz", + "integrity": "sha512-sRl7J0oX9yUNamSdc8cwgzh9KBLnQXNzGmW0RVHwg/jEYjGNYHC6UvnYD8+hAeut9WwxRvhG9biK7g/wDGxcMw==", "requires": { - "fast-xml-parser": "^3.19.0" + "fast-xml-parser": "^4.1.3" } }, "isexe": { diff --git a/package.json b/package.json index be9220cd..dfc859b7 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,6 @@ "typescript": "^4.7.3" }, "dependencies": { - "is-svg": "^4.3.2" + "is-svg": "^5.0.0" } }