Skip to content

Commit adbac70

Browse files
kevvasindresorhus
authored andcommitted
Normalize newline characters (#40)
1 parent 7bcd854 commit adbac70

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ const exec = (string, columns, options = {}) => {
179179
module.exports = (string, columns, options) => {
180180
return String(string)
181181
.normalize()
182+
.replace(/\r\n/g, '\n')
182183
.split('\n')
183184
.map(line => exec(line, columns, options))
184185
.join('\n');

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Wrap words to the specified column width.
3535

3636
Type: `string`
3737

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

4040
#### columns
4141

test.js

+5
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,8 @@ test('#27, does not remove spaces in line with ansi escapes when no trimming', t
148148
t.is(wrapAnsi(chalk.bgGreen(` ${chalk.black('OK')} `), 100, {trim: false}), chalk.bgGreen(` ${chalk.black('OK')} `));
149149
t.is(wrapAnsi(chalk.bgGreen(' hello '), 10, {hard: true, trim: false}), chalk.bgGreen(' hello '));
150150
});
151+
152+
test('#39, normalizes newlines', t => {
153+
t.is(wrapAnsi('foobar\r\nfoobar\r\nfoobar\nfoobar', 3, {hard: true}), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
154+
t.is(wrapAnsi('foo bar\r\nfoo bar\r\nfoo bar\nfoo bar', 3), 'foo\nbar\nfoo\nbar\nfoo\nbar\nfoo\nbar');
155+
});

0 commit comments

Comments
 (0)