@jaysalvat/smart-model
Advanced tools
Comparing version 0.2.2 to 0.2.3
{ | ||
"name": "@jaysalvat/smart-model", | ||
"version": "0.2.2", | ||
"version": "0.2.3", | ||
"description": "Javascript object model", | ||
@@ -5,0 +5,0 @@ "main": "./build/smart-model.umd.js", |
@@ -1,3 +0,3 @@ | ||
import SuperModel from './Model.js' | ||
import SuperModel from './SuperModel.js' | ||
export default SuperModel |
export function isUndef(value) { | ||
return typeof value === 'undefined' | ||
} | ||
export function isEmpty(value) { | ||
return value === '' || value === null || typeof value === 'undefined' | ||
return value === '' || value === null || isUndef(value) | ||
} | ||
@@ -26,52 +30,4 @@ | ||
export function checkErrors(entry, property, value) { | ||
const errors = [] | ||
if (entry.required && isEmpty(value)) { | ||
errors.push({ | ||
message: `Invalid value 'required' on property '${property}'`, | ||
code: 'required' | ||
}) | ||
return errors | ||
} | ||
if (typeof value === 'undefined') { | ||
return errors | ||
} | ||
if (entry.type) { | ||
let typeOk | ||
const types = isArray(entry.type) ? entry.type : [ entry.type ] | ||
if (!entry.required && isEmpty(value)) { | ||
typeOk = true | ||
} else { | ||
typeOk = types.some((type) => { | ||
return typeof value === typeof type() || value instanceof type | ||
}) | ||
} | ||
if (!typeOk) { | ||
errors.push({ | ||
message: `Invalid type '${typeof value}' on property '${property}'`, | ||
code: 'type' | ||
}) | ||
} | ||
} | ||
if (entry.rule) { | ||
Object.keys(entry.rule).forEach((key) => { | ||
const rule = entry.rule[key] | ||
if (rule(value)) { | ||
errors.push({ | ||
message: `Invalid value '${key}' on property '${property}'`, | ||
code: key | ||
}) | ||
} | ||
}) | ||
} | ||
return errors | ||
export function isType(value, type) { | ||
return typeof value === typeof type() || value instanceof type | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12796
13
339
1