Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mev

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mev - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

dist/field/index.d.ts

9

dist/index.d.ts

@@ -1,4 +0,5 @@

export { createValidationField } from './field/FieldFactory';
export { createValidationRule } from './rule/RuleFactory';
export { createValidationSchema, Schema } from './schema/Schema';
export { isSuccess, isError } from './utils';
export * from './rule';
export * from './field';
export * from './schema';
export * from './utils';
export * from './types';
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
Object.defineProperty(exports, "__esModule", { value: true });
var FieldFactory_1 = require("./field/FieldFactory");
exports.createValidationField = FieldFactory_1.createValidationField;
var RuleFactory_1 = require("./rule/RuleFactory");
exports.createValidationRule = RuleFactory_1.createValidationRule;
var Schema_1 = require("./schema/Schema");
exports.createValidationSchema = Schema_1.createValidationSchema;
exports.Schema = Schema_1.Schema;
var utils_1 = require("./utils");
exports.isSuccess = utils_1.isSuccess;
exports.isError = utils_1.isError;
__export(require("./rule"));
__export(require("./field"));
__export(require("./schema"));
__export(require("./utils"));
//# sourceMappingURL=index.js.map

@@ -1,8 +0,3 @@

import { Schema } from '..';
import { Validation, ValidationError, ValidationSuccess } from '../types/Validation';
export declare function isSuccess(val: Validation): val is ValidationSuccess;
export declare function isError(val: Validation): val is ValidationError;
export interface MiddlewareOptions {
ignoredParamsInReturn: string[];
}
export declare const middlewave: (schema: Schema, options?: MiddlewareOptions) => (req: any, res: any, next: () => {}) => void;

@@ -11,29 +11,2 @@ "use strict";

exports.isError = isError;
const defaultMiddlewareOptions = {
ignoredParamsInReturn: [],
};
function deleteMatchingAttributes(obj, attributes) {
return Object.keys(obj)
.filter((prop) => !attributes.includes(prop))
.map((prop) => ({
p: prop,
d: typeof obj[prop] === 'object' ? deleteMatchingAttributes(obj[prop], attributes) : obj[prop],
}))
.reduce((o, { p, d }) => (Object.assign({}, o, { [p]: d })), {});
}
exports.middlewave = (schema, options = defaultMiddlewareOptions) => (req, res, next) => {
options = Object.assign({}, defaultMiddlewareOptions, options);
if (req.body && req.body && req.body.data === 'object') {
const validation = schema.test(req.body.data);
if (isSuccess(validation)) {
next();
}
else {
const { errors } = validation;
res.status(422).json({
status: 'failure',
});
}
}
};
//# sourceMappingURL=index.js.map

@@ -1,4 +0,5 @@

export { createValidationField } from './field/FieldFactory';
export { createValidationRule } from './rule/RuleFactory';
export { createValidationSchema, Schema } from './schema/Schema';
export { isSuccess, isError } from './utils';
export * from './rule';
export * from './field';
export * from './schema';
export * from './utils';
export * from './types';

@@ -1,2 +0,1 @@

import { Schema } from '..';
import { Validation, ValidationError, ValidationSuccess } from '../types/Validation';

@@ -11,36 +10,1 @@

}
export interface MiddlewareOptions {
ignoredParamsInReturn: string[];
}
const defaultMiddlewareOptions: MiddlewareOptions = {
ignoredParamsInReturn: [],
};
function deleteMatchingAttributes(obj: any, attributes: string[]): any {
return Object.keys(obj)
.filter((prop) => !attributes.includes(prop))
.map((prop) => ({
p: prop,
d: typeof obj[prop] === 'object' ? deleteMatchingAttributes(obj[prop], attributes) : obj[prop],
}))
.reduce((o, {p, d}) => ({ ...o, [p]: d }), {});
}
export const middlewave =
(schema: Schema, options: MiddlewareOptions = defaultMiddlewareOptions) =>
(req: any, res: any, next: () => {}) => {
options = { ...defaultMiddlewareOptions, ...options };
if (req.body && req.body && req.body.data === 'object') {
const validation = schema.test(req.body.data);
if (isSuccess(validation)) {
next();
} else {
const { errors } = validation;
res.status(422).json({
status: 'failure',
});
}
}
};
{
"name": "mev",
"version": "2.2.0",
"version": "2.2.1",
"description": "Another validator..",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -37,3 +37,3 @@ # mev

- Object and primitive data validation
- Customisable, user friendly errors
- Customisable, user-friendly errors
- Chain based API

@@ -74,3 +74,3 @@ - Written in TypeScript

Mev has many build in methods for testing data. These are specific to the data type being tested, and as such there is an extension of `Rule` for each primitive data type `string`, `number` & `boolean`.
Mev has many built in methods for testing data. These are specific to the data type being tested, and as such there is an extension of `Rule` for each primitive data type `string`, `number` & `boolean`.

@@ -333,1 +333,37 @@ ### `StringRule`

## Utils
Provided are methods for determining the outcome of a validation test.
This allows type knowledge of the result which is essential in TypeScript
and useful for the type knowledge in your IDE.
### `isSuccess` & `isError`
```js
import { isSuccess, isError, createValidationSchema } from 'mev';
const schema = createValidationSchema()
.addField('age', f => f
.number()
.addRule(r => r
.title('negative age')
.description('an age must be greater than 0')
.min(0)
)
);
const result = schema.test({ age: 32 });
if (isSuccess(result)) {
// will have access to result.success
} else {
// will have access to result.errors
}
if (isError(result)) {
// will have access to result.errors
} else {
// will have access to result.success
}
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc