FEATURE: a way to clear the escape sequences from a string...
Hi,
Something like this would come in really handy for cases when string lengths would need to be calculated for text formatting (i.e. screen char length)...
Object.defineProperty(String.prototype, 'raw', {
get: function(){
return this.replace(/\x1b\[..?m/g, '') }, })
Used like this
var s = 'some string'.zebra
console.log('number of characters:', s.length,
'\nscreen width in chars:', s.raw.length)
Thanks!
Hey @flynx Thanks for this, just what I needed.
Hey @flynx Thanks for this, just what I needed.
You are quite welcome, but I really hope @Marak would get into this discussion as externally patching a good lib is always worse than using relevant provided functionality =)
@flynx how about submitting a PR to provide the needed changes. I would think if it had merit @Marak would accept the PR.
@flynx how about submitting a PR to provide the needed changes. I would think if it had merit @Marak would accept the PR.
So far I had just enough time to do a simple hack/patch (posted above), a good PR would involve some more work diving into the module architecture/style/infrastructure/... ...I'm coming up on a point in the project I'm working on now where I'll have some time for this and subsequently will have to make a decision on the way forward on this aspect, I'll think about it then =)
@flynx how about submitting a PR to provide the needed changes. I would think if it had merit @Marak would accept the PR.
A quick look at the code revealed that this is already implemented but I/we either missed it in the docs or it is not documented...
Here's a converted example:
var s = 'some string'.zebra
console.log('number of characters:', s.length,
'\nscreen width in chars:', s.strip.length)
Guess I now have to re-qualify this as a documentation missing issue, but first re-check the docs, just in case ;)