is-valid-object is a Javascript library for making sure objects conform to a defined structure.
npm install is-valid-object
import { ObjectChecker } from 'is-valid-object';
const schema = {
"keyToCheck": {
"type": "string"
}
};
const objectToCheck = {
"keyToCheck": "some string"
};
console.time("object-checker");
const checker = new ObjectChecker();
try {
// will throw if there is some problem with the specified object
checker.check(objectToCheck, schema);
} catch (error) {
// some key is malformed
console.log(error.message || error, "error");
}
console.timeEnd("object-checker");
A detailed example can be found in this file
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.