@e-group/redux-modules
Version:
eGroup team react-redux modules that share across projects.
24 lines (22 loc) • 672 B
JavaScript
/**
* Check variable has supported types(at least one of all).
* @param {any} variable
* @param {array} supportedTypes ["object", "null", "array", "boolean", "string", "bigint", "function", "number", "symbol", "undefined"]
*/
export default function supportedTypes(variable, supportedTypes) {
let objType = typeof variable;
if (objType === 'object') {
if (variable === null) {
objType = 'null';
} else if (Array.isArray(variable)) {
objType = 'array';
}
}
let isSupported = false;
supportedTypes.forEach(supportedType => {
if (objType === supportedType) {
isSupported = true;
}
});
return [isSupported, objType];
}