Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jaysalvat/smart-model

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jaysalvat/smart-model - npm Package Compare versions

Comparing version 0.2.2 to 0.2.3

src/checkErrors.js

2

package.json
{
"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
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc