Validates the schema of a JSON data return type
Using browser
<script src="dist/mcgorgeous.min.js"></script>
Using Yarn
yarn add mcgorgeous
Using NPM
npm install mcgorgeous
Use via try
and catch
import check from "mcgorgeous";
const sitesSchema = [{ name: "string" }];
// data coming back from server
const sitesData = [{ name: "Jeff" }, { name: "Gary" }];
try{
check(sitesSchema, sitesData);
} catch(e) {
// throw proper error
console.log(e.message);
}
[{ name: "string" }];
[{ id: "number" }];
[{ id: "boolean" }];
[{ id: null }];
Null type will be skipped. Can be null
or "null"
.
[{ name: "string notnull" }];
[{ name: "number notnull" }];
[{ name: "boolean notnull" }];
Will throw an error if the strings value is null.
{
names: ["string"]
}
Check out the tests for full examples