index.js 275 B

1234567891011121314
  1. 'use strict';
  2. const isUtf8 = require('is-utf8');
  3. module.exports = x => {
  4. if (!Buffer.isBuffer(x)) {
  5. throw new TypeError('Expected a Buffer, got ' + typeof x);
  6. }
  7. if (x[0] === 0xEF && x[1] === 0xBB && x[2] === 0xBF && isUtf8(x)) {
  8. return x.slice(3);
  9. }
  10. return x;
  11. };