Skip to content

Instantly share code, notes, and snippets.

@rhzs
Created September 9, 2017 08:31
Show Gist options
  • Save rhzs/71a651935c17e5a8ba08802175e37716 to your computer and use it in GitHub Desktop.
Save rhzs/71a651935c17e5a8ba08802175e37716 to your computer and use it in GitHub Desktop.
Fastest Validator using Next.Js, this is a demo schema validation faster than Hapi Joi schema.
// !!!!!!!!!!!
// Move this file to inside `pages` directory
// !!!!!!!!!!!
import React from "react";
import Validator from "fastest-validator";
class Index extends React.Component {
render() {
const v = new Validator();
const schema = {
multi: [
{ type: "string", min: 3, max: 255 },
{ type: "boolean" }
]
};
return (
<div>
Multi schema validator: {v.validate({ multi: 'john' }, schema) === true ? 'yey!' : 'nope..'}
<br />
Failed Multi schema validator: {JSON.stringify(v.validate({ multi: 123 }, schema))}
</div>
);
return (
<div>Hello</div>
);
}
}
export default Index;
{
"name": "fastest-validator-nextjs-demo",
"version": "0.0.1",
"author": "incubus8",
"description": "Fastest Validator Demo Gist by Incubus8",
"scripts": {
"start": "next",
"build": "next build"
},
"dependencies": {
"fastest-validator": "^0.6.5",
"next": "^3.2.2",
"react": "^15.6.1",
"react-dom": "^15.6.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment