@nr1e/commons 0.0.2-alpha.9 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,19 @@
1
1
  import { HttpStatusCode } from '../http';
2
2
  interface IError {
3
3
  stack?: string;
4
- message?: string;
5
4
  name?: string;
5
+ message?: string;
6
6
  statusCode?: HttpStatusCode | number;
7
7
  }
8
+ export interface HttpError extends Error {
9
+ statusCode: HttpStatusCode | number;
10
+ }
11
+ /**
12
+ * Checks if the given parameter is an HttpError.
13
+ *
14
+ * @param e the parameter to check
15
+ */
16
+ export declare function isHttpError(e?: IError | null): e is HttpError;
8
17
  /**
9
18
  * Checks if the given parameter is a NotFoundError.
10
19
  *
@@ -14,7 +23,7 @@ export declare function isNotFoundError(e?: IError | null): e is NotFoundError;
14
23
  /**
15
24
  * Thrown when a resource cannot be found.
16
25
  */
17
- export declare class NotFoundError extends Error {
26
+ export declare class NotFoundError extends Error implements HttpError {
18
27
  readonly statusCode = HttpStatusCode.NOT_FOUND;
19
28
  constructor(message?: string);
20
29
  }
@@ -27,7 +36,7 @@ export declare function isForbiddenError(e?: IError | null): e is ForbiddenError
27
36
  /**
28
37
  * Thrown when a requested operations is not allowed.
29
38
  */
30
- export declare class ForbiddenError extends Error {
39
+ export declare class ForbiddenError extends Error implements HttpError {
31
40
  readonly statusCode = HttpStatusCode.FORBIDDEN;
32
41
  constructor(message?: string);
33
42
  }
@@ -40,7 +49,7 @@ export declare function isValidationError(e?: IError | null): e is ValidationErr
40
49
  /**
41
50
  * Thrown when a validation error occurs.
42
51
  */
43
- export declare class ValidationError extends Error {
52
+ export declare class ValidationError extends Error implements HttpError {
44
53
  readonly statusCode = HttpStatusCode.BAD_REQUEST;
45
54
  constructor(message?: string);
46
55
  }
@@ -53,7 +62,7 @@ export declare function isBadRequestError(e?: IError | null): e is BadRequestErr
53
62
  /**
54
63
  * Thrown when a bad request is made.
55
64
  */
56
- export declare class BadRequestError extends Error {
65
+ export declare class BadRequestError extends Error implements HttpError {
57
66
  readonly statusCode = HttpStatusCode.BAD_REQUEST;
58
67
  constructor(message?: string);
59
68
  }
@@ -66,7 +75,7 @@ export declare function isInternalServerError(e?: IError | null): e is InternalS
66
75
  /**
67
76
  * Throws when an internal server error occurs.
68
77
  */
69
- export declare class InternalServerError extends Error {
78
+ export declare class InternalServerError extends Error implements HttpError {
70
79
  readonly statusCode = HttpStatusCode.INTERNAL_SERVER_ERROR;
71
80
  constructor(message?: string);
72
81
  }
@@ -79,7 +88,7 @@ export declare function isConflictError(e?: IError | null): e is ConflictError;
79
88
  /**
80
89
  * Thrown when a conflict occurs.
81
90
  */
82
- export declare class ConflictError extends Error {
91
+ export declare class ConflictError extends Error implements HttpError {
83
92
  readonly statusCode = HttpStatusCode.CONFLICT;
84
93
  constructor(message?: string);
85
94
  }
@@ -92,7 +101,7 @@ export declare function isUnsupportedMediaTypeError(e?: IError | null): e is Uns
92
101
  /**
93
102
  * Thrown when a unsupported media type is used.
94
103
  */
95
- export declare class UnsupportedMediaTypeError extends Error {
104
+ export declare class UnsupportedMediaTypeError extends Error implements HttpError {
96
105
  readonly statusCode = HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
97
106
  constructor(message?: string);
98
107
  }
@@ -105,9 +114,10 @@ export declare function isNotImplementedError(e?: IError | null): e is NotImplem
105
114
  /**
106
115
  * Thrown when a requested operation is not implemented.
107
116
  */
108
- export declare class NotImplementedError extends Error {
117
+ export declare class NotImplementedError extends Error implements HttpError {
109
118
  readonly statusCode = HttpStatusCode.NOT_IMPLEMENTED;
110
119
  readonly expose = true;
111
120
  constructor(message?: string);
112
121
  }
122
+ export declare function toError(code: number | HttpStatusCode, message?: string): Error;
113
123
  export {};
package/errors/errors.js CHANGED
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = void 0;
3
+ exports.toError = exports.NotImplementedError = exports.isNotImplementedError = exports.UnsupportedMediaTypeError = exports.isUnsupportedMediaTypeError = exports.ConflictError = exports.isConflictError = exports.InternalServerError = exports.isInternalServerError = exports.BadRequestError = exports.isBadRequestError = exports.ValidationError = exports.isValidationError = exports.ForbiddenError = exports.isForbiddenError = exports.NotFoundError = exports.isNotFoundError = exports.isHttpError = void 0;
4
4
  const http_1 = require("../http");
5
+ /**
6
+ * Checks if the given parameter is an HttpError.
7
+ *
8
+ * @param e the parameter to check
9
+ */
10
+ function isHttpError(e) {
11
+ return !!(e && e.stack && e.statusCode && e.message && e.name);
12
+ }
13
+ exports.isHttpError = isHttpError;
5
14
  /**
6
15
  * Checks if the given parameter is a NotFoundError.
7
16
  *
@@ -10,8 +19,8 @@ const http_1 = require("../http");
10
19
  function isNotFoundError(e) {
11
20
  return !!(e &&
12
21
  e.stack &&
13
- e.message &&
14
22
  e.statusCode &&
23
+ e.message &&
15
24
  e.name &&
16
25
  e.name === 'NotFoundError');
17
26
  }
@@ -21,7 +30,8 @@ exports.isNotFoundError = isNotFoundError;
21
30
  */
22
31
  class NotFoundError extends Error {
23
32
  constructor(message) {
24
- super(message !== null && message !== void 0 ? message : 'Not found');
33
+ message = message !== null && message !== void 0 ? message : 'Not found';
34
+ super(message);
25
35
  this.statusCode = http_1.HttpStatusCode.NOT_FOUND;
26
36
  this.name = 'NotFoundError';
27
37
  }
@@ -35,8 +45,8 @@ exports.NotFoundError = NotFoundError;
35
45
  function isForbiddenError(e) {
36
46
  return !!(e &&
37
47
  e.stack &&
38
- e.message &&
39
48
  e.statusCode &&
49
+ e.message &&
40
50
  e.name &&
41
51
  e.name === 'ForbiddenError');
42
52
  }
@@ -46,7 +56,8 @@ exports.isForbiddenError = isForbiddenError;
46
56
  */
47
57
  class ForbiddenError extends Error {
48
58
  constructor(message) {
49
- super(message !== null && message !== void 0 ? message : 'Forbidden');
59
+ message = message !== null && message !== void 0 ? message : 'Forbidden';
60
+ super(message);
50
61
  this.statusCode = http_1.HttpStatusCode.FORBIDDEN;
51
62
  this.name = 'ForbiddenError';
52
63
  }
@@ -60,8 +71,8 @@ exports.ForbiddenError = ForbiddenError;
60
71
  function isValidationError(e) {
61
72
  return !!(e &&
62
73
  e.stack &&
63
- e.message &&
64
74
  e.statusCode &&
75
+ e.message &&
65
76
  e.name === 'ValidationError');
66
77
  }
67
78
  exports.isValidationError = isValidationError;
@@ -70,7 +81,8 @@ exports.isValidationError = isValidationError;
70
81
  */
71
82
  class ValidationError extends Error {
72
83
  constructor(message) {
73
- super(message !== null && message !== void 0 ? message : 'Validation error');
84
+ message = message !== null && message !== void 0 ? message : 'Validation error';
85
+ super(message);
74
86
  this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
75
87
  this.name = 'ValidationError';
76
88
  }
@@ -84,8 +96,8 @@ exports.ValidationError = ValidationError;
84
96
  function isBadRequestError(e) {
85
97
  return !!(e &&
86
98
  e.stack &&
87
- e.message &&
88
99
  e.statusCode &&
100
+ e.message &&
89
101
  e.name === 'BadRequestError');
90
102
  }
91
103
  exports.isBadRequestError = isBadRequestError;
@@ -94,6 +106,7 @@ exports.isBadRequestError = isBadRequestError;
94
106
  */
95
107
  class BadRequestError extends Error {
96
108
  constructor(message) {
109
+ message = message !== null && message !== void 0 ? message : 'Bad request';
97
110
  super(message !== null && message !== void 0 ? message : 'Bad request');
98
111
  this.statusCode = http_1.HttpStatusCode.BAD_REQUEST;
99
112
  this.name = 'BadRequestError';
@@ -108,8 +121,8 @@ exports.BadRequestError = BadRequestError;
108
121
  function isInternalServerError(e) {
109
122
  return !!(e &&
110
123
  e.stack &&
111
- e.message &&
112
124
  e.statusCode &&
125
+ e.message &&
113
126
  e.name === 'InternalServerError');
114
127
  }
115
128
  exports.isInternalServerError = isInternalServerError;
@@ -118,7 +131,8 @@ exports.isInternalServerError = isInternalServerError;
118
131
  */
119
132
  class InternalServerError extends Error {
120
133
  constructor(message) {
121
- super(message !== null && message !== void 0 ? message : 'Internal server error');
134
+ message = message !== null && message !== void 0 ? message : 'Internal server error';
135
+ super(message);
122
136
  this.statusCode = http_1.HttpStatusCode.INTERNAL_SERVER_ERROR;
123
137
  this.name = 'InternalServerError';
124
138
  }
@@ -132,8 +146,8 @@ exports.InternalServerError = InternalServerError;
132
146
  function isConflictError(e) {
133
147
  return !!(e &&
134
148
  e.stack &&
135
- e.message &&
136
149
  e.statusCode &&
150
+ e.message &&
137
151
  e.name === 'ConflictError');
138
152
  }
139
153
  exports.isConflictError = isConflictError;
@@ -142,7 +156,8 @@ exports.isConflictError = isConflictError;
142
156
  */
143
157
  class ConflictError extends Error {
144
158
  constructor(message) {
145
- super(message !== null && message !== void 0 ? message : 'Conflict');
159
+ message = message !== null && message !== void 0 ? message : 'Conflict';
160
+ super(message);
146
161
  this.statusCode = http_1.HttpStatusCode.CONFLICT;
147
162
  this.name = 'ConflictError';
148
163
  }
@@ -156,8 +171,8 @@ exports.ConflictError = ConflictError;
156
171
  function isUnsupportedMediaTypeError(e) {
157
172
  return !!(e &&
158
173
  e.stack &&
159
- e.message &&
160
174
  e.statusCode &&
175
+ e.message &&
161
176
  e.name === 'UnsupportedMediaTypeError');
162
177
  }
163
178
  exports.isUnsupportedMediaTypeError = isUnsupportedMediaTypeError;
@@ -166,7 +181,8 @@ exports.isUnsupportedMediaTypeError = isUnsupportedMediaTypeError;
166
181
  */
167
182
  class UnsupportedMediaTypeError extends Error {
168
183
  constructor(message) {
169
- super(message !== null && message !== void 0 ? message : 'Unsupported media type');
184
+ message = message !== null && message !== void 0 ? message : 'Unsupported media type';
185
+ super(message);
170
186
  this.statusCode = http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE;
171
187
  this.name = 'UnsupportedMediaTypeError';
172
188
  }
@@ -180,8 +196,8 @@ exports.UnsupportedMediaTypeError = UnsupportedMediaTypeError;
180
196
  function isNotImplementedError(e) {
181
197
  return !!(e &&
182
198
  e.stack &&
183
- e.message &&
184
199
  e.statusCode &&
200
+ e.message &&
185
201
  e.name === 'NotImplementedError');
186
202
  }
187
203
  exports.isNotImplementedError = isNotImplementedError;
@@ -190,11 +206,33 @@ exports.isNotImplementedError = isNotImplementedError;
190
206
  */
191
207
  class NotImplementedError extends Error {
192
208
  constructor(message) {
193
- super(message !== null && message !== void 0 ? message : 'Not implemented');
209
+ message = message !== null && message !== void 0 ? message : 'Not implemented';
210
+ super(message);
194
211
  this.statusCode = http_1.HttpStatusCode.NOT_IMPLEMENTED;
195
212
  this.expose = true;
196
213
  this.name = 'NotImplementedError';
197
214
  }
198
215
  }
199
216
  exports.NotImplementedError = NotImplementedError;
217
+ function toError(code, message) {
218
+ switch (code) {
219
+ case http_1.HttpStatusCode.NOT_FOUND:
220
+ return new NotFoundError(message);
221
+ case http_1.HttpStatusCode.FORBIDDEN:
222
+ return new ForbiddenError(message);
223
+ case http_1.HttpStatusCode.BAD_REQUEST:
224
+ return new BadRequestError(message);
225
+ case http_1.HttpStatusCode.INTERNAL_SERVER_ERROR:
226
+ return new InternalServerError(message);
227
+ case http_1.HttpStatusCode.CONFLICT:
228
+ return new ConflictError(message);
229
+ case http_1.HttpStatusCode.UNSUPPORTED_MEDIA_TYPE:
230
+ return new UnsupportedMediaTypeError(message);
231
+ case http_1.HttpStatusCode.NOT_IMPLEMENTED:
232
+ return new NotImplementedError(message);
233
+ default:
234
+ return new Error(message);
235
+ }
236
+ }
237
+ exports.toError = toError;
200
238
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["errors.ts"],"names":[],"mappings":";;;AAAA,kCAAuC;AASvC;;;;GAIG;AACH,SAAgB,eAAe,CAAC,CAAiB;IAC/C,OAAO,CAAC,CAAC,CACP,CAAC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AAC,CAAC;QACrC,KAAK,qBAAc,CAAC,WAAW;YAC7B,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QACtC,KAAK,qBAAc,CAAC,qBAAqB;YACvC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C,KAAK,qBAAc,CAAC,QAAQ;YAC1B,OAAO,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;QACpC,KAAK,qBAAc,CAAC,sBAAsB;YACxC,OAAO,IAAI,yBAAyB,CAAC,OAAO,CAAC,CAAC;QAChD,KAAK,qBAAc,CAAC,eAAe;YACjC,OAAO,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC1C;YACE,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC7B;AACH,CAAC;AAtBD,0BAsBC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Provides common patterns for validation",
4
- "version": "0.0.2-alpha.9",
4
+ "version": "0.0.2",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "author": "NR1E, Inc.",
@@ -25,6 +25,7 @@
25
25
  "gts": "^5.2.0",
26
26
  "jest": "^29.7.0",
27
27
  "ts-jest": "^29.1.1",
28
+ "typedoc": "^0.25.6",
28
29
  "typescript": "~5.1.6"
29
30
  },
30
31
  "exports": {
@@ -36,15 +37,13 @@
36
37
  },
37
38
  "scripts": {
38
39
  "build": "tsc",
40
+ "postbuild": "prettier --check . && gts lint",
39
41
  "watch": "tsc -w",
40
42
  "test": "jest",
41
43
  "lint": "gts lint",
42
- "clean": "gts clean",
43
- "compile": "tsc",
44
+ "clean": "find . -depth 1 \\( -name '*.js' -o -name '*.d.ts' -o -name '*.map' \\) ! -name '.*' ! -name 'jest.config.js' -delete",
44
45
  "fix": "gts fix",
45
- "pretest": "pnpm run compile",
46
- "posttest": "pnpm run lint",
47
- "check": "prettier --check .",
48
- "makepretty": "prettier --write ."
46
+ "makepretty": "prettier --write .",
47
+ "site": "typedoc --out site index.ts"
49
48
  }
50
49
  }
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Tests if a value is null or undefined.
3
+ *
4
+ * @param o the value to check
5
+ */
6
+ export declare function isNotNull(o?: unknown): o is NonNullable<unknown>;
1
7
  /**
2
8
  * Throws a ValidationError if the value is null or undefined.
3
9
  * This function also asserts the value to be NonNullable if the check passes.
@@ -6,6 +12,12 @@
6
12
  * @param o the value to check
7
13
  */
8
14
  export declare function notNull(name: string, o?: unknown): asserts o is NonNullable<unknown>;
15
+ /**
16
+ * Tests if a value is empty, null, undefined or has a length of 0.
17
+ *
18
+ * @param o the value to check
19
+ */
20
+ export declare function isNotEmpty(o?: unknown): o is NonNullable<unknown>;
9
21
  /**
10
22
  * Throws a ValidationError if the value is null, undefined or the length is 0.
11
23
  * This function also asserts the value to be NonNullable if the check passes.
@@ -14,6 +26,12 @@ export declare function notNull(name: string, o?: unknown): asserts o is NonNull
14
26
  * @param o the value to check
15
27
  */
16
28
  export declare function notEmpty(name: string, o?: unknown): asserts o is NonNullable<unknown>;
29
+ /**
30
+ * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.
31
+ *
32
+ * @param o the value to check
33
+ */
34
+ export declare function isNotBlank(o?: unknown): o is NonNullable<unknown>;
17
35
  /**
18
36
  * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.
19
37
  * This function also asserts the value to be NonNullable if the check passes.
@@ -23,14 +41,29 @@ export declare function notEmpty(name: string, o?: unknown): asserts o is NonNul
23
41
  */
24
42
  export declare function notBlank(name: string, o?: unknown): asserts o is NonNullable<unknown>;
25
43
  /**
26
- * Throws a ValidationError if the value does not match the regular expression provided.
44
+ * Tests if a value does not match the regular expression provided.
45
+ * Undefined and null values are skipped and not tested.
46
+ *
47
+ * @param regex the regular expression to test with
48
+ * @param o the value to check
49
+ */
50
+ export declare function isMatch(regex: RegExp, o?: string | null): o is string;
51
+ /**
52
+ * Throws a ValidationError if the value matches the regular expression provided.
27
53
  * Undefined and null values are skipped and not validated.
28
54
  *
29
55
  * @param name the name of the variable
30
56
  * @param regex the regular expression to validate with
31
57
  * @param o the value to check
32
58
  */
33
- export declare function matches(name: string, regex: RegExp, o?: string | null): void;
59
+ export declare function match(name: string, regex: RegExp, o?: string | null): void;
60
+ /**
61
+ * Tests if a value is a valid email address.
62
+ * Undefined and null values are skipped and not validated.
63
+ *
64
+ * @param o the value to check
65
+ */
66
+ export declare function isEmail(o?: string | null): o is string;
34
67
  /**
35
68
  * Throws a ValidationError if the value provided is not an email.
36
69
  * Undefined and null values are skipped and not validated.
@@ -38,7 +71,15 @@ export declare function matches(name: string, regex: RegExp, o?: string | null):
38
71
  * @param name the name of the variable
39
72
  * @param o the value to check
40
73
  */
41
- export declare function isEmail(name: string, o?: string | null): void;
74
+ export declare function email(name: string, o?: string | null): void;
75
+ /**
76
+ * Tests if a value has a length that is less than the provided length.
77
+ * Undefined and null values are skipped and not validated.
78
+ *
79
+ * @param length the maximum length of the variable
80
+ * @param o the value to check
81
+ */
82
+ export declare function isMaxLength(length: number, o?: string | unknown[] | null): boolean;
42
83
  /**
43
84
  * Throws a ValidationError if the value provided has a length that exceeds the provided length.
44
85
  * Undefined and null values are skipped and not validated.
@@ -48,6 +89,14 @@ export declare function isEmail(name: string, o?: string | null): void;
48
89
  * @param o the value to check
49
90
  */
50
91
  export declare function maxLength(name: string, length: number, o?: string | unknown[] | null): void;
92
+ /**
93
+ * Tests if a value has a length that is greater than the provided length.
94
+ * Undefined and null values are skipped and not validated.
95
+ *
96
+ * @param length the minimum length of the variable
97
+ * @param o the value to check
98
+ */
99
+ export declare function isMinLength(length: number, o?: string | unknown[] | null): boolean;
51
100
  /**
52
101
  * Throws a ValidationError if the value provided has a length that is less than the provided length.
53
102
  * Undefined and null values are skipped and not validated.
@@ -57,6 +106,13 @@ export declare function maxLength(name: string, length: number, o?: string | unk
57
106
  * @param o the value to check
58
107
  */
59
108
  export declare function minLength(name: string, length: number, o?: string | unknown[] | null): void;
109
+ /**
110
+ * Tests if a value provided is a number.
111
+ * Undefined and null values are skipped and not validated.
112
+ *
113
+ * @param o the value to check
114
+ */
115
+ export declare function isNumber(o?: string | null | number): boolean;
60
116
  /**
61
117
  * Throws a ValidationError if the value provided is not a number.
62
118
  * Undefined and null values are skipped and not validated.
@@ -64,7 +120,15 @@ export declare function minLength(name: string, length: number, o?: string | unk
64
120
  * @param name the name of the variable
65
121
  * @param o the value to check
66
122
  */
67
- export declare function isNumber(name: string, o?: string | null | number): void;
123
+ export declare function number(name: string, o?: string | null | number): void;
124
+ /**
125
+ * Tests if a value is less than the provided minimum value.
126
+ * Undefined and null values are skipped and not validated.
127
+ *
128
+ * @param minValue the minimum value allowed
129
+ * @param o the value to check
130
+ */
131
+ export declare function isMinValue(minValue: number, o?: string | number | null): boolean;
68
132
  /**
69
133
  * Throws a ValidationError if the value is less than the provided minimum value.
70
134
  * Undefined and null values are skipped and not validated.
@@ -74,6 +138,14 @@ export declare function isNumber(name: string, o?: string | null | number): void
74
138
  * @param o the value to check
75
139
  */
76
140
  export declare function minValue(name: string, minValue: number, o?: number | string | null): void;
141
+ /**
142
+ * Tests if a value is more than the provided maximum value.
143
+ * Undefined and null values are skipped and not validated.
144
+ *
145
+ * @param maxValue the maximum value allowed
146
+ * @param o the value to check
147
+ */
148
+ export declare function isMaxValue(maxValue: number, o?: string | number | null): boolean;
77
149
  /**
78
150
  * Throws a ValidationError if the value is more than the provided maximum value.
79
151
  * Undefined and null values are skipped and not validated.
@@ -83,6 +155,15 @@ export declare function minValue(name: string, minValue: number, o?: number | st
83
155
  * @param o the value to check
84
156
  */
85
157
  export declare function maxValue(name: string, maxValue: number, o?: number | string | null): void;
158
+ /**
159
+ * Tests if the value is between the provided minimum and maximum values inclusive.
160
+ * Undefined and null values are skipped and not validated.
161
+ *
162
+ * @param minValue the minimum value allowed
163
+ * @param maxValue the maximum value allowed
164
+ * @param o the value to check
165
+ */
166
+ export declare function isBetweenValues(minValue: number, maxValue: number, o?: string | number | null): boolean;
86
167
  /**
87
168
  * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.
88
169
  * Undefined and null values are skipped and not validated.
@@ -94,14 +175,14 @@ export declare function maxValue(name: string, maxValue: number, o?: number | st
94
175
  */
95
176
  export declare function betweenValues(name: string, minValue: number, maxValue: number, o?: string | number | null): void;
96
177
  export interface StringValidationOptions {
97
- readonly name: string;
98
178
  readonly required: boolean;
99
179
  readonly minLength?: number;
100
180
  readonly maxLength?: number;
101
181
  readonly regex?: RegExp;
102
182
  readonly notBlank?: boolean;
103
183
  readonly notEmpty?: boolean;
104
- readonly isEmail?: boolean;
105
- readonly isNumber?: boolean;
184
+ readonly email?: boolean;
185
+ readonly number?: boolean;
106
186
  }
107
- export declare function validateString(options: StringValidationOptions, value?: unknown): void;
187
+ export declare function isValidString(options: StringValidationOptions, value?: unknown): value is string;
188
+ export declare function validString(name: string, options: StringValidationOptions, value?: unknown): void;
@@ -1,7 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateString = exports.betweenValues = exports.maxValue = exports.minValue = exports.isNumber = exports.minLength = exports.maxLength = exports.isEmail = exports.matches = exports.notBlank = exports.notEmpty = exports.notNull = void 0;
3
+ exports.validString = exports.isValidString = exports.betweenValues = exports.isBetweenValues = exports.maxValue = exports.isMaxValue = exports.minValue = exports.isMinValue = exports.number = exports.isNumber = exports.minLength = exports.isMinLength = exports.maxLength = exports.isMaxLength = exports.email = exports.isEmail = exports.match = exports.isMatch = exports.notBlank = exports.isNotBlank = exports.notEmpty = exports.isNotEmpty = exports.notNull = exports.isNotNull = void 0;
4
4
  const errors_1 = require("../errors");
5
+ /**
6
+ * Tests if a value is null or undefined.
7
+ *
8
+ * @param o the value to check
9
+ */
10
+ function isNotNull(o) {
11
+ return o !== undefined && o !== null;
12
+ }
13
+ exports.isNotNull = isNotNull;
5
14
  /**
6
15
  * Throws a ValidationError if the value is null or undefined.
7
16
  * This function also asserts the value to be NonNullable if the check passes.
@@ -10,11 +19,20 @@ const errors_1 = require("../errors");
10
19
  * @param o the value to check
11
20
  */
12
21
  function notNull(name, o) {
13
- if (o === undefined || o === null) {
22
+ if (!isNotNull(o)) {
14
23
  throw new errors_1.ValidationError(`${name} may not be null or undefined`);
15
24
  }
16
25
  }
17
26
  exports.notNull = notNull;
27
+ /**
28
+ * Tests if a value is empty, null, undefined or has a length of 0.
29
+ *
30
+ * @param o the value to check
31
+ */
32
+ function isNotEmpty(o) {
33
+ return !(o === undefined || o === null || o.toString().length === 0);
34
+ }
35
+ exports.isNotEmpty = isNotEmpty;
18
36
  /**
19
37
  * Throws a ValidationError if the value is null, undefined or the length is 0.
20
38
  * This function also asserts the value to be NonNullable if the check passes.
@@ -23,11 +41,20 @@ exports.notNull = notNull;
23
41
  * @param o the value to check
24
42
  */
25
43
  function notEmpty(name, o) {
26
- if (o === undefined || o === null || o.toString().length === 0) {
44
+ if (!isNotEmpty(o)) {
27
45
  throw new errors_1.ValidationError(`${name} may not be empty`);
28
46
  }
29
47
  }
30
48
  exports.notEmpty = notEmpty;
49
+ /**
50
+ * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.
51
+ *
52
+ * @param o the value to check
53
+ */
54
+ function isNotBlank(o) {
55
+ return !(o === undefined || o === null || o.toString().trim().length === 0);
56
+ }
57
+ exports.isNotBlank = isNotBlank;
31
58
  /**
32
59
  * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.
33
60
  * This function also asserts the value to be NonNullable if the check passes.
@@ -36,25 +63,50 @@ exports.notEmpty = notEmpty;
36
63
  * @param o the value to check
37
64
  */
38
65
  function notBlank(name, o) {
39
- if (o === undefined || o === null || o.toString().trim().length === 0) {
66
+ if (!isNotBlank(o)) {
40
67
  throw new errors_1.ValidationError(`${name} may not be blank`);
41
68
  }
42
69
  }
43
70
  exports.notBlank = notBlank;
44
71
  /**
45
- * Throws a ValidationError if the value does not match the regular expression provided.
72
+ * Tests if a value does not match the regular expression provided.
73
+ * Undefined and null values are skipped and not tested.
74
+ *
75
+ * @param regex the regular expression to test with
76
+ * @param o the value to check
77
+ */
78
+ function isMatch(regex, o) {
79
+ if (o === undefined || o === null) {
80
+ return true;
81
+ }
82
+ return o.match(regex) !== null;
83
+ }
84
+ exports.isMatch = isMatch;
85
+ /**
86
+ * Throws a ValidationError if the value matches the regular expression provided.
46
87
  * Undefined and null values are skipped and not validated.
47
88
  *
48
89
  * @param name the name of the variable
49
90
  * @param regex the regular expression to validate with
50
91
  * @param o the value to check
51
92
  */
52
- function matches(name, regex, o) {
53
- if (o !== undefined && o !== null && !o.match(regex)) {
93
+ function match(name, regex, o) {
94
+ if (!isMatch(regex, o)) {
54
95
  throw new errors_1.ValidationError(`${name} must match ${regex}`);
55
96
  }
56
97
  }
57
- exports.matches = matches;
98
+ exports.match = match;
99
+ /**
100
+ * Tests if a value is a valid email address.
101
+ * Undefined and null values are skipped and not validated.
102
+ *
103
+ * @param o the value to check
104
+ */
105
+ function isEmail(o) {
106
+ const expression = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
107
+ return !(o !== undefined && o !== null && !expression.test(o));
108
+ }
109
+ exports.isEmail = isEmail;
58
110
  /**
59
111
  * Throws a ValidationError if the value provided is not an email.
60
112
  * Undefined and null values are skipped and not validated.
@@ -62,13 +114,23 @@ exports.matches = matches;
62
114
  * @param name the name of the variable
63
115
  * @param o the value to check
64
116
  */
65
- function isEmail(name, o) {
66
- const expression = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/;
67
- if (o !== undefined && o !== null && !expression.test(o)) {
117
+ function email(name, o) {
118
+ if (!isEmail(o)) {
68
119
  throw new errors_1.ValidationError(`${name} is not a valid email address`);
69
120
  }
70
121
  }
71
- exports.isEmail = isEmail;
122
+ exports.email = email;
123
+ /**
124
+ * Tests if a value has a length that is less than the provided length.
125
+ * Undefined and null values are skipped and not validated.
126
+ *
127
+ * @param length the maximum length of the variable
128
+ * @param o the value to check
129
+ */
130
+ function isMaxLength(length, o) {
131
+ return !(o !== undefined && o !== null && o.length > length);
132
+ }
133
+ exports.isMaxLength = isMaxLength;
72
134
  /**
73
135
  * Throws a ValidationError if the value provided has a length that exceeds the provided length.
74
136
  * Undefined and null values are skipped and not validated.
@@ -78,11 +140,22 @@ exports.isEmail = isEmail;
78
140
  * @param o the value to check
79
141
  */
80
142
  function maxLength(name, length, o) {
81
- if (o !== undefined && o !== null && o.length > length) {
143
+ if (!isMaxLength(length, o)) {
82
144
  throw new errors_1.ValidationError(`length of ${name} may not exceed ${length}`);
83
145
  }
84
146
  }
85
147
  exports.maxLength = maxLength;
148
+ /**
149
+ * Tests if a value has a length that is greater than the provided length.
150
+ * Undefined and null values are skipped and not validated.
151
+ *
152
+ * @param length the minimum length of the variable
153
+ * @param o the value to check
154
+ */
155
+ function isMinLength(length, o) {
156
+ return !(o !== undefined && o !== null && o.length < length);
157
+ }
158
+ exports.isMinLength = isMinLength;
86
159
  /**
87
160
  * Throws a ValidationError if the value provided has a length that is less than the provided length.
88
161
  * Undefined and null values are skipped and not validated.
@@ -92,11 +165,21 @@ exports.maxLength = maxLength;
92
165
  * @param o the value to check
93
166
  */
94
167
  function minLength(name, length, o) {
95
- if (o !== undefined && o !== null && o.length < length) {
168
+ if (!isMinLength(length, o)) {
96
169
  throw new errors_1.ValidationError(`length of ${name} may not be less than ${length}`);
97
170
  }
98
171
  }
99
172
  exports.minLength = minLength;
173
+ /**
174
+ * Tests if a value provided is a number.
175
+ * Undefined and null values are skipped and not validated.
176
+ *
177
+ * @param o the value to check
178
+ */
179
+ function isNumber(o) {
180
+ return o === undefined || o === null || !isNaN(+o);
181
+ }
182
+ exports.isNumber = isNumber;
100
183
  /**
101
184
  * Throws a ValidationError if the value provided is not a number.
102
185
  * Undefined and null values are skipped and not validated.
@@ -104,12 +187,23 @@ exports.minLength = minLength;
104
187
  * @param name the name of the variable
105
188
  * @param o the value to check
106
189
  */
107
- function isNumber(name, o) {
108
- if (o !== undefined && o !== null && isNaN(Number(o))) {
190
+ function number(name, o) {
191
+ if (!isNumber(o)) {
109
192
  throw new errors_1.ValidationError(`${name} is not a number`);
110
193
  }
111
194
  }
112
- exports.isNumber = isNumber;
195
+ exports.number = number;
196
+ /**
197
+ * Tests if a value is less than the provided minimum value.
198
+ * Undefined and null values are skipped and not validated.
199
+ *
200
+ * @param minValue the minimum value allowed
201
+ * @param o the value to check
202
+ */
203
+ function isMinValue(minValue, o) {
204
+ return o === undefined || o === null || +o >= minValue;
205
+ }
206
+ exports.isMinValue = isMinValue;
113
207
  /**
114
208
  * Throws a ValidationError if the value is less than the provided minimum value.
115
209
  * Undefined and null values are skipped and not validated.
@@ -119,16 +213,22 @@ exports.isNumber = isNumber;
119
213
  * @param o the value to check
120
214
  */
121
215
  function minValue(name, minValue, o) {
122
- if (o !== undefined && o !== null) {
123
- if (typeof o === 'string') {
124
- isNumber(name, o);
125
- }
126
- if (+o < minValue) {
127
- throw new errors_1.ValidationError(`${name} may not be less than ${minValue}`);
128
- }
216
+ if (!isMinValue(minValue, o)) {
217
+ throw new errors_1.ValidationError(`${name} may not be less than ${minValue}`);
129
218
  }
130
219
  }
131
220
  exports.minValue = minValue;
221
+ /**
222
+ * Tests if a value is more than the provided maximum value.
223
+ * Undefined and null values are skipped and not validated.
224
+ *
225
+ * @param maxValue the maximum value allowed
226
+ * @param o the value to check
227
+ */
228
+ function isMaxValue(maxValue, o) {
229
+ return !(o !== undefined && o !== null && +o > maxValue);
230
+ }
231
+ exports.isMaxValue = isMaxValue;
132
232
  /**
133
233
  * Throws a ValidationError if the value is more than the provided maximum value.
134
234
  * Undefined and null values are skipped and not validated.
@@ -138,16 +238,23 @@ exports.minValue = minValue;
138
238
  * @param o the value to check
139
239
  */
140
240
  function maxValue(name, maxValue, o) {
141
- if (o !== undefined && o !== null) {
142
- if (typeof o === 'string') {
143
- isNumber(name, o);
144
- }
145
- if (+o > maxValue) {
146
- throw new errors_1.ValidationError(`${name} may not be greater than ${maxValue}`);
147
- }
241
+ if (!isMaxValue(maxValue, o)) {
242
+ throw new errors_1.ValidationError(`${name} may not be greater than ${maxValue}`);
148
243
  }
149
244
  }
150
245
  exports.maxValue = maxValue;
246
+ /**
247
+ * Tests if the value is between the provided minimum and maximum values inclusive.
248
+ * Undefined and null values are skipped and not validated.
249
+ *
250
+ * @param minValue the minimum value allowed
251
+ * @param maxValue the maximum value allowed
252
+ * @param o the value to check
253
+ */
254
+ function isBetweenValues(minValue, maxValue, o) {
255
+ return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));
256
+ }
257
+ exports.isBetweenValues = isBetweenValues;
151
258
  /**
152
259
  * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.
153
260
  * Undefined and null values are skipped and not validated.
@@ -158,48 +265,65 @@ exports.maxValue = maxValue;
158
265
  * @param o the value to check
159
266
  */
160
267
  function betweenValues(name, minValue, maxValue, o) {
161
- if (o !== undefined && o !== null) {
162
- if (typeof o === 'string') {
163
- isNumber(name, o);
164
- }
165
- if (+o < minValue || +o > maxValue) {
166
- throw new errors_1.ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
167
- }
268
+ if (!isBetweenValues(minValue, maxValue, o)) {
269
+ throw new errors_1.ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
168
270
  }
169
271
  }
170
272
  exports.betweenValues = betweenValues;
171
273
  const isString = (value) => typeof value === 'string';
172
- function validateString(options, value) {
274
+ function isValidString(options, value) {
173
275
  if (options.required) {
174
- notNull(options.name, value);
276
+ if (!isNotNull(value)) {
277
+ return false;
278
+ }
175
279
  }
176
280
  else if (value === undefined || value === null) {
177
- return;
281
+ return true;
178
282
  }
179
283
  if (!isString(value)) {
180
- throw new errors_1.ValidationError(`${options.name} must be a string`);
284
+ return false;
181
285
  }
182
- if (options.minLength !== undefined && value.length < options.minLength) {
183
- throw new errors_1.ValidationError(`${options.name} must be at least ${options.minLength} characters`);
286
+ if (options.minLength && !isMinLength(options.minLength, value)) {
287
+ return false;
184
288
  }
185
- if (options.maxLength !== undefined && value.length > options.maxLength) {
186
- throw new errors_1.ValidationError(`${options.name} must be at most ${options.maxLength} characters`);
289
+ if (options.maxLength && !isMaxLength(options.maxLength, value)) {
290
+ return false;
187
291
  }
188
- if (options.regex !== undefined && !options.regex.test(value)) {
189
- throw new errors_1.ValidationError(`${options.name} must match ${options.regex}`);
292
+ if (options.regex && !isMatch(options.regex, value)) {
293
+ return false;
190
294
  }
191
- if (options.notBlank !== undefined && options.notBlank) {
192
- notBlank(options.name, value);
295
+ if (options.notBlank && !isNotBlank(value)) {
296
+ return false;
193
297
  }
194
- if (options.notEmpty !== undefined && options.notEmpty) {
195
- notEmpty(options.name, value);
298
+ if (options.notEmpty && !isNotEmpty(value)) {
299
+ return false;
196
300
  }
197
- if (options.isEmail !== undefined && options.isEmail) {
198
- isEmail(options.name, value);
301
+ if (options.email && !isEmail(value)) {
302
+ return false;
199
303
  }
200
- if (options.isNumber !== undefined && options.isNumber) {
201
- isNumber(options.name, value);
304
+ if (options.number && !isNumber(value)) {
305
+ return false;
306
+ }
307
+ return true;
308
+ }
309
+ exports.isValidString = isValidString;
310
+ function validString(name, options, value) {
311
+ if (options.required) {
312
+ notNull(name, value);
313
+ }
314
+ else if (value === undefined || value === null) {
315
+ return;
316
+ }
317
+ if (!isString(value)) {
318
+ throw new errors_1.ValidationError(`${name} must be a string`);
202
319
  }
320
+ options.minLength && minLength(name, options.minLength, value);
321
+ options.maxLength && maxLength(name, options.maxLength, value);
322
+ options.regex && match(name, options.regex, value);
323
+ options.notBlank && notBlank(name, value);
324
+ options.notEmpty && notEmpty(name, value);
325
+ options.email && email(name, value);
326
+ options.number && number(name, value);
203
327
  }
204
- exports.validateString = validateString;
328
+ exports.validString = validString;
205
329
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["validators.ts"],"names":[],"mappings":";;;AAAA,sCAA0C;AAE1C;;;;;;GAMG;AACH,SAAgB,OAAO,CACrB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,EAAE;QACjC,MAAM,IAAI,wBAAe,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;KACnE;AACH,CAAC;AAPD,0BAOC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CACtB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QAC9D,MAAM,IAAI,wBAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;AACH,CAAC;AAPD,4BAOC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CACtB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QACrE,MAAM,IAAI,wBAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;AACH,CAAC;AAPD,4BAOC;AAED;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,IAAY,EAAE,KAAa,EAAE,CAAiB;IACpE,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI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