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

detect-newline

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-newline - npm Package Compare versions

Comparing version 2.1.0 to 3.0.0

index.d.ts

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

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