Hi. Somehow, I wrote this code piece in the past. Today, I don't use this code but this still exists in our project.
function isNumber(data) {
return typeof data == 'number' && !isNaN(data)
}
function isBoolean(data) {
return typeof data === "boolean"
}
function isFloat(data){
return isNumber(data) && data % 1 !== 0
}
function isNull(data){
return !data && Object.is(data, null) && data === null
}
function isUndefined(data) {
return !data && Object.is(data, undefined) && data === undefined
}
function isEmpty(data) {
return data === "" && data.length === 0
}
const I = {
sware: {
this(data) {
return {
is: {
number: () => isNumber(data),
float: () => isFloat(data),
bool: () => isBoolean(data),
null: () => isNull(data),
undefined: () => isUndefined(data),
empty: () => isEmpty(data)
}
}
}
}
}
const aNumericValue = 341
const aFloatValue = 3.14
const aBoolValue = false
const aNullValue = null
You can use this like that;
const aNumericValue = 341
I.sware.this(aNumericValue).is.number()
So, what is yours?
Top comments (5)
Static values in pre-ES6:
instead now:
Nice, I'll add a bit. It's a little experiment I did back in the day and now I think is not very useful:
You can use it as follows:
This outputs the following:
Omg. I like that :P Should I use this :P
Feel free, I was just messing around, although it might have some cool usage. Let me know if you end up using it :)
Kinda weird, looking at it now :P