mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Pull white space checks into function
Clean up code by pulling white space checks into a seperate helper function
This commit is contained in:
parent
338b2f3458
commit
ad5bc1afbd
1 changed files with 11 additions and 3 deletions
|
@ -90,6 +90,15 @@ Cast.toRgbColorObject = function (value) {
|
|||
return color;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if a Scratch argument is a white space string (or null / empty).
|
||||
* @param {*} val value to check.
|
||||
* @return {boolean} True if the argument is all white spaces or null / empty.
|
||||
*/
|
||||
Cast.isWhiteSpace = function (val) {
|
||||
return val === null || typeof val === 'string' && val.trim().length === 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Compare two values, using Scratch cast, case-insensitive string compare, etc.
|
||||
* In Scratch 2.0, this is captured by `interp.compare.`
|
||||
|
@ -100,10 +109,9 @@ Cast.toRgbColorObject = function (value) {
|
|||
Cast.compare = function (v1, v2) {
|
||||
var n1 = Number(v1);
|
||||
var n2 = Number(v2);
|
||||
if (n1 === 0 && (v1 == null || typeof v1 === 'string' && v1.trim().length === 0)) {
|
||||
if (n1 === 0 && Cast.isWhiteSpace(v1)) {
|
||||
n1 = NaN;
|
||||
}
|
||||
if (n2 === 0 && (v2 == null || typeof v2 === 'string' && v2.trim().length === 0)) {
|
||||
} else if (n2 === 0 && Cast.isWhiteSpace(v2)) {
|
||||
n2 = NaN;
|
||||
}
|
||||
if (isNaN(n1) || isNaN(n2)) {
|
||||
|
|
Loading…
Reference in a new issue