convert-newline
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "convert-newline", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Convert newlines to specifc one", | ||
@@ -9,8 +9,20 @@ "homepage": "https://github.com/takenspc/convert-newline/", | ||
"scripts": { | ||
"coverage": "istanbul cover --report html node_modules/mocha/bin/_mocha -- test.js -R spec", | ||
"test": "eslint . && mocha test.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/takenspc/convert-newline.git" | ||
}, | ||
"dependencies": { | ||
"iconv-lite": "^0.4.8" | ||
}, | ||
"devDependencies": { | ||
"iconv-lite": "^0.4.8", | ||
"eslint": "^0.20.0", | ||
"istanbul": "^0.3.13", | ||
"mocha": "^2.2.4" | ||
}, | ||
"engines": { | ||
"iojs" : "2.0.x" | ||
} | ||
} |
@@ -1,1 +0,75 @@ | ||
# convert-newline | ||
# convert-newline | ||
Unify newline characters to either `\n`,`\r\n`, or `\r`. | ||
## Usage | ||
### String | ||
var convertNewline = require("convert-newline"); | ||
var converter = convertNewline("lf").string(); | ||
converter("AAA\rBBB\r\nCCC\n"); // -> "AAA\nBBB\nCCC\n" | ||
### Buffer | ||
var convertNewline = require("convert-newline"); | ||
var buffer = new Buffer("AAA\rBBB\r\nCCC\n"); | ||
var converter = convertNewline("lf").buffer(); | ||
var newBuffer = converter(buffer); | ||
newBuffer.toString(); // -> "AAA\nBBB\nCCC\n" | ||
Converting non-utf8 encoded buffers is supported. | ||
var iconv = require("iconv-lite"); | ||
var convertNewline = require("convert-newline"); | ||
var buffer = iconv.encode(new Buffer("あ\rい\r\nう\n"), "shift_jis"); | ||
var converter = convertNewline("lf", "shift_jis").buffer(); | ||
var newBuffer = converter(buffer); | ||
iconv.decode(newBuffer, "shift_jis"); // -> "あ\nい\nう\n" | ||
### Stream | ||
var fs = require("fs"); | ||
var convertNewline = require("convert-newline"); | ||
var reader = fs.createReadStream("foo.txt", { encoding: "utf8" }); | ||
var writer = fs.createWriteStream("bar.txt"); | ||
var converter = convertNewline("lf").stream(); | ||
reader | ||
.pipe(converter) | ||
.pipe(writer); | ||
To convert non-utf8 encoded streams, you can use [iconv-lite](https://github.com/ashtuchkin/iconv-lite/). | ||
var fs = require("fs"); | ||
var iconv = require("iconv-lite"); | ||
var convertNewline = require("convert-newline"); | ||
var reader = fs.createReadStream("foo.txt"); | ||
var writer = fs.createWriteStream("bar.txt"); | ||
var converter = convertNewline("lf").stream(); | ||
reader | ||
.pipe(iconv.decodeStream("shift_jis")) | ||
.pipe(converter) | ||
.pipe(iconv.encodeStream("shift_jis")) | ||
.pipe(writer); | ||
## API | ||
### convertNewline(newline, encoding) | ||
#### newline | ||
Target newline characters. Either `"lf"`, `"crlf"`, or `"cr"`. | ||
### encoding | ||
Optional. The encoding of the buffer. | ||
[Supported encodings](https://github.com/ashtuchkin/iconv-lite/wiki/Supported-Encodings) are listed on the [iconv-lite](https://github.com/ashtuchkin/iconv-lite/) wiki. |
@@ -136,3 +136,3 @@ "use strict"; | ||
var originalFilename = "data/utf8/" + key2 + ".txt"; | ||
var targetFilename = originalFilename + "." + key1 + ".txt"; | ||
var targetFilename = originalFilename + "." + key1; | ||
var options = { | ||
@@ -167,3 +167,3 @@ encoding: UTF8 | ||
var originalFilename = "data/shift_jis/" + key2 + ".txt"; | ||
var targetFilename = originalFilename + "." + key1 + ".txt"; | ||
var targetFilename = originalFilename + "." + key1; | ||
var reader = fs.createReadStream(originalFilename); | ||
@@ -170,0 +170,0 @@ var writer = fs.createWriteStream(targetFilename); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
13337
291
75
1
1
3
38
+ Addediconv-lite@^0.4.8
+ Addediconv-lite@0.4.24(transitive)
+ Addedsafer-buffer@2.1.2(transitive)