UNPKG

charset-parser

Version:

Parse charset string from http header and hmtl meta

20 lines (14 loc) 501 B
function getCharset(str){ if(str == null) return null; var charset = str.match(/charset=["]*([^>"\s]+)/i); if(charset instanceof Array && charset.length >= 2) return charset[1]; return null; } module.exports = function (header, binary, default_charset) { var charset = getCharset(header); if(binary != null){ if(charset == null) charset = getCharset(binary); if(charset == null) charset=(typeof default_charset==="undefined")?"utf-8":default_charset; } return charset; };