@yuzulabo/query-types

1.2.0 • Public • Published

@yuzulabo/query-types

A variable validator using prop-types

tl;dr

import PropTypes from 'prop-types';
import QueryTypes from '@yuzulabo/query-types';

const types = {
  ping: PropTypes.string.isRequired
};

const goodQuery = {
  ping: 'pong'
};

const badQuery = {
  ping() {
    return 'piyo';
  }
};

QueryTypes.check(types, goodQuery); // { valid: true, errors: [] }
QueryTypes.check(types, badQuery); // { valid: false, errors: [ { name: 'ping', message: 'Invalid null `ping`...' } ] }

Extension validators (for QueryTypes)

All validators have .isRequired

const extensionTypes = {
  OptionalStringWithLength: QueryTypes.stringWithLength(min, max),
  OptionalNumberWithLength: QueryTypes.numberWithLength(min, max),
  OptionalArrayWithLength: QueryTypes.arrayWithLength(min, max)
};

Readme

Keywords

none

Package Sidebar

Install

npm i @yuzulabo/query-types

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

9.7 kB

Total Files

22

Last publish

Collaborators

  • yuzulabo