@honojs/validator
Advanced tools
Comparing version 0.1.0 to 0.1.1
import type { Handler, Context } from 'hono'; | ||
import validator from './validator'; | ||
export declare type Validator = typeof validator; | ||
declare type Param = string | number | Record<string, string | number> | Message; | ||
declare type Param = string | number | string[] | number[] | Record<string, string | number> | Message; | ||
declare type Rule = Function | [Function, ...Param[]]; | ||
@@ -6,0 +6,0 @@ declare type Rules = Rule | Rule[]; |
@@ -52,5 +52,13 @@ "use strict"; | ||
else { | ||
for (const rule of rules) { | ||
check(rule); | ||
// [v.isIn, ['valid', 'also_valid']] | ||
if (typeof rules[0] === ('string' || 'number')) { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
results[count - 1].params.push(rules); | ||
} | ||
else { | ||
for (const rule of rules) { | ||
check(rule); | ||
} | ||
} | ||
} | ||
@@ -100,3 +108,4 @@ }; | ||
const field = v.body; | ||
const parsedBody = (await c.req.parseBody()); | ||
const req = c.req.clone(); | ||
const parsedBody = (await req.parseBody()); | ||
Object.keys(field).map(async (key) => { | ||
@@ -110,3 +119,4 @@ const value = parsedBody[key]; | ||
const field = v.json; | ||
const json = (await c.req.json()); | ||
const req = c.req.clone(); | ||
const json = (await req.json()); | ||
Object.keys(field).map(async (key) => { | ||
@@ -113,0 +123,0 @@ const data = (0, jsonpath_plus_1.JSONPath)({ path: key, json }); |
{ | ||
"name": "@honojs/validator", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Validator Middleware for Hono", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -6,4 +6,14 @@ # Validator Middleware for Hono | ||
**IT'S BETA QUALITY. DO NOT USE IT FOR PRODUCTION USAGE.** | ||
![SS](https://user-images.githubusercontent.com/10682/184135311-bdc9bd65-3e58-4d36-9709-bdf324e808ad.png) | ||
## Features | ||
- **Hono integration** - You can use it just like any other middleware. | ||
- **Multi platform** - Works on Cloudflare Workers, Deno, Bun, and others. | ||
- **A lot of rules** - Rules defined in [validator.js](https://github.com/validatorjs/validator.js) are available. | ||
- **Sanitization** - Sanitize functions like `trim` are also available. | ||
- **Rendering error automatically** - If it's a bother, you don't have to set error messages. | ||
- **Result set** - It's flexible to handle validation results. | ||
- **JSON Path** - You can specify the JSON value using "_JSON Path_". | ||
## Install | ||
@@ -29,2 +39,9 @@ | ||
Bun: | ||
``` | ||
bun install hono | ||
bun install @honojs/validator | ||
``` | ||
## Usage | ||
@@ -66,2 +83,3 @@ | ||
name: [v.isAlpha, [v.contains, 'abc']], | ||
pref: [v.required, [v.isIn, ['valid', 'also_valid']]], | ||
}, | ||
@@ -160,2 +178,15 @@ header: { | ||
## Contributing | ||
Contributions Welcome! See the contribution guide on Hono repository. | ||
- [Contribution Guide](https://github.com/honojs/hono/blob/main/docs/CONTRIBUTING.md) | ||
## Related Projects | ||
- Hono - <https://honojs.dev/> | ||
- Hono Examples - <https://github.com/honojs/examples> | ||
- validator.js - <https://github.com/validatorjs/validator.js> | ||
- JSONPath-Plus - <http://goessner.net/articles/JsonPath/](https://github.com/JSONPath-Plus/JSONPath> | ||
## Author | ||
@@ -162,0 +193,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19597
290
195