Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 1 | 'use strict'; |
Paul Lewis | 75090cf | 2019-10-25 13:13:11 | [diff] [blame] | 2 | module.exports = x => { |
3 | if (typeof x !== 'string') { | ||||
4 | throw new TypeError('Expected a string, got ' + typeof x); | ||||
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 5 | } |
6 | |||||
Paul Lewis | 75090cf | 2019-10-25 13:13:11 | [diff] [blame] | 7 | // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string |
8 | // conversion translates it to FEFF (UTF-16 BOM) | ||||
9 | if (x.charCodeAt(0) === 0xFEFF) { | ||||
10 | return x.slice(1); | ||||
Lorne Mitchell | db3885d | 2019-10-24 21:53:01 | [diff] [blame] | 11 | } |
12 | |||||
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 13 | return x; |
14 | }; |