Socket
Socket
Sign inDemoInstall

strip-bom

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

13

index.js
'use strict';
var isUtf8 = require('is-utf8');
module.exports = x => {
if (typeof x !== 'string') {
throw new TypeError('Expected a string, got ' + typeof x);
}
module.exports = function (x) {
// Catches EFBBBF (UTF-8 BOM) because the buffer-to-string
// conversion translates it to FEFF (UTF-16 BOM)
if (typeof x === 'string' && x.charCodeAt(0) === 0xFEFF) {
if (x.charCodeAt(0) === 0xFEFF) {
return x.slice(1);
}
if (Buffer.isBuffer(x) && isUtf8(x) &&
x[0] === 0xEF && x[1] === 0xBB && x[2] === 0xBF) {
return x.slice(3);
}
return x;
};
{
"name": "strip-bom",
"version": "2.0.0",
"description": "Strip UTF-8 byte order mark (BOM) from a string/buffer",
"version": "3.0.0",
"description": "Strip UTF-8 byte order mark (BOM) from a string",
"license": "MIT",

@@ -13,6 +13,6 @@ "repository": "sindresorhus/strip-bom",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "mocha"
"test": "xo && ava"
},

@@ -23,5 +23,6 @@ "files": [

"keywords": [
"strip",
"bom",
"strip",
"byte",
"order",
"mark",

@@ -35,11 +36,8 @@ "unicode",

"text",
"buffer",
"string"
],
"dependencies": {
"is-utf8": "^0.2.0"
},
"devDependencies": {
"mocha": "*"
"ava": "*",
"xo": "*"
}
}
# strip-bom [![Build Status](https://travis-ci.org/sindresorhus/strip-bom.svg?branch=master)](https://travis-ci.org/sindresorhus/strip-bom)
> Strip UTF-8 [byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8) (BOM) from a string/buffer
> Strip UTF-8 [byte order mark](http://en.wikipedia.org/wiki/Byte_order_mark#UTF-8) (BOM) from a string

@@ -20,10 +20,6 @@ From Wikipedia:

```js
var fs = require('fs');
var stripBom = require('strip-bom');
const stripBom = require('strip-bom');
stripBom('\uFEFFunicorn');
//=> 'unicorn'
stripBom(fs.readFileSync('unicorn.txt'));
//=> 'unicorn'
```

@@ -35,2 +31,3 @@

- [strip-bom-cli](https://github.com/sindresorhus/strip-bom-cli) - CLI for this module
- [strip-bom-buf](https://github.com/sindresorhus/strip-bom-buf) - Buffer version of this module
- [strip-bom-stream](https://github.com/sindresorhus/strip-bom-stream) - Stream version of this module

@@ -41,2 +38,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc