0.0.9 • Published 5 years ago
mcgorgeous v0.0.9
McGorgeous
Validates the schema of a JSON data return type
Usage
Install
Using browser
<script src="dist/mcgorgeous.min.js"></script>
Using Yarn
yarn add mcgorgeous
Using NPM
npm install mcgorgeous
JavaScript
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);
}
Types
String type
[{ name: "string" }];
Numeric type
[{ id: "number" }];
Boolean type
[{ id: "boolean" }];
Null type
[{ id: null }];
Null type will be skipped. Can be null
or "null"
.
Not Null
[{ name: "string notnull" }];
[{ name: "number notnull" }];
[{ name: "boolean notnull" }];
Will throw an error if the strings value is null.
Array of type
{
names: ["string"]
}
Check out the tests for full examples