detect-newline
Advanced tools
Comparing version 2.1.0 to 3.0.0
21
index.js
'use strict'; | ||
module.exports = function (str) { | ||
if (typeof str !== 'string') { | ||
const detectNewline = string => { | ||
if (typeof string !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
var newlines = (str.match(/(?:\r?\n)/g) || []); | ||
const newlines = string.match(/(?:\r?\n)/g) || []; | ||
if (newlines.length === 0) { | ||
return null; | ||
return; | ||
} | ||
var crlf = newlines.filter(function (el) { | ||
return el === '\r\n'; | ||
}).length; | ||
const crlf = newlines.filter(newline => newline === '\r\n').length; | ||
const lf = newlines.length - crlf; | ||
var lf = newlines.length - crlf; | ||
return crlf > lf ? '\r\n' : '\n'; | ||
}; | ||
module.exports.graceful = function (str) { | ||
return module.exports(str) || '\n'; | ||
}; | ||
module.exports = detectNewline; | ||
module.exports.graceful = string => detectNewline(string) || '\n'; |
{ | ||
"name": "detect-newline", | ||
"version": "2.1.0", | ||
"description": "Detect the dominant newline character of a string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/detect-newline", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"newline", | ||
"linebreak", | ||
"line-break", | ||
"line", | ||
"lf", | ||
"crlf", | ||
"eol", | ||
"linefeed", | ||
"character", | ||
"char" | ||
], | ||
"devDependencies": { | ||
"ava": "*", | ||
"xo": "*" | ||
} | ||
"name": "detect-newline", | ||
"version": "3.0.0", | ||
"description": "Detect the dominant newline character of a string", | ||
"license": "MIT", | ||
"repository": "sindresorhus/detect-newline", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"newline", | ||
"linebreak", | ||
"line-break", | ||
"line", | ||
"lf", | ||
"crlf", | ||
"eol", | ||
"linefeed", | ||
"character", | ||
"char" | ||
], | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # detect-newline [![Build Status](https://travis-ci.org/sindresorhus/detect-newline.svg?branch=master)](https://travis-ci.org/sindresorhus/detect-newline) | ||
``` | ||
$ npm install --save detect-newline | ||
$ npm install detect-newline | ||
``` | ||
@@ -26,9 +26,9 @@ | ||
### detectNewline(input) | ||
### detectNewline(string) | ||
Returns detected newline or `null` when no newline character is found. | ||
Returns the detected newline or `undefined` when no newline character is found. | ||
### detectNewline.graceful(input) | ||
### detectNewline.graceful(string) | ||
Returns detected newline or `\n` when no newline character is found. | ||
Returns the detected newline or `\n` when no newline character is found. | ||
@@ -44,2 +44,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
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
3652
5
34
3