Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including joi-react with all npm packages installed. Try it out:

var joiReact = require("joi-react")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

joi-react v1.0.1

Convert joi schemas to React PropTypes.

Synopsis

joi-react is a tiny wrapper to convert joi schemas into React PropType validators.

license - MIT Dependencies

NPM status

Build Status Coverage Status

Install

Node.js

With NPM

npm install joi-react

From source

git clone https://github.com/foss-haas/joi-react.git
cd joi-react
npm install
npm run test && npm run dist

API

joiToPropType(joiSchema):Function

Takes a joi schema and returns a React PropType.

Example:

var joi = require('joi');
var joiToPropType = require('joi-react');
var React = require('react');
var starsSchema = joi.number().integer().min(1).max(5).required();
var starsPropType = joiToPropType(starsSchema);

var Rating = React.createClass({
  displayName: 'Rating',
  propTypes: {
    stars: starsPropType
  },
  render: function () {
    var stars = [];
    for (var i = 0; i < this.props.stars; i++) {
      stars.push(React.createElement('img', {src: 'star.png'}));
    }
    return stars;
  };
});

React.renderToString(React.createElement(Rating));
// -> Warning: value is required
React.renderToString(React.createElement(Rating, {stars: 0}));
// -> Warning: value must be larger than or equal to 1
React.renderToString(React.createElement(Rating, {stars: 6}));
// -> Warning: value must be less than or equal to 5
React.renderToString(React.createElement(Rating, {stars: 5}));
// no warnings

License

The MIT/Expat license. For more information, see http://foss-haas.mit-license.org/ or the accompanying LICENSE file.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free