# detect-newline

> Detect the dominant newline character of a string

Latest version **4.0.1** (published 2023-09-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install detect-newline
pnpm add detect-newline
yarn add detect-newline
bun add detect-newline
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2023-09-22 |
| First published | 2014-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 3.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 55 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | newline, linebreak, line-break, line, lf, crlf, eol, linefeed, character |

## Links

- npm: https://www.npmjs.com/package/detect-newline
- Repository: https://github.com/sindresorhus/detect-newline
- Homepage: https://github.com/sindresorhus/detect-newline#readme
- Issues: https://github.com/sindresorhus/detect-newline/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/detect-newline

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2023-09-22
- 4.0.0 — 2021-10-14
- 3.1.0 — 2019-11-13
- 3.0.0 — 2019-04-11
- 2.1.0 — 2016-02-16
- 2.0.1 — 2016-02-09
- 2.0.0 — 2016-02-09
- 1.0.3 — 2015-02-16
- 1.0.2 — 2015-01-24
- 1.0.1 — 2014-08-17
- 1.0.0 — 2014-08-14
- 0.1.1 — 2014-06-28
- 0.1.0 — 2014-06-28

## README

# detect-newline

> Detect the dominant newline character of a string

## Install

```sh
npm install detect-newline
```

## Usage

```js
import {detectNewline} from 'detect-newline';

detectNewline('foo\nbar\nbaz\r\n');
//=> '\n'
```

## API

### detectNewline(string)

Returns the detected newline or `undefined` when no newline character is found or `\n` when no dominant newline is present.

### detectNewlineGraceful(unknown)

Returns the detected newline or `\n` when no newline character is found, no dominant newline is present, or the input is not a string.

## Related

- [detect-newline-cli](https://github.com/sindresorhus/detect-newline-cli) - CLI for this module
- [detect-indent](https://github.com/sindresorhus/detect-indent) - Detect the indentation of code

---
_Source: https://npm.io/package/detect-newline · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
