aboutsummaryrefslogtreecommitdiff
path: root/node_modules/strip-bom-buf/index.js
blob: e23e718c78d9107705f3e567844af46fda4d7127 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'use strict';
const isUtf8 = require('is-utf8');

module.exports = x => {
	if (!Buffer.isBuffer(x)) {
		throw new TypeError('Expected a Buffer, got ' + typeof x);
	}

	if (x[0] === 0xEF && x[1] === 0xBB && x[2] === 0xBF && isUtf8(x)) {
		return x.slice(3);
	}

	return x;
};