项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

21 rivejä
519 B

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