1 | 'use strict';
|
2 | const htmlCommentRegex = require('html-comment-regex');
|
3 |
|
4 | const isBinary = buffer => {
|
5 | const isBuffer = Buffer.isBuffer(buffer);
|
6 |
|
7 | for (let i = 0; i < 24; i++) {
|
8 | const characterCode = isBuffer ? buffer[i] : buffer.charCodeAt(i);
|
9 |
|
10 | if (characterCode === 65533 || characterCode <= 8) {
|
11 | return true;
|
12 | }
|
13 | }
|
14 |
|
15 | return false;
|
16 | };
|
17 |
|
18 | const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i;
|
19 |
|
20 | const isSvg = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));
|
21 |
|
22 | module.exports = isSvg;
|
23 | module.exports.default = isSvg;
|