detect-newline

Detect the dominant newline character of a string

Usage no npm install needed!

<script type="module">
  import detectNewline from 'https://cdn.skypack.dev/detect-newline';
</script>

README

detect-newline

Detect the dominant newline character of a string

Install

npm install detect-newline

Usage

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.

detectNewlineGraceful(unknown)

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

Related