Comparing version
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ declare module eol { |
@@ -0,0 +0,0 @@ !function(root, name, make) { |
{ | ||
"name": "eol", | ||
"description": "Newline character converter", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"homepage": "https://github.com/ryanve/eol", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
# eol | ||
#### [Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript | ||
[Newline](http://en.wikipedia.org/wiki/Newline) character converter for JavaScript. Available [on npm](https://www.npmjs.com/package/eol). | ||
@@ -8,6 +8,12 @@ ``` | ||
### `require` or `import` | ||
```js | ||
var eol = require('eol') | ||
const eol = require('eol') | ||
``` | ||
```js | ||
import eol from 'eol' | ||
``` | ||
## API | ||
@@ -43,3 +49,14 @@ | ||
### Joining | ||
Coercing `eol.auto`|`eol.crlf`|`eol.lf`|`eol.cr` to string yields the appropriate character. This is useful for joining. | ||
```js | ||
String(eol.lf) // "\n" | ||
eol.split(text).join(eol.auto) // same as eol.auto(text) | ||
eol.split(text).filter(line => line).join(eol.auto) // text joined after removing empty lines | ||
eol.split(text).slice(-3).join(eol.auto) // last 3 lines joined | ||
``` | ||
## License | ||
MIT |
15
test.js
@@ -6,2 +6,6 @@ !function(root) { | ||
function identity(v) { | ||
return v | ||
} | ||
var common = typeof module != 'undefined' && !!module.exports | ||
@@ -27,2 +31,6 @@ var aok = common ? require('aok') : root.aok | ||
aok('crlf repeat newlines intact', eol.crlf('\r\n\r\n') === '\r\n\r\n') | ||
aok('lf function coerces to string', String(eol.lf) === '\n') | ||
aok('crlf function coerces to string', String(eol.crlf) === '\r\n') | ||
aok('cr function coerces to string', String(eol.cr) === '\r') | ||
aok('auto function coerces to string', String(eol.auto) === isWindows ? '\r\n' : '\n') | ||
aok('split return type', eol.split('0\n1\n2') instanceof Array) | ||
@@ -33,6 +41,5 @@ aok('split lf', eol.split('0\n1\n2').join('') === '012') | ||
aok('split mixed', eol.split('0\r\n1\n2\r3\r\n4').join('') === '01234') | ||
aok('lf function coerces to string', String(eol.lf) === '\n') | ||
aok('crlf function coerces to string', String(eol.crlf) === '\r\n') | ||
aok('cr function coerces to string', String(eol.cr) === '\r') | ||
aok('auto function coerces to string', String(eol.auto) === isWindows ? '\r\n' : '\n') | ||
aok('split join', eol.split('0\n1\n\n2\n').join(eol.auto) === eol.auto('0\n1\n\n2\n')) | ||
aok('split filter join', eol.split('A\n\nB').filter(identity).join(eol.lf) === 'A\nB') | ||
aok('split slice join', eol.split('A\nB\nC\nD').slice(-2).join(eol.lf) === 'C\nD') | ||
@@ -39,0 +46,0 @@ aok.pass(meths, function(method, i) { |
@@ -0,0 +0,0 @@ /* global eol */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
12419
10.51%219
2.82%61
38.64%