Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

convert-newline

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

convert-newline - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.travis.yml

16

package.json
{
"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.

4

test.js

@@ -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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc