New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.2 to 0.0.3

.eslintignore

13

package.json
{
"name": "convert-newline",
"version": "0.0.2",
"description": "Convert newlines to specifc one",
"version": "0.0.3",
"description": "Unify newline characters to either \\n, \\r\\n, or \\r.",
"homepage": "https://github.com/takenspc/convert-newline/",

@@ -9,4 +9,6 @@ "author": "Takeshi Kurosawa <taken.spc@gmail.com>",

"scripts": {
"coverage": "istanbul cover --report html node_modules/mocha/bin/_mocha -- test.js -R spec",
"test": "eslint . && mocha test.js"
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -- test.js -R spec",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "eslint .",
"test": "mocha test.js"
},

@@ -18,2 +20,3 @@ "repository": {

"dependencies": {
"coveralls": "^2.11.2",
"iconv-lite": "^0.4.8"

@@ -27,4 +30,4 @@ },

"engines": {
"iojs" : "2.0.x"
"iojs": "2.0.x"
}
}
# convert-newline
[![Build Status](https://travis-ci.org/takenspc/convert-newline.svg?branch=master)](https://travis-ci.org/takenspc/convert-newline)
[![Coverage Status](https://coveralls.io/repos/takenspc/convert-newline/badge.svg?branch=master)](https://coveralls.io/r/takenspc/convert-newline?branch=master)
Unify newline characters to either `\n`,`\r\n`, or `\r`.

@@ -4,0 +7,0 @@

"use strict";
var assert = require("assert");
var fs = require("fs");
var path = require("path");
var util = require("util");
var iconv = require("iconv-lite");

@@ -10,2 +12,3 @@ var convertNewline = require("./");

//
var PACKAGE_NAME = "convert-newline";
var UTF8 = "utf8";

@@ -27,5 +30,5 @@ var SHIFT_JIS = "shift_jis";

return {
cr: fs.readFileSync("data/utf8/cr.txt"),
crlf: fs.readFileSync("data/utf8/crlf.txt"),
lf: fs.readFileSync("data/utf8/lf.txt")
cr: fs.readFileSync(path.join("data", UTF8, "cr.txt")),
crlf: fs.readFileSync(path.join("data", UTF8, "crlf.txt")),
lf: fs.readFileSync(path.join("data", UTF8, "lf.txt"))
};

@@ -45,5 +48,5 @@

return {
cr: fs.readFileSync("data/shift_jis/cr.txt"),
crlf: fs.readFileSync("data/shift_jis/crlf.txt"),
lf: fs.readFileSync("data/shift_jis/lf.txt")
cr: fs.readFileSync(path.join("data", SHIFT_JIS, "cr.txt")),
crlf: fs.readFileSync(path.join("data", SHIFT_JIS, "crlf.txt")),
lf: fs.readFileSync(path.join("data", SHIFT_JIS, "lf.txt"))
};

@@ -70,11 +73,13 @@ }

//
describe("crlf", function() {
it("string", function() {
var data = getStringTestData();
var keys = Object.keys(data);
keys.forEach(function(key1) {
var converter = convertNewline(key1).string();
var reference = data[key1];
keys.forEach(function(key2) {
assert.strictEqual(converter(data[key2]), reference, key2 + " were converted to " + key1);
describe(PACKAGE_NAME, function() {
describe("in string mode", function() {
var testData = getStringTestData();
var newlinews = Object.keys(testData);
newlinews.forEach(function(toNewline) {
newlinews.forEach(function(fromNewline) {
it(util.format("should convert from %s to %s", fromNewline, toNewline), function() {
var converter = convertNewline(toNewline).string();
var reference = testData[toNewline];
assert.strictEqual(converter(testData[fromNewline]), reference);
});
});

@@ -84,10 +89,12 @@ });

it("buffer (simple)", function() {
var data = getUTF8BufferTestData();
var keys = Object.keys(data);
keys.forEach(function(key1) {
var converter = convertNewline(key1).buffer();
var reference = data[key1];
keys.forEach(function(key2) {
assert.ok(reference.equals(converter(data[key2])), key2 + " were converted to " + key1);
describe("in buffer mode (simple)", function() {
var testData = getUTF8BufferTestData();
var newlines = Object.keys(testData);
newlines.forEach(function(toNewline) {
newlines.forEach(function(fromNewline) {
it(util.format("should convert from %s to %s", fromNewline, toNewline), function() {
var converter = convertNewline(toNewline).buffer();
var reference = testData[toNewline];
assert.ok(reference.equals(converter(testData[fromNewline])));
});
});

@@ -97,10 +104,12 @@ });

describe("buffer (iconv)", function() {
var data = getShiftJISBufferTestData();
var keys = Object.keys(data);
keys.forEach(function(key1) {
var converter = convertNewline(key1, SHIFT_JIS).buffer();
var reference = data[key1];
keys.forEach(function(key2) {
assert.ok(reference.equals(converter(data[key2])), key2 + " were converted to " + key1);
describe("in buffer mode (iconv)", function() {
var testData = getShiftJISBufferTestData();
var newlines = Object.keys(testData);
newlines.forEach(function(toNewline) {
newlines.forEach(function(fromNewline) {
it(util.format("should convert from %s to %s", fromNewline, toNewline), function() {
var converter = convertNewline(toNewline, SHIFT_JIS).buffer();
var reference = testData[toNewline];
assert.ok(reference.equals(converter(testData[fromNewline])));
});
});

@@ -110,13 +119,17 @@ });

it("load test data (utf8)", function() {
var filedata = getUTF8FileTestData();
var bufferdata = getUTF8FileTestData();
var keys = Object.keys(filedata);
keys.forEach(function(key1) {
var reference = bufferdata[key1];
assert.ok(reference.equals(filedata[key1]), key1 + ".txt is loaded correctly");
keys.forEach(function(key2) {
if (key1 !== key2) {
assert.ok(!reference.equals(filedata[key2]), key1 + ".txt is not same as " + key2 + ".txt");
}
describe("test code (utf8)", function() {
var testData = getUTF8FileTestData();
var referenceData = getUTF8BufferTestData();
var newlines = Object.keys(testData);
newlines.forEach(function(newline1) {
it("should load test data correctly", function() {
newlines.forEach(function (newline2) {
var target = testData[newline2];
var reference = referenceData[newline1];
if (newline1 === newline2) {
assert.ok(reference.equals(target), util.format("%s test data is loaded correctly", newline1));
} else {
assert.ok(!reference.equals(target), util.format("%s test data is not same as %s correctly", newline1, newline2));
}
});
});

@@ -126,12 +139,17 @@ });

it("load test data (shift_jis)", function() {
var filedata = getShiftJISFileTestData();
var bufferdata = getShiftJISBufferTestData();
var keys = Object.keys(filedata);
keys.forEach(function(key1) {
assert.ok(bufferdata[key1].equals(filedata[key1]), key1 + ".txt is loaded correctly");
keys.forEach(function(key2) {
if (key1 !== key2) {
assert.ok(!filedata[key1].equals(filedata[key2]), key1 + ".txt is not same as " + key2 + ".txt");
}
describe("test code (utf8)", function() {
var testData = getShiftJISFileTestData();
var referenceData = getShiftJISBufferTestData();
var newlines = Object.keys(testData);
newlines.forEach(function(newline1) {
it("should load test data correctly", function() {
newlines.forEach(function (newline2) {
var target = testData[newline2];
var reference = referenceData[newline1];
if (newline1 === newline2) {
assert.ok(reference.equals(target), util.format("%s test data is loaded correctly", newline1));
} else {
assert.ok(!reference.equals(target), util.format("%s test data is not same as %s correctly", newline1, newline2));
}
});
});

@@ -141,17 +159,20 @@ });

describe("stream (utf8)", function() {
function testStream(key1, key2, reference, done) {
var originalFilename = "data/utf8/" + key2 + ".txt";
var targetFilename = originalFilename + "." + key1;
describe("in stream mode (simple)", function() {
function testStream(toNewline, fromNewline, reference, done) {
var fromFilename = path.join("data", UTF8, fromNewline + ".txt");
var targetFilename = fromFilename + "." + toNewline;
var options = {
encoding: UTF8
};
var reader = fs.createReadStream(originalFilename, options);
var reader = fs.createReadStream(fromFilename, options);
var writer = fs.createWriteStream(targetFilename);
var converter = convertNewline(key1).stream();
var converter = convertNewline(toNewline).stream();
writer.on("finish", function() {
var target = fs.readFileSync(targetFilename);
assert.ok(reference.equals(target), key2 + " were converted to " + key1);
assert.ok(reference.equals(target));
done();
});
reader

@@ -161,8 +182,9 @@ .pipe(converter)

}
var references = getUTF8BufferTestData();
var keys = Object.keys(references);
keys.forEach(function (key1) {
keys.forEach(function(key2) {
it("Convert " + key2 + " to " + key1, function(done) {
testStream(key1, key2, references[key1], done);
var newlines = Object.keys(references);
newlines.forEach(function (toNewline) {
newlines.forEach(function(fromNewline) {
it(util.format("should convert from %s to %s", fromNewline, toNewline), function(done) {
testStream(toNewline, fromNewline, references[toNewline], done);
});

@@ -173,14 +195,17 @@ });

describe("stream (shift_jis)", function() {
function testStream(key1, key2, reference, done) {
var originalFilename = "data/shift_jis/" + key2 + ".txt";
var targetFilename = originalFilename + "." + key1;
var reader = fs.createReadStream(originalFilename);
describe("in stream mode (iconv)", function() {
function testStream(toNewline, fromNewline, reference, done) {
var fromFilename = path.join("data", SHIFT_JIS, fromNewline + ".txt");
var targetFilename = fromFilename + "." + toNewline;
var reader = fs.createReadStream(fromFilename);
var writer = fs.createWriteStream(targetFilename);
var converter = convertNewline(key1).stream();
var converter = convertNewline(toNewline).stream();
writer.on("finish", function() {
var target = fs.readFileSync(targetFilename);
assert.ok(reference.equals(target), key2 + " were converted to " + key1);
assert.ok(reference.equals(target));
done();
});
reader

@@ -192,8 +217,9 @@ .pipe(iconv.decodeStream(SHIFT_JIS))

}
var references = getShiftJISBufferTestData();
var keys = Object.keys(references);
keys.forEach(function (key1) {
keys.forEach(function(key2) {
it("Convert " + key2 + " to " + key1, function (done) {
testStream(key1, key2, references[key1], done);
var newlines = Object.keys(references);
newlines.forEach(function (toNewline) {
newlines.forEach(function(fromNewline) {
it(util.format("should convert from %s to %s", fromNewline, toNewline), function(done) {
testStream(toNewline, fromNewline, references[toNewline], done);
});

@@ -200,0 +226,0 @@ });

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