Last active
April 17, 2022 18:25
-
-
Save Ambratolm/db5d7417ba87755451070c7ff43fb9f9 to your computer and use it in GitHub Desktop.
Simple JavaScript functions wrapper module for common checking of data types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const check = { | |
// Primitives | |
boolean(value) { | |
return typeof value === "boolean"; | |
}, | |
number(value) { | |
return (value) => typeof value === "number" && !isNaN(value); | |
}, | |
biginit(value) { | |
return typeof value === "bigint"; | |
}, | |
string(value) { | |
return typeof value === "string"; | |
}, | |
symbol(value) { | |
return typeof value === "symbol"; | |
}, | |
undefined(value) { | |
return value === undefined; | |
}, | |
null(value) { | |
return value === null; | |
}, | |
// Objects | |
object(value) { | |
return typeof value === "object" && value !== null; | |
}, | |
emptyObject(value) { | |
return this.object(value) && !Object.getOwnPropertyNames(value).length; | |
}, | |
array(value) { | |
return value instanceof Array; | |
}, | |
arrayLike(value) { | |
return this.object(value) && !this.array(value) && "length" in value; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment