2017-12-15 10:56:14 -08:00
|
|
|
'use strict';
|
2021-05-08 05:39:21 -07:00
|
|
|
|
|
|
|
module.exports = string => {
|
|
|
|
if (typeof string !== 'string') {
|
|
|
|
throw new TypeError(`Expected a string, got ${typeof string}`);
|
2017-12-15 10:56:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
|
|
|
|
// conversion translates it to FEFF (UTF-16 BOM)
|
2021-05-08 05:39:21 -07:00
|
|
|
if (string.charCodeAt(0) === 0xFEFF) {
|
|
|
|
return string.slice(1);
|
2017-12-15 10:56:14 -08:00
|
|
|
}
|
|
|
|
|
2021-05-08 05:39:21 -07:00
|
|
|
return string;
|
2017-12-15 10:56:14 -08:00
|
|
|
};
|