Skip to content

Commit

Permalink
Normalize newline characters (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva authored and sindresorhus committed Oct 23, 2019
1 parent 7bcd854 commit adbac70
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const exec = (string, columns, options = {}) => {
module.exports = (string, columns, options) => {
return String(string)
.normalize()
.replace(/\r\n/g, '\n')
.split('\n')
.map(line => exec(line, columns, options))
.join('\n');
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Wrap words to the specified column width.

Type: `string`

String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.

#### columns

Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,8 @@ test('#27, does not remove spaces in line with ansi escapes when no trimming', t
t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
t.is(wrapAnsi(chalk.bgGreen(' hello '), 10, {hard: true, trim: false}), chalk.bgGreen(' hello '));
});

test('#39, normalizes newlines', t => {
t.is(wrapAnsi('foobar\r\nfoobar\r\nfoobar\nfoobar', 3, {hard: true}), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
t.is(wrapAnsi('foo bar\r\nfoo bar\r\nfoo bar\nfoo bar', 3), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
});

0 comments on commit adbac70

Please sign in to comment.