@hono/typebox-validator
Advanced tools
| {"type": "module"} |
@@ -58,3 +58,5 @@ "use strict"; | ||
| return (0, validator_1.validator)(target, (unprocessedData, c) => { | ||
| const data = stripNonSchemaItems ? removeNonSchemaItems(schema, unprocessedData) : unprocessedData; | ||
| const data = stripNonSchemaItems | ||
| ? removeNonSchemaItems(schema, unprocessedData) | ||
| : unprocessedData; | ||
| if (value_1.Value.Check(schema, data)) { | ||
@@ -81,4 +83,5 @@ if (hook) { | ||
| function removeNonSchemaItems(schema, obj) { | ||
| if (typeof obj !== 'object' || obj === null) | ||
| if (typeof obj !== 'object' || obj === null) { | ||
| return obj; | ||
| } | ||
| if (Array.isArray(obj)) { | ||
@@ -89,6 +92,5 @@ return obj.map((item) => removeNonSchemaItems(schema.items, item)); | ||
| for (const key in schema.properties) { | ||
| if (obj.hasOwnProperty(key)) { | ||
| if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
| const propertySchema = schema.properties[key]; | ||
| if (IsObject(propertySchema) && | ||
| !IsArray(propertySchema)) { | ||
| if (IsObject(propertySchema) && !IsArray(propertySchema)) { | ||
| result[key] = removeNonSchemaItems(propertySchema, obj[key]); | ||
@@ -95,0 +97,0 @@ } |
@@ -1,3 +0,3 @@ | ||
| import { TSchema, Static } from '@sinclair/typebox'; | ||
| import { type ValueError } from '@sinclair/typebox/value'; | ||
| import type { TSchema, Static } from '@sinclair/typebox'; | ||
| import type { ValueError } from '@sinclair/typebox/value'; | ||
| import type { Context, Env, MiddlewareHandler, ValidationTargets } from 'hono'; | ||
@@ -4,0 +4,0 @@ export type Hook<T, E extends Env, P extends string> = (result: { |
@@ -55,3 +55,5 @@ import { ValueGuard } from '@sinclair/typebox'; | ||
| return validator(target, (unprocessedData, c) => { | ||
| const data = stripNonSchemaItems ? removeNonSchemaItems(schema, unprocessedData) : unprocessedData; | ||
| const data = stripNonSchemaItems | ||
| ? removeNonSchemaItems(schema, unprocessedData) | ||
| : unprocessedData; | ||
| if (Value.Check(schema, data)) { | ||
@@ -77,4 +79,5 @@ if (hook) { | ||
| function removeNonSchemaItems(schema, obj) { | ||
| if (typeof obj !== 'object' || obj === null) | ||
| if (typeof obj !== 'object' || obj === null) { | ||
| return obj; | ||
| } | ||
| if (Array.isArray(obj)) { | ||
@@ -85,6 +88,5 @@ return obj.map((item) => removeNonSchemaItems(schema.items, item)); | ||
| for (const key in schema.properties) { | ||
| if (obj.hasOwnProperty(key)) { | ||
| if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
| const propertySchema = schema.properties[key]; | ||
| if (IsObject(propertySchema) && | ||
| !IsArray(propertySchema)) { | ||
| if (IsObject(propertySchema) && !IsArray(propertySchema)) { | ||
| result[key] = removeNonSchemaItems(propertySchema, obj[key]); | ||
@@ -91,0 +93,0 @@ } |
+2
-2
| { | ||
| "name": "@hono/typebox-validator", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "description": "Validator middleware using TypeBox", | ||
@@ -14,3 +14,3 @@ "main": "dist/cjs/index.js", | ||
| "build:cjs": "tsc -p tsconfig.cjs.json", | ||
| "build:esm": "tsc -p tsconfig.esm.json", | ||
| "build:esm": "tsc -p tsconfig.esm.json && echo '{\"type\": \"module\"}' > dist/esm/package.json", | ||
| "build": "rimraf dist && yarn build:cjs && yarn build:esm", | ||
@@ -17,0 +17,0 @@ "prerelease": "yarn build && yarn test", |
10029
1.61%6
20%261
1.56%