pax_global_header00006660000000000000000000000064134612470660014523gustar00rootroot0000000000000052 comment=15a9f8fe347a30a823acef84ad57945ba0b69826 strip-bom-buf-2.0.0/000077500000000000000000000000001346124706600142105ustar00rootroot00000000000000strip-bom-buf-2.0.0/.editorconfig000066400000000000000000000002571346124706600166710ustar00rootroot00000000000000root = 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/.gitattributes000066400000000000000000000000231346124706600170760ustar00rootroot00000000000000* text=auto eol=lf strip-bom-buf-2.0.0/.gitignore000066400000000000000000000000271346124706600161770ustar00rootroot00000000000000node_modules yarn.lock strip-bom-buf-2.0.0/.npmrc000066400000000000000000000000231346124706600153230ustar00rootroot00000000000000package-lock=false strip-bom-buf-2.0.0/.travis.yml000066400000000000000000000000651346124706600163220ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' - '8' strip-bom-buf-2.0.0/index.d.ts000066400000000000000000000005761346124706600161210ustar00rootroot00000000000000/// /** 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.js000066400000000000000000000005001346124706600156500ustar00rootroot00000000000000'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.ts000066400000000000000000000002451346124706600170670ustar00rootroot00000000000000import * as fs from 'fs'; import {expectType} from 'tsd'; import stripBomBuffer = require('.'); expectType(stripBomBuffer(fs.readFileSync('unicorn.txt'))); strip-bom-buf-2.0.0/license000066400000000000000000000021251346124706600155550ustar00rootroot00000000000000MIT 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.json000066400000000000000000000013331346124706600164760ustar00rootroot00000000000000{ "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.md000066400000000000000000000015641346124706600157750ustar00rootroot00000000000000# strip-bom-buf [![Build Status](https://travis-ci.org/sindresorhus/strip-bom-buf.svg?branch=master)](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/000077500000000000000000000000001346124706600151675ustar00rootroot00000000000000strip-bom-buf-2.0.0/test/fixture-utf16be000066400000000000000000000000241346124706600200460ustar00rootroot00000000000000Unicorn strip-bom-buf-2.0.0/test/fixture-utf16le000066400000000000000000000000241346124706600200600ustar00rootroot00000000000000Unicorn strip-bom-buf-2.0.0/test/fixture-utf8000066400000000000000000000000131346124706600174560ustar00rootroot00000000000000Unicorn strip-bom-buf-2.0.0/test/test.js000066400000000000000000000013061346124706600165040ustar00rootroot00000000000000import 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); });