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.

index.js 407B

1234567891011121314151617
  1. 'use strict';
  2. var isUtf8 = require('is-utf8');
  3. module.exports = function (x) {
  4. // Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
  5. // conversion translates it to FEFF (UTF-16 BOM)
  6. if (typeof x === 'string' && x.charCodeAt(0) === 0xFEFF) {
  7. return x.slice(1);
  8. }
  9. if (Buffer.isBuffer(x) && isUtf8(x) &&
  10. x[0] === 0xEF && x[1] === 0xBB && x[2] === 0xBF) {
  11. return x.slice(3);
  12. }
  13. return x;
  14. };