Created
September 9, 2017 08:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// !!!!!!!!!!! | |
// 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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