@dozerg/end-of-line
TypeScript icon, indicating that this package has built-in type declarations

1.0.17 • Public • Published

End-of-line

npm Downloads Build Status

Determine EOL based on given text and OS.

Install

npm i @dozerg/end-of-line

Usage

import { endOfLine } from '@dozerg/end-of-line';

// Detect OS-specific EOL.
const default_eol = endOfLine();

// Detect EOL for a given text.
const text = 'some\ntext\nwith\r\nnewlines\r';
const text_eol = endOfLine(text); // '\n'

// Detect EOL for a file.
const filename = '/path/to/file.ext';
const file_eol = endOfLineForFile(filename);

APIs

function endOfLine(): string

Determine the OS-specific end-of-line marker. Equivalent to os.EOL.

function endOfLine(text: string): string

Determine end-of-line marker for a given text. The following markers will be recognized:

  • \n
  • \r\n
  • \r
  • \n\r

If there is no EOL found, os.EOL will be returned.

function endOfLineForFile(filePath: string): string

Determine end-of-line marker for a given file.

If file doesn't exist or cannot be read, os.EOL will be returned.

License

MIT

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.17560latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.17560
1.0.16792
1.0.15435
1.0.1417
1.0.135
1.0.120
1.0.110
1.0.1064
1.0.90
1.0.8890
1.0.71
1.0.60
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i @dozerg/end-of-line

Weekly Downloads

2,764

Version

1.0.17

License

MIT

Unpacked Size

8.29 kB

Total Files

7

Last publish

Collaborators

  • wqqafnd