Itachi Uchiha
Posted on July 6, 2020
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?
💖 💪 🙅 🚩
Itachi Uchiha
Posted on July 6, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.