You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
567 B

4 years ago
  1. 'use strict';
  2. const htmlCommentRegex = require('html-comment-regex');
  3. function isBinary(buf) {
  4. const isBuf = Buffer.isBuffer(buf);
  5. for (let i = 0; i < 24; i++) {
  6. const charCode = isBuf ? buf[i] : buf.charCodeAt(i);
  7. if (charCode === 65533 || charCode <= 8) {
  8. return true;
  9. }
  10. }
  11. return false;
  12. }
  13. const regex = /^\s*(?:<\?xml[^>]*>\s*)?(?:<!doctype svg[^>]*\s*(?:\[?(?:\s*<![^>]*>\s*)*\]?)*[^>]*>\s*)?<svg[^>]*>[^]*<\/svg>\s*$/i;
  14. module.exports = input => Boolean(input) && !isBinary(input) && regex.test(input.toString().replace(htmlCommentRegex, ''));