Comparing version 0.2.1 to 0.3.0
18
cli.js
@@ -8,8 +8,2 @@ #!/usr/bin/env node | ||
function stdin(cb) { | ||
var ret = ''; | ||
process.stdin.on('data', function (data) { ret += data }); | ||
process.stdin.on('end', cb.bind(null, ret)); | ||
} | ||
function help() { | ||
@@ -26,7 +20,3 @@ console.log(pkg.description); | ||
function init(data) { | ||
process.stdout.write(stripBom(data)); | ||
} | ||
if (process.argv.indexOf('-h') !== -1 || process.argv.indexOf('--help') !== -1) { | ||
if (process.argv.indexOf('--help') !== -1) { | ||
help(); | ||
@@ -36,3 +26,3 @@ return; | ||
if (process.argv.indexOf('-v') !== -1 || process.argv.indexOf('--version') !== -1) { | ||
if (process.argv.indexOf('--version') !== -1) { | ||
console.log(pkg.version); | ||
@@ -48,5 +38,5 @@ return; | ||
init(fs.readFileSync(input)); | ||
fs.createReadStream(input).pipe(stripBom.stream()).pipe(process.stdout); | ||
} else { | ||
stdin(init); | ||
process.stdin.pipe(stripBom.stream()).pipe(process.stdout); | ||
} |
17
index.js
'use strict'; | ||
var isUtf8 = require('is-utf8'); | ||
module.exports = function (arg) { | ||
var stripBom = module.exports = function (arg) { | ||
if (typeof arg === 'string') { | ||
@@ -16,1 +16,16 @@ return arg.replace(/^\uFEFF/g, ''); | ||
}; | ||
stripBom.stream = function () { | ||
var through = require('through2'); | ||
var first = true; | ||
return through(function (chunk, enc, cb) { | ||
if (first) { | ||
first = false; | ||
chunk = stripBom(chunk); | ||
} | ||
this.push(chunk); | ||
cb(); | ||
}); | ||
}; |
{ | ||
"name": "strip-bom", | ||
"version": "0.2.1", | ||
"description": "Strip UTF-8 byte order mark (BOM) from a string/buffer", | ||
"version": "0.3.0", | ||
"description": "Strip UTF-8 byte order mark (BOM) from a string/buffer/stream", | ||
"license": "MIT", | ||
@@ -40,10 +40,14 @@ "repository": "sindresorhus/strip-bom", | ||
"buffer", | ||
"string" | ||
"string", | ||
"stream", | ||
"streams" | ||
], | ||
"dependencies": { | ||
"is-utf8": "^0.2.0" | ||
"is-utf8": "^0.2.0", | ||
"through2": "^0.4.1" | ||
}, | ||
"devDependencies": { | ||
"concat-stream": "^1.4.5", | ||
"mocha": "*" | ||
} | ||
} |
# 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/buffer/stream | ||
@@ -13,3 +13,3 @@ | ||
```bash | ||
```sh | ||
$ npm install --save strip-bom | ||
@@ -32,14 +32,21 @@ ``` | ||
Or as a [Transform stream](http://nodejs.org/api/stream.html#stream_class_stream_transform): | ||
```js | ||
var fs = require('fs'); | ||
var stripBom = require('strip-bom'); | ||
fs.createReadStream('unicorn.txt') | ||
.pipe(stripBom.stream()) | ||
.pipe(fs.createWriteStream('unicorn.txt')); | ||
``` | ||
## CLI | ||
You can also use it as a CLI app by installing it globally: | ||
```bash | ||
```sh | ||
$ npm install --global strip-bom | ||
``` | ||
#### Usage | ||
```bash | ||
```sh | ||
$ strip-bom --help | ||
@@ -58,2 +65,2 @@ | ||
[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3467
57
64
2
2
+ Addedthrough2@^0.4.1
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedobject-keys@0.4.0(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.4.2(transitive)
+ Addedxtend@2.1.2(transitive)