You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
465 B
JavaScript
18 lines
465 B
JavaScript
import iconv from 'iconv-lite';
|
|
import { DEFAULT_ENCODING, ENCODING_RE } from './constants';
|
|
|
|
// check a string for encoding; this is
|
|
// used in our fetchResource function to
|
|
// ensure correctly encoded responses
|
|
export default function getEncoding(str) {
|
|
let encoding = DEFAULT_ENCODING;
|
|
const matches = ENCODING_RE.exec(str);
|
|
if (matches !== null) {
|
|
[, str] = matches;
|
|
}
|
|
if (iconv.encodingExists(str)) {
|
|
encoding = str;
|
|
}
|
|
return encoding;
|
|
}
|