You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my project i've found two strange cases with is.Number function, that i think that's not behaving like it should.
I have a condition like the example underneath, that only accept Numbers, but in fact is.Number is accepting arrays with numbers or string numbers. I don't think this is the right behavior to handle it, unless it have a good reason for that, that i'm not seeing clearly.
varUtil=require('findhit-util');vararray1=["123"];vararray2=[123];// Example 1if(Util.is.Number(array1)){console.log("array1 it's a number...");}else{console.log("array1 it's not a number...");}// Example 2if(Util.is.Number(array2)){console.log("array2 it's a number...");}else{console.log("array2 it's not a number...");}// example 1 console.log -> "array1 it's a number..."// example 2 console.log -> "array2 it's a number..."// the cases above should not be a number...
And the Same ( opposite ) thing for isnt.Number:
// Example 3if(Util.isnt.Number(array1)){console.log("array1 it's not a number...");}else{console.log("array1 it's a number...");}// Example 4if(Util.isnt.Number(array2)){console.log("array2 it's not a number...");}else{console.log("array2 it's a number...");}// example 3 console.log -> "array1 it's a number..."// example 4 console.log -> "array2 it's a number..."// the cases above should not be a number...
Maybe the proto of the array is assuming the number since the array contains it.
The text was updated successfully, but these errors were encountered:
Seems important enough. f.is.Number parses the input to an Integer as the process of checking. That happens for some reasons, one of them is that we may check if a certain string is a number. Obviously, if we wan't to check if something is a number on Javascript, we use typeof x === "number", but f.is.Number was built to be clever enough.
Imagine that you are receiving something trough an http request:
var qs = // some request query parsing code
/*
{
id: [ "123" ]
}
*/
// If you use `f.is.Number` it won't break even if you gave params wrong, but you must parse always before using it:
var id;
if ( Util.is.Number( qs.id ) {
id = +qs.id
// id = 123
}
Seems important enough to be documented, but firstly we have to discuss which changes we have to made on this, i have some plans that increases loading performance on browsers.
In my project i've found two strange cases with
is.Number
function, that i think that's not behaving like it should.I have a condition like the example underneath, that only accept Numbers, but in fact
is.Number
is accepting arrays with numbers or string numbers. I don't think this is the right behavior to handle it, unless it have a good reason for that, that i'm not seeing clearly.And the Same ( opposite ) thing for
isnt.Number
:Maybe the proto of the array is assuming the number since the array contains it.
The text was updated successfully, but these errors were encountered: