Handle CRLF for splitting lines on Windows

This commit is contained in:
Suhas Karanth
2017-12-27 08:35:11 +05:30
parent 339767fdc3
commit 7aaaf19d16
2 changed files with 4 additions and 4 deletions

View File

@ -1759,9 +1759,9 @@ Use `readFileSync` function in `fs` node package to create a `Buffer` from a fil
convert buffer to string using `toString(encoding)` function. convert buffer to string using `toString(encoding)` function.
creating an array from contents of file by `split`ing file content line by line (each `\n`). creating an array from contents of file by `split`ing file content line by line (each `\n`).
```js ```js
const fs = require('fs'); const fs = require('fs');
const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').split('\n'); const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').split(/\r?\n/);
/* /*
contents of test.txt : contents of test.txt :
line1 line1

View File

@ -6,9 +6,9 @@ Use `readFileSync` function in `fs` node package to create a `Buffer` from a fil
convert buffer to string using `toString(encoding)` function. convert buffer to string using `toString(encoding)` function.
creating an array from contents of file by `split`ing file content line by line (each `\n`). creating an array from contents of file by `split`ing file content line by line (each `\n`).
```js ```js
const fs = require('fs'); const fs = require('fs');
const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').split('\n'); const readFileLines = filename => fs.readFileSync(filename).toString('UTF8').split(/\r?\n/);
/* /*
contents of test.txt : contents of test.txt :
line1 line1