Judgment.js 1.62 KB
import _ from 'lodash'

export const isEmptyValue = function(o) {
    return [undefined, null].includes(o)
}

export const isNotEmptyValue = function(o) {
    return !isEmptyValue(o)
}

export const isArray = function(o) {
    return Array.isArray(o)
}

export const isNotArray = function(o) {
    return !isArray(o)
}

export const isEmptyArray = function(o) {
    return isArray(o) && o.length === 0
}

export const isNotEmptyArray = function(o) {
    return !isEmptyArray(o)
}

export const isObject = function(o) {
    return Object.prototype.toString.call(o) === '[object Object]'
}

export const isNotObject = function(o) {
    return !isObject(o)
}

export const isEmptyObject = function(o) {
    return isObject(o) && Object.keys(o).length === 0
}

export const isNotEmptyObject = function(o) {
    return !isEmptyObject(o)
}

export const isDate = function(o) {
    return Object.prototype.toString.call(o) === '[object Date]'
}

export const isNotDate = function(o) {
    return !isDate(o)
}

export const isEqual = (value, other) => {
    return _.isEqual(value, other)
}

export const isNotEqual = (value, other) => {
    return !isEqual(value, other)
}

export const isOneOfTheseValues = function(value, expectedValueList) {
    for (let expectedValue of expectedValueList)
    {
        if (isEqual(value, expectedValue))
        {
            return true
        }
    }
    return false
}

export const isNoneOfTheseValues = function(value, unexpectedValueList) {
    for (let unexpectedValue of unexpectedValueList)
    {
        if (isEqual(value, unexpectedValue))
        {
            return false
        }
    }
    return true
}