util/helpers/instances.js


/**
 * instanceTypes
 *
 * @export
 * @name instanceTypes
 * @type object
 * @description Types of instances that can be used from props
 */
export const instanceTypes = {
    string: "String",
    array: "Array",
    number: "Number",
    bool: "Boolean",
    date: "Date",
    func: "Function",
    object: "Object",
    regExp: "RegExp",
}

/**
 *
 *
 * @export
 * @name is
 * @param {sting} type | Instance type of the variable, on of @see {instanceTypes}
 * @param {object} obj | Instance that needs to be checked
 * @returns boolean
 */
export function is(type, obj) {
    const clas = Object.prototype.toString.call(obj).slice(8, -1)
    return obj !== undefined && obj !== null && clas === type
}