All Projects → znck → prop-types

znck / prop-types

Licence: MIT License
Fluent prop validation for Vue

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to prop-types

React Required If
React PropType to conditionally add `.isRequired` based on other props
Stars: ✭ 72 (-25.77%)
Mutual labels:  validation, props
array-validation
Validation utilities for array structure
Stars: ✭ 14 (-85.57%)
Mutual labels:  validation
fqdn
RFC-compliant FQDN validation and manipulation for Python.
Stars: ✭ 23 (-76.29%)
Mutual labels:  validation
exvalibur
Elixir Validator Generator
Stars: ✭ 14 (-85.57%)
Mutual labels:  validation
verum-php
Server-Side Validation Library for PHP
Stars: ✭ 17 (-82.47%)
Mutual labels:  validation
openapi-schema-validator
OpenAPI schema validator for Python
Stars: ✭ 35 (-63.92%)
Mutual labels:  validation
vue-tiny-validate
💯 Tiny Vue Validate Composition
Stars: ✭ 80 (-17.53%)
Mutual labels:  validation
php-assert
Fast flexible php assert
Stars: ✭ 18 (-81.44%)
Mutual labels:  validation
yform standalone validator
YForm-Erweiterung: Validieren von PHP Arrays ohne HTML-Formular
Stars: ✭ 23 (-76.29%)
Mutual labels:  validation
NZ-Bank-Account-Validator
A small, zero dependency NZ bank account validation library that runs everywhere.
Stars: ✭ 15 (-84.54%)
Mutual labels:  validation
react-form-validation-demo
React Form Validation Demo
Stars: ✭ 88 (-9.28%)
Mutual labels:  validation
fastify-response-validation
A simple plugin that enables response validation for Fastify.
Stars: ✭ 20 (-79.38%)
Mutual labels:  validation
ValidatedTextInputLayout
An extension to Android Design Support library's TextInputLayout with integrated validation support
Stars: ✭ 54 (-44.33%)
Mutual labels:  validation
liquibase-linter
Quality control for your Liquibase scripts
Stars: ✭ 15 (-84.54%)
Mutual labels:  validation
flaskerk
A flask extension for api doc and validation of request&response.
Stars: ✭ 24 (-75.26%)
Mutual labels:  validation
ng2-multi-step-wizard-ui-router1
Series 3: Tutorials on creating an Angular 2 Multi-Step Wizard using UI-Router 1.0 and TypeScript 2.0.10
Stars: ✭ 33 (-65.98%)
Mutual labels:  validation
peppermint
Declarative data validation framework, written in Swift
Stars: ✭ 37 (-61.86%)
Mutual labels:  validation
valid8
Valid8 - Super Simple Bootstrap Form Valiation
Stars: ✭ 17 (-82.47%)
Mutual labels:  validation
typesentry
Python 2.7 & 3.5+ runtime type-checker
Stars: ✭ 19 (-80.41%)
Mutual labels:  validation
fastq utils
Validation and manipulation of FASTQ files, scRNA-seq barcode pre-processing and UMI quantification.
Stars: ✭ 25 (-74.23%)
Mutual labels:  validation
prop-types


vue2 NPM version NPM downloads CircleCI codecov

Introduction

Fluent prop validation for Vue that won't land in your production code.

Use rollup-plugin-replace or DefinePlugin to replace process.env.NODE_ENV with 'production'.
If you are using Vue CLI or Nuxt, it's already done for you.

Usage

Installation

npm install --save @znck/prop-types

Examples

import PropTypes from '@znck/prop-types'; // ES6
var PropTypes = require('@znck/prop-types'); // ES5 with npm

Make sure to add @znck/prop-types/remove to babel config.

// babel.config.js or .babelrc.js
...
  plugins: [
    '@znck/prop-types/remove'
  ]
...

Here is an example of using PropTypes with a Vue component, which also documents the different validators provided:

<script>
import PropTypes from 'prop-types';

export default {
  props: {
    // You can declare that a prop is a specific JS primitive. By default, these
    // are all optional.
    optionalArray: PropTypes.array,
    optionalBool: PropTypes.bool,
    optionalFunc: PropTypes.func,
    optionalNumber: PropTypes.number,
    optionalObject: PropTypes.object,
    optionalString: PropTypes.string,
    optionalSymbol: PropTypes.symbol,

    // You can also declare that a prop is an instance of a class. This uses
    // JS's instanceof operator.
    optionalMessage: PropTypes.instanceOf(Message),

    // You can ensure that your prop is limited to specific values by treating
    // it as an enum.
    optionalEnum: PropTypes.oneOf(['News', 'Photos']),

    // An object that could be one of many types
    optionalUnion: PropTypes.oneOfType([
      PropTypes.string,
      PropTypes.number,
      PropTypes.instanceOf(Message)
    ]),

    // An array of a certain type
    optionalArrayOf: PropTypes.arrayOf(PropTypes.number),

    // An object with property values of a certain type
    optionalObjectOf: PropTypes.objectOf(PropTypes.number),

    // An object taking on a particular shape
    optionalObjectWithShape: PropTypes.shape({
      color: PropTypes.string,
      fontSize: PropTypes.number
    }),

    // You can chain any of the above with `isRequired` to make sure a warning
    // is shown if the prop isn't provided.
    requiredFunc: PropTypes.func.isRequired,

    // A value of any data type
    requiredAny: PropTypes.any.isRequired,

    // You can also supply a custom validator.
    customArrayProp: PropTypes.string.validate(value => value === 'foo'),
  }
}
</script>

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Author

prop-types © Rahul Kadyan, Released under the MIT License.
Authored and maintained by Rahul Kadyan with help from contributors (list).

znck.me · GitHub @Rahul Kadyan · Twitter @znck0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].