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