Skip to content

Instantly share code, notes, and snippets.

@Ambratolm
Last active April 17, 2022 18:25
Show Gist options
  • Save Ambratolm/db5d7417ba87755451070c7ff43fb9f9 to your computer and use it in GitHub Desktop.
Save Ambratolm/db5d7417ba87755451070c7ff43fb9f9 to your computer and use it in GitHub Desktop.
Simple JavaScript functions wrapper module for common checking of data types.
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