2.0.0 • Published 2 years ago

feathers-fastest-validator v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

feathers-fastest-validator

Build Status Coverage Status Download Status npm version

Feathers hooks for schema validation extended from fastest-validator

Table of content

Installation

Recommended using either yarn or npm for install.

# NPM
$ npm install feathers-fastest-validator --save

# YARN
$ yarn add feathers-fastest-validator

Usage

The library is extended from Fastest Validator to support validate function on Feathers hook. For others Fastest Validator function such as add custom rules, add customized error message, add alias validation, and etc. Please read more on https://github.com/icebob/fastest-validator. Here's an example of a Feathers server that uses feathers-fastest-validator.

const Validator = require('feathers-fastest-validator');

// create validator instance
const validator = new Validator();

// More information about schema validation,
// please visit here https://github.com/icebob/fastest-validator
const schema = {
  key: { type: 'string' },
}

// The data that need to validate
const field = 'data'

//  The hooks can only use as a `before` hooks
export.before = {
  create: [ validator.validateHook(schema, field) ]
}

Properties

The parameter for validateHook(schema, field).

ParameterDefaultTypeDescription
schema-ValidationSchemaPlease visit https://github.com/icebob/fastest-validator
fielddatastringthe reference of data which need to validate such as context.data or context.params.query. For more info about feathers hook context plese visit https://docs.feathersjs.com/api/hooks.html.

License

Copyright (c) 2018

Licensed under the MIT license.

"Buy Me A Coffee"