hojs-schema
API参数检查
特性
- 参数数据类型检查
- 参数自动格式化
- 参数默认值
- 自定义数据类型
- 自动生成文档(未完成)
安装
$ npm install hojs-schema --save
使用
'use strict'; const Manager Schema = ; // 创建一个 Manager 实例const manager = ; // 注册自定义类型manager; // 定义检查模式manager; // 检查并格式化数据,如果出错会抛出相应的异常try console; /*输出:{ email: 'me@ucdok.com', password: '123456789', born: 2016-10-30T00:00:00.000Z, age: 18, signature: '哈哈哈哈' } */ catch err return const.errorerr;
在 Express 中使用
'use strict'; const Manager Schema = ;const express = ; const manager = ;const app = ; // 注册的模式名称格式为: METHOD pathmanager; // 使用中间件app; // 使用app;
License
MIT License
Copyright (c) 2016 Zongmin Lei <leizongmin@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.