@knowark/validarkjs
Version:
Simple Data Validation Library
16 lines (14 loc) • 463 B
JavaScript
import { HasError } from './errors.js'
export function has (instance, properties) {
if (!instance) {
throw new HasError(`Instance must be an object. Got "${instance}".`)
}
properties = [properties].flat().map(item => item.split(',').map(
subitem => subitem.trim())).flat()
for (const property of properties) {
if (!instance[property]) {
throw new HasError(`Instance does not have property "${property}".`)
}
}
return instance
}