Issue in Stdlib.isLayerEmpty

Discussion of the xtools Toolkit

Moderators: Tom, Kukurykus

myranalis

Issue in Stdlib.isLayerEmpty

Post by myranalis »

Using 1.7 release I found I had to modify the parseInt call slightly to:

Code: Select allparseInt(layer.bounds.toString().replace(/\D/g,""),10)

In my case a layer with the bounds 0 px, 0 px, 900 px, 900 px was returning as empty since parseInt("00900900") returns 0.
xbytor

Issue in Stdlib.isLayerEmpty

Post by xbytor »

That's why I hate using parseInt; if the first character is '0' it assumes the number is octal so it stops parsing when it hits the first '9'.

Here are two other ways of tackling the problem. I'll change stdlib.js to use one of them.

Code: Select all  return Number(layer.bounds.toString().replace(/\D/g,"")) == 0;

  return layer.bounds.toString().replace(/\D|0/g,"") == '';


Thanks for finding this.

-X
Mike Hale

Issue in Stdlib.isLayerEmpty

Post by Mike Hale »

For what it's worth, I like myranalis' fix the best.

Both parseInt and Number can default to an unexpected base. At least with parseInt you can specify that you want it to convert to base 10.