Initial commit
[yaffs-website] / node_modules / strip-bom / index.js
1 'use strict';
2 var isUtf8 = require('is-utf8');
3
4 var stripBom = module.exports = function (arg) {
5         if (typeof arg === 'string') {
6                 return arg.replace(/^\ufeff/g, '');
7         }
8
9         if (Buffer.isBuffer(arg) && isUtf8(arg) &&
10                 arg[0] === 0xef && arg[1] === 0xbb && arg[2] === 0xbf) {
11                 return arg.slice(3);
12         }
13
14         return arg;
15 };
16
17 stripBom.stream = function () {
18         var firstChunk = require('first-chunk-stream');
19
20         return firstChunk({minSize: 3}, function (chunk, enc, cb) {
21                 this.push(stripBom(chunk));
22                 cb();
23         });
24 };