pax_global_header 0000666 0000000 0000000 00000000064 13461247066 0014523 g ustar 00root root 0000000 0000000 52 comment=15a9f8fe347a30a823acef84ad57945ba0b69826
strip-bom-buf-2.0.0/ 0000775 0000000 0000000 00000000000 13461247066 0014210 5 ustar 00root root 0000000 0000000 strip-bom-buf-2.0.0/.editorconfig 0000664 0000000 0000000 00000000257 13461247066 0016671 0 ustar 00root root 0000000 0000000 root = true
[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.yml]
indent_style = space
indent_size = 2
strip-bom-buf-2.0.0/.gitattributes 0000664 0000000 0000000 00000000023 13461247066 0017076 0 ustar 00root root 0000000 0000000 * text=auto eol=lf
strip-bom-buf-2.0.0/.gitignore 0000664 0000000 0000000 00000000027 13461247066 0016177 0 ustar 00root root 0000000 0000000 node_modules
yarn.lock
strip-bom-buf-2.0.0/.npmrc 0000664 0000000 0000000 00000000023 13461247066 0015323 0 ustar 00root root 0000000 0000000 package-lock=false
strip-bom-buf-2.0.0/.travis.yml 0000664 0000000 0000000 00000000065 13461247066 0016322 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- '12'
- '10'
- '8'
strip-bom-buf-2.0.0/index.d.ts 0000664 0000000 0000000 00000000576 13461247066 0016121 0 ustar 00root root 0000000 0000000 ///
/**
Strip UTF-8 [byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8) (BOM) from a buffer.
@example
```
import * as fs from 'fs';
import stripBomBuffer = require('strip-bom-buf');
stripBomBuffer(fs.readFileSync('unicorn.txt'));
//=> 'unicorn'
```
*/
declare function stripBomBuffer(buffer: Buffer): Buffer;
export = stripBomBuffer;
strip-bom-buf-2.0.0/index.js 0000664 0000000 0000000 00000000500 13461247066 0015650 0 ustar 00root root 0000000 0000000 'use strict';
const isUtf8 = require('is-utf8');
module.exports = buffer => {
if (!Buffer.isBuffer(buffer)) {
throw new TypeError(`Expected a Buffer, got ${typeof buffer}`);
}
if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF && isUtf8(buffer)) {
return buffer.slice(3);
}
return buffer;
};
strip-bom-buf-2.0.0/index.test-d.ts 0000664 0000000 0000000 00000000245 13461247066 0017067 0 ustar 00root root 0000000 0000000 import * as fs from 'fs';
import {expectType} from 'tsd';
import stripBomBuffer = require('.');
expectType(stripBomBuffer(fs.readFileSync('unicorn.txt')));
strip-bom-buf-2.0.0/license 0000664 0000000 0000000 00000002125 13461247066 0015555 0 ustar 00root root 0000000 0000000 MIT License
Copyright (c) Sindre Sorhus (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
strip-bom-buf-2.0.0/package.json 0000664 0000000 0000000 00000001333 13461247066 0016476 0 ustar 00root root 0000000 0000000 {
"name": "strip-bom-buf",
"version": "2.0.0",
"description": "Strip UTF-8 byte order mark (BOM) from a buffer",
"license": "MIT",
"repository": "sindresorhus/strip-bom-buf",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"strip",
"bom",
"byte",
"order",
"mark",
"unicode",
"utf8",
"utf-8",
"remove",
"delete",
"trim",
"text",
"buffer"
],
"dependencies": {
"is-utf8": "^0.2.1"
},
"devDependencies": {
"@types/node": "^11.13.8",
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}
strip-bom-buf-2.0.0/readme.md 0000664 0000000 0000000 00000001564 13461247066 0015775 0 ustar 00root root 0000000 0000000 # strip-bom-buf [](https://travis-ci.org/sindresorhus/strip-bom-buf)
> Strip UTF-8 [byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8) (BOM) from a buffer
From Wikipedia:
> The Unicode Standard permits the BOM in UTF-8, but does not require nor recommend its use. Byte order has no meaning in UTF-8.
## Install
```
$ npm install strip-bom-buf
```
## Usage
```js
const fs = require('fs');
const stripBomBuffer = require('strip-bom-buf');
stripBomBuffer(fs.readFileSync('unicorn.txt'));
//=> 'unicorn'
```
## Related
- [strip-bom](https://github.com/sindresorhus/strip-bom) - String version of this module
- [strip-bom-stream](https://github.com/sindresorhus/strip-bom-stream) - Stream version of this module
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
strip-bom-buf-2.0.0/test/ 0000775 0000000 0000000 00000000000 13461247066 0015167 5 ustar 00root root 0000000 0000000 strip-bom-buf-2.0.0/test/fixture-utf16be 0000664 0000000 0000000 00000000024 13461247066 0020046 0 ustar 00root root 0000000 0000000 U n i c o r n
strip-bom-buf-2.0.0/test/fixture-utf16le 0000664 0000000 0000000 00000000024 13461247066 0020060 0 ustar 00root root 0000000 0000000 U n i c o r n
strip-bom-buf-2.0.0/test/fixture-utf8 0000664 0000000 0000000 00000000013 13461247066 0017456 0 ustar 00root root 0000000 0000000 Unicorn
strip-bom-buf-2.0.0/test/test.js 0000664 0000000 0000000 00000001306 13461247066 0016504 0 ustar 00root root 0000000 0000000 import fs from 'fs';
import path from 'path';
import test from 'ava';
import stripBomBuffer from '..';
test('strips BOM from UTF-8 buffer', t => {
const fixture = fs.readFileSync(path.join(__dirname, '/fixture-utf8'));
t.true(stripBomBuffer(fixture).equals(Buffer.from('Unicorn\n')));
});
test('doesn\'t strip anything that looks like a UTF-8-encoded BOM from UTF16LE', t => {
const fixture = fs.readFileSync(path.join(__dirname, 'fixture-utf16le'));
t.is(stripBomBuffer(fixture), fixture);
});
test('doesn\'t strip anything that looks like a UTF-8-encoded BOM from UTF16BE', t => {
const fixture = fs.readFileSync(path.join(__dirname, 'fixture-utf16be'));
t.is(stripBomBuffer(fixture), fixture);
});