andrehtissot/dexie-orm-addon

View on GitHub
src/attributeTypes/ObjectType.js

Summary

Maintainability
A
0 mins
Test Coverage
const isAValidUndefined = (value, options) => value === undefined && (!options || options.require !== true)
const isAValidNull = (value, options) => value !== null || (options && options.allowNull === true)
const isTypeObject = (value) => typeof value !== 'object'

const ObjectType = {
    validate: (value, options = { require: false, allowNull: false }) => {
        if (isAValidUndefined(value, options)) {
            return true
        }
        if (isTypeObject(value)) {
            return 'is not an Object'
        }
        if (isAValidNull(value, options)) {
            return true
        }
        return 'is null'
    },
}

export default ObjectType