@particle/detect-newline-style
Determine a string's preferred newline character
Installation
npm install @particle/detect-newline-style --save
API
@particle/detect-newline-style
string
⏏
module.exports(input, [options]) ⇒ Figure out which newline style a given string uses (windows: \r\n
or unix: \n
)
Kind: Exported function
Returns: string
- Either \r\n
or \n
based on string contents
Param | Type | Default | Description |
---|---|---|---|
input | string |
The string you want to analyze | |
[options] | object |
||
[options.defaultEOL] | string |
"'\n'" |
Default newline character |
Example
const newline = detectNewlineStyle('foo\nbar\r\n\baz\n');
console.log(newline); // '\n'
NOTE: Unfortunately, docs have a nasty habit of falling out of date. When in doubt, check usage in tests