https://github.com/sonicdoe/detect-newline-at-eof
Detect newline at end of file
https://github.com/sonicdoe/detect-newline-at-eof
detect eof javascript newline nodejs
Last synced: 2 months ago
JSON representation
Detect newline at end of file
- Host: GitHub
- URL: https://github.com/sonicdoe/detect-newline-at-eof
- Owner: sonicdoe
- License: bsd-2-clause
- Created: 2015-07-18T11:17:31.000Z (almost 11 years ago)
- Default Branch: develop
- Last Pushed: 2020-07-20T15:46:05.000Z (almost 6 years ago)
- Last Synced: 2025-04-20T00:45:47.770Z (about 1 year ago)
- Topics: detect, eof, javascript, newline, nodejs
- Language: JavaScript
- Homepage:
- Size: 192 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# detect-newline-at-eof
[](https://www.npmjs.com/package/detect-newline-at-eof)
[](https://travis-ci.org/sonicdoe/detect-newline-at-eof)
[](https://ci.appveyor.com/project/sonicdoe/detect-newline-at-eof)
> Detect newline at end of file
detect-newline-at-eof is similar to [trailing-newline](https://github.com/bendrucker/trailing-newline) but will also match `\n` on Windows and `\r\n` on macOS.
## Installation
```console
$ npm install detect-newline-at-eof
```
## Usage
```js
const fs = require('fs')
const detectNewlineAtEof = require('detect-newline-at-eof')
const fileContents = fs.readFileSync('file.txt', 'utf8')
const newlineCharacter = detectNewlineAtEof(fileContents)
console.log(newlineCharacter)
// => \n, \r\n, or null if no newline character at the end was found
```
## Changelog
This project follows [Semantic Versioning 2](https://semver.org).
- v1.0.0 (2018-07-20):
- Add support for Node.js v6, v8, and v10
- Drop support for Node.js versions older than v6
- Drop support for io.js
- v0.1.0 (2015-07-18): Initial release.