GitShow/sindresorhus/is-svg
sindresorhus

is-svg

Check if a string or buffer is SVG

by sindresorhus
Star on GitHubForknpm

JavaScript

142 stars21 forks14 contributorsQuiet · 6mo agoSince 2014v6.1.0MIT

Meet the team

See all 14 on GitHub →
sindresorhus
sindresorhus51 contributions
kevva
kevva5 contributions
Borewit
Borewit2 contributions
BendingBender
BendingBender2 contributions
SamVerschueren
SamVerschueren1 contribution
urbanautomaton
urbanautomaton1 contribution
steffenweber
steffenweber1 contribution
StephanHoyer
StephanHoyer1 contribution

Languages

View on GitHub →
JavaScript97.3%
TypeScript2.7%

Commit activity

Last 12 weeks · 0 commits

Full graph →

Community health

4 of 6 standards met

Community profile →
85
✓README✓License✓Contributing✓Code of Conduct○Issue Template○PR Template

Recent PRs & issues

Quiet · 1 in progress · Last activity 6mo ago
See all on GitHub →
jayscheidt
v6: Performance regression when attempting to check non-svg imagesOpenIssue

Hello! We recently upgraded from -> and noticed a performance regression when calling on image buffers that are not XML. Large and images would previously get excuted around and now take upwards of . We would like to continue using the option for scenarios when the image buffer is an . In the meantime, we have had to downgrade to . This is what our function looks like. We take each image buffer and provide it to . If it returns a result, we return the content-type . If it doesn't, we then have infer it. Following the performance script from https://github.com/sindresorhus/is-svg/issues/42, I created another one to measure the performance of different file sizes for , , and . Here is the perf script, running on node 22.22.0 v5.1.0 results: v6.1.0 results: Should we be performing the custom detector suggestion from https://github.com/sindresorhus/file-type?tab=readme-ov-file#customdetectors to determine the file is XML, before trying to use ? If so, it would be great if this package explicitly states it should not be used until the content type is known to be XML. If this package should handle all image buffers in a timely manner, that would definitely be our preference, since it matches how we've used this package for the past many years! Thanks!

jayscheidt · 5mo ago
Borewit
Update `@file-type/xml` to `^1.1.0`OpenPR
Borewit · 6mo ago

Recent fixes

View closed PRs →
guoyangzhen
Add fast pre-check to skip XmlTextDetector on non-XML contentMergedPR

Fixes #46 Problem v6 introduced XmlTextDetector with fullScan by default. When checking non-SVG buffers (PNG/JPG), the detector scans the entire content — large images can be megabytes, causing ~600ms latency vs v5's ~0.1ms. Fix Add a cheap pre-check before the expensive XmlTextDetector: 1. Content must start with 2. First 512 bytes must contain , , or This rejects non-XML content immediately without running the full scan. Real SVG content passes through unchanged.

guoyangzhen · 5mo ago
bencurio
Buffer input is no longer supported (breaking change?)ClosedIssue

Hi! 👋 It looks like recent versions no longer accept Buffer input and now require a string. Older versions (e.g. v4.3.2) still worked with buffers, so this feels like a breaking change. Would you consider supporting Buffer again? Thank you!

bencurio · 6mo ago
Borewit
Add support for `Uint8Array`, detecting SVG in binary dataMergedPR

Extend , to which you can provide, in addition to an XML an . This may be convenient as the SVG may be encoded in multiple ways. Following text encodings automatically detected and supported: UTF8 without a preceding BOM field UTF8 with a preceding BOM field UTF16-LE without a preceding BOM field UTF16-BE without a preceding BOM field UTF16-LE with a preceding BOM field UTF16-BE with a preceding BOM field Build on top of #40, utilizing @file-type/xml, the XML detection plugin for file-type.

Borewit · 1y ago
Structured data for AI agents

Repository: sindresorhus/is-svg. Description: Check if a string or buffer is SVG Stars: 142, Forks: 21. Primary language: JavaScript. Languages: JavaScript (97.3%), TypeScript (2.7%). License: MIT. Latest release: v6.1.0 (1y ago). Open PRs: 1, open issues: 1. Last activity: 6mo ago. Community health: 85%. Top contributors: sindresorhus, kevva, Borewit, BendingBender, SamVerschueren, urbanautomaton, steffenweber, StephanHoyer, kraftner, tprobinson and others.

·@ofershap

Replace github.com with gitshow.dev