extendHex bug -> quick fix
adrianpikul opened this issue · 1 comments
adrianpikul commented
Hi,
In all methods where We use color in Hex value, at first We should trim the string value.
a) Buggs in old version:
- extendHex('#03f'); // '#0033ff' <- here is ok
- extendHex(' #03f'); // "# ##0033ff" <- with space char in start
b) Correct version:
const extendHexCorrect = strHex =>{
let shortHex = strHex.trim()
'#' +
shortHex
.slice(shortHex.startsWith('#') ? 1 : 0)
.split('')
.map(x => x + x)
.join('');
return shortHex
};
Chalarangelo commented
This isn't necessarily a bug with the snippet, but more a poor usage of it. Trimming is up to the developer to handle. If you aren't passing the expected output and the snippet doesn't explicitly says it handles it, chances are it shouldn't. Closing.