Skip to content

Feathers hooks for schema validation using fastest-validator as a core validator

License

Notifications You must be signed in to change notification settings

pr1te/featherjs-fastest-validator

Repository files navigation

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).

Parameter Default Type Description
schema - ValidationSchema Please visit https://github.com/icebob/fastest-validator
field data string the 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"