0.0.9 • Published 5 years ago

mcgorgeous v0.0.9

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

McGorgeous

Validates the schema of a JSON data return type

CircleCI

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

0.0.9

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago