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

Unify newline characters to either \n, \r\n, or \r.

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-38.14%
Maintainers
1
Weekly downloads
 
Created
Source

convert-newline

Build Status Build status Coverage Status

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.

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 are listed on the iconv-lite wiki.

FAQs

Package last updated on 12 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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