badmfck-api-server 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,13 @@
1
+ export type TValidatorType = "string" | "number" | "boolean" | "date" | "array" | "object" | "email" | "phone";
1
2
  export interface IValidatorOptions {
2
3
  min?: number;
3
4
  max?: number;
4
- type?: "string" | "boolean" | "number";
5
+ type?: TValidatorType;
5
6
  regex?: RegExp;
6
7
  }
7
8
  export interface IValidaotrType {
8
9
  name: string;
9
- type: "string" | "number" | "boolean" | "date" | "array" | "object" | "email" | "phone";
10
+ type: TValidatorType;
10
11
  optional?: boolean;
11
12
  arrayType?: IValidaotrType;
12
13
  }
@@ -86,6 +86,9 @@ class Validator {
86
86
  return ValidationReport.VALUE_TOO_BIG;
87
87
  if (opt.min && value.length < opt.min)
88
88
  return ValidationReport.VALUE_TOO_SHORT;
89
+ if (opt.type === "email" && !opt.regex) {
90
+ opt.regex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,6}$/g;
91
+ }
89
92
  if (opt.regex) {
90
93
  const tmp = value.replaceAll(opt.regex, "");
91
94
  if (tmp.length !== 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",