Difference in output between 2.1.0 and 3.0.1
coreyfarrell opened this issue · 5 comments
I have the following minimal test case:
'use strict'
const wrap = require('wrap-ansi');
const chalk = require('chalk');
const srcString = chalk.blue(' 1 2 ');
console.log('"' + wrap(srcString, 20, {hard: true}) + '"');
console.log('"' + wrap(srcString, 20, {hard: true, trim: false}) + '"');
Note that srcString has 2 spaces before, between and after the numbers.
Against v2.1.0:
The test prints the same output twice (trim: false
is ignored). The output is "1 2 "
- both spaces before the '1' were removed. If color terminal is disabled the spaces after the '2' are also removed.
Against v3.0.1:
The first line prints with a single space between the numbers, and if color is enabled a single space after the numbers.
The second line prints the original string if color is enabled, if color is disabled it prints an extra space before the string (3 spaces total before the '1').
This was found when trying to update cliui to use v3.0.1. I don't know what the correct behavior should be.
stroncium earned $40.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
The issue can be boiled down to this:
var text = 'foo bar'
console.log(JSON.stringify(text)) // => "foo bar"
var r1 = wrap(text, 42)
console.log(JSON.stringify(r1)) // => "foo bar"
var r2 = wrap(text, 42, {trim: false})
console.log(JSON.stringify(r2)) // => "foo bar"
I'm not sure from reading the readme if this is the intended result, or if this is a bug. But if it's the intended result, I think trim: true
it's the wrong default as it's very counter intuitive.
For reference, this is where the trimming happens:
@IssueHunt has funded $40.00 to this issue. See it on IssueHunt
@sindresorhus has rewarded $36.00 to @stroncium. See it on IssueHunt
- 💰 Total deposit: $40.00
- 🎉 Repository reward(0%): $0.00
- 🔧 Service fee(10%): $4.00