@nr1e/commons 0.0.3-alpha.2 → 0.0.3-alpha.21

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.
Files changed (56) hide show
  1. package/bitsnbytes/b64.d.ts +1 -0
  2. package/bitsnbytes/b64.d.ts.map +1 -0
  3. package/bitsnbytes/b64.js +17 -25
  4. package/bitsnbytes/b64.js.map +1 -1
  5. package/bitsnbytes/index.d.ts +1 -0
  6. package/bitsnbytes/index.d.ts.map +1 -0
  7. package/bitsnbytes/index.js +1 -17
  8. package/bitsnbytes/index.js.map +1 -1
  9. package/errors/errors.d.ts +52 -30
  10. package/errors/errors.d.ts.map +1 -0
  11. package/errors/errors.js +104 -101
  12. package/errors/errors.js.map +1 -1
  13. package/errors/index.d.ts +1 -0
  14. package/errors/index.d.ts.map +1 -0
  15. package/errors/index.js +1 -17
  16. package/errors/index.js.map +1 -1
  17. package/http/http-method.d.ts +1 -0
  18. package/http/http-method.d.ts.map +1 -0
  19. package/http/http-method.js +2 -5
  20. package/http/http-method.js.map +1 -1
  21. package/http/http-status-code.d.ts +1 -0
  22. package/http/http-status-code.d.ts.map +1 -0
  23. package/http/http-status-code.js +2 -5
  24. package/http/http-status-code.js.map +1 -1
  25. package/http/index.d.ts +1 -0
  26. package/http/index.d.ts.map +1 -0
  27. package/http/index.js +2 -18
  28. package/http/index.js.map +1 -1
  29. package/lang/index.d.ts +2 -0
  30. package/lang/index.d.ts.map +1 -0
  31. package/lang/index.js +2 -17
  32. package/lang/index.js.map +1 -1
  33. package/lang/sleep.d.ts +7 -0
  34. package/lang/sleep.d.ts.map +1 -0
  35. package/lang/sleep.js +9 -0
  36. package/lang/sleep.js.map +1 -0
  37. package/lang/type-functions.d.ts +1 -0
  38. package/lang/type-functions.d.ts.map +1 -0
  39. package/lang/type-functions.js +3 -9
  40. package/lang/type-functions.js.map +1 -1
  41. package/package.json +37 -19
  42. package/validator/index.d.ts +1 -0
  43. package/validator/index.d.ts.map +1 -0
  44. package/validator/index.js +1 -17
  45. package/validator/index.js.map +1 -1
  46. package/validator/validators.d.ts +1 -0
  47. package/validator/validators.d.ts.map +1 -0
  48. package/validator/validators.js +37 -64
  49. package/validator/validators.js.map +1 -1
  50. package/.prettierrc.js +0 -3
  51. package/LICENSE +0 -26
  52. package/README.md +0 -14
  53. package/index.d.ts +0 -5
  54. package/index.js +0 -9
  55. package/index.js.map +0 -1
  56. package/jest.config.js +0 -8
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@nr1e/commons",
3
3
  "description": "Provides common patterns for validation",
4
- "version": "0.0.3-alpha.2",
5
- "main": "index.js",
6
- "types": "index.d.ts",
4
+ "version": "0.0.3-alpha.21",
5
+ "type": "module",
7
6
  "author": "NR1E, Inc.",
8
7
  "publishConfig": {
9
8
  "access": "public"
@@ -13,39 +12,58 @@
13
12
  "type": "git",
14
13
  "url": "https://github.com/nr1etech/commons-js.git"
15
14
  },
15
+ "bugs": {
16
+ "url": "https://github.com/nr1etech/commons-js/issues"
17
+ },
18
+ "homepage": "https://github.com/nr1etech/commons-js#readme",
16
19
  "files": [
17
- "/**/*.d.ts",
18
- "/**/*.js",
19
- "/**/*.js.map",
20
- "!/**/*.test.*"
20
+ "**"
21
21
  ],
22
22
  "devDependencies": {
23
- "@types/jest": "^29.5.10",
23
+ "@types/jest": "^29.5.11",
24
24
  "@types/node": "20.8.2",
25
25
  "gts": "^5.2.0",
26
26
  "jest": "^29.7.0",
27
- "ts-jest": "^29.1.1",
27
+ "ts-jest": "^29.1.2",
28
+ "ts-node": "^10.9.2",
28
29
  "typedoc": "^0.25.6",
29
30
  "typescript": "~5.1.6"
30
31
  },
32
+ "dependencies": {
33
+ "tslib": "^2.6.2"
34
+ },
31
35
  "exports": {
32
- ".": "./index.js",
33
- "./bitsnbytes": "./bitsnbytes/index.js",
34
- "./errors": "./errors/index.js",
35
- "./http": "./http/index.js",
36
- "./lang": "./lang/index.js",
36
+ "./bitsnbytes": {
37
+ "import": "./bitsnbytes/index.js",
38
+ "types": "./bitsnbytes/index.d.ts"
39
+ },
40
+ "./errors": {
41
+ "import": "./errors/index.js",
42
+ "types": "./errors/index.d.ts"
43
+ },
44
+ "./http": {
45
+ "import": "./http/index.js",
46
+ "types": "./http/index.d.ts"
47
+ },
48
+ "./lang": {
49
+ "import": "./lang/index.js",
50
+ "types": "./lang/index.d.ts"
51
+ },
37
52
  "./package.json": "./package.json",
38
- "./validator": "./validator/index.js"
53
+ "./validator": {
54
+ "import": "./validator/index.js",
55
+ "types": "./validator/index.d.ts"
56
+ }
39
57
  },
40
58
  "scripts": {
41
59
  "build": "tsc",
42
- "postbuild": "prettier --check . && gts lint",
60
+ "postbuild": "prettier --check . && gts lint && cp package.json dist",
43
61
  "watch": "tsc -w",
44
- "test": "jest",
62
+ "test": "jest --coverage --collectCoverageFrom='src/**/*.{ts,tsx}'",
45
63
  "lint": "gts lint",
46
- "clean": "find . -depth 1 \\( -name '*.js' -o -name '*.d.ts' -o -name '*.map' \\) ! -name '.*' ! -name 'jest.config.js' -delete",
64
+ "clean": "rm -rf dist && rm -rf site",
47
65
  "fix": "gts fix",
48
66
  "makepretty": "prettier --write .",
49
- "site": "typedoc --out site index.ts"
67
+ "site": "typedoc --out site \"src/**/*.ts\" --exclude \"src/**/*.test.ts\""
50
68
  }
51
69
  }
@@ -1 +1,2 @@
1
1
  export * from './validators';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
@@ -1,18 +1,2 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./validators"), exports);
1
+ export * from './validators';
18
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC","sourcesContent":["export * from './validators';\n"]}
@@ -186,3 +186,4 @@ export interface StringValidationOptions {
186
186
  }
187
187
  export declare function isValidString(options: StringValidationOptions, value?: unknown): value is string;
188
188
  export declare function validString(name: string, options: StringValidationOptions, value?: unknown): void;
189
+ //# sourceMappingURL=validators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validator/validators.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAEhE;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CACrB,IAAI,EAAE,MAAM,EACZ,CAAC,CAAC,EAAE,OAAO,GACV,OAAO,CAAC,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAInC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAEjE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,E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AC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,QAO3B;AAID,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,uBAAuB,EAChC,KAAK,CAAC,EAAE,OAAO,GACd,KAAK,IAAI,MAAM,CAiCjB;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,uBAAuB,EAChC,KAAK,CAAC,EAAE,OAAO,GACd,IAAI,CAgBN"}
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- const errors_1 = require("../errors");
1
+ import { ValidationError } from '../errors';
5
2
  /**
6
3
  * Tests if a value is null or undefined.
7
4
  *
8
5
  * @param o the value to check
9
6
  */
10
- function isNotNull(o) {
7
+ export function isNotNull(o) {
11
8
  return o !== undefined && o !== null;
12
9
  }
13
- exports.isNotNull = isNotNull;
14
10
  /**
15
11
  * Throws a ValidationError if the value is null or undefined.
16
12
  * This function also asserts the value to be NonNullable if the check passes.
@@ -18,21 +14,19 @@ exports.isNotNull = isNotNull;
18
14
  * @param name the name of the variable
19
15
  * @param o the value to check
20
16
  */
21
- function notNull(name, o) {
17
+ export function notNull(name, o) {
22
18
  if (!isNotNull(o)) {
23
- throw new errors_1.ValidationError(`${name} may not be null or undefined`);
19
+ throw new ValidationError(`${name} may not be null or undefined`);
24
20
  }
25
21
  }
26
- exports.notNull = notNull;
27
22
  /**
28
23
  * Tests if a value is empty, null, undefined or has a length of 0.
29
24
  *
30
25
  * @param o the value to check
31
26
  */
32
- function isNotEmpty(o) {
27
+ export function isNotEmpty(o) {
33
28
  return !(o === undefined || o === null || o.toString().length === 0);
34
29
  }
35
- exports.isNotEmpty = isNotEmpty;
36
30
  /**
37
31
  * Throws a ValidationError if the value is null, undefined or the length is 0.
38
32
  * This function also asserts the value to be NonNullable if the check passes.
@@ -40,21 +34,19 @@ exports.isNotEmpty = isNotEmpty;
40
34
  * @param name the name of the variable
41
35
  * @param o the value to check
42
36
  */
43
- function notEmpty(name, o) {
37
+ export function notEmpty(name, o) {
44
38
  if (!isNotEmpty(o)) {
45
- throw new errors_1.ValidationError(`${name} may not be empty`);
39
+ throw new ValidationError(`${name} may not be empty`);
46
40
  }
47
41
  }
48
- exports.notEmpty = notEmpty;
49
42
  /**
50
43
  * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.
51
44
  *
52
45
  * @param o the value to check
53
46
  */
54
- function isNotBlank(o) {
47
+ export function isNotBlank(o) {
55
48
  return !(o === undefined || o === null || o.toString().trim().length === 0);
56
49
  }
57
- exports.isNotBlank = isNotBlank;
58
50
  /**
59
51
  * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.
60
52
  * This function also asserts the value to be NonNullable if the check passes.
@@ -62,12 +54,11 @@ exports.isNotBlank = isNotBlank;
62
54
  * @param name the name of the variable
63
55
  * @param o the value to check
64
56
  */
65
- function notBlank(name, o) {
57
+ export function notBlank(name, o) {
66
58
  if (!isNotBlank(o)) {
67
- throw new errors_1.ValidationError(`${name} may not be blank`);
59
+ throw new ValidationError(`${name} may not be blank`);
68
60
  }
69
61
  }
70
- exports.notBlank = notBlank;
71
62
  /**
72
63
  * Tests if a value does not match the regular expression provided.
73
64
  * Undefined and null values are skipped and not tested.
@@ -75,13 +66,12 @@ exports.notBlank = notBlank;
75
66
  * @param regex the regular expression to test with
76
67
  * @param o the value to check
77
68
  */
78
- function isMatch(regex, o) {
69
+ export function isMatch(regex, o) {
79
70
  if (o === undefined || o === null) {
80
71
  return true;
81
72
  }
82
73
  return o.match(regex) !== null;
83
74
  }
84
- exports.isMatch = isMatch;
85
75
  /**
86
76
  * Throws a ValidationError if the value matches the regular expression provided.
87
77
  * Undefined and null values are skipped and not validated.
@@ -90,23 +80,21 @@ exports.isMatch = isMatch;
90
80
  * @param regex the regular expression to validate with
91
81
  * @param o the value to check
92
82
  */
93
- function match(name, regex, o) {
83
+ export function match(name, regex, o) {
94
84
  if (!isMatch(regex, o)) {
95
- throw new errors_1.ValidationError(`${name} must match ${regex}`);
85
+ throw new ValidationError(`${name} must match ${regex}`);
96
86
  }
97
87
  }
98
- exports.match = match;
99
88
  /**
100
89
  * Tests if a value is a valid email address.
101
90
  * Undefined and null values are skipped and not validated.
102
91
  *
103
92
  * @param o the value to check
104
93
  */
105
- function isEmail(o) {
94
+ export function isEmail(o) {
106
95
  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
96
  return !(o !== undefined && o !== null && !expression.test(o));
108
97
  }
109
- exports.isEmail = isEmail;
110
98
  /**
111
99
  * Throws a ValidationError if the value provided is not an email.
112
100
  * Undefined and null values are skipped and not validated.
@@ -114,12 +102,11 @@ exports.isEmail = isEmail;
114
102
  * @param name the name of the variable
115
103
  * @param o the value to check
116
104
  */
117
- function email(name, o) {
105
+ export function email(name, o) {
118
106
  if (!isEmail(o)) {
119
- throw new errors_1.ValidationError(`${name} is not a valid email address`);
107
+ throw new ValidationError(`${name} is not a valid email address`);
120
108
  }
121
109
  }
122
- exports.email = email;
123
110
  /**
124
111
  * Tests if a value has a length that is less than the provided length.
125
112
  * Undefined and null values are skipped and not validated.
@@ -127,10 +114,9 @@ exports.email = email;
127
114
  * @param length the maximum length of the variable
128
115
  * @param o the value to check
129
116
  */
130
- function isMaxLength(length, o) {
117
+ export function isMaxLength(length, o) {
131
118
  return !(o !== undefined && o !== null && o.length > length);
132
119
  }
133
- exports.isMaxLength = isMaxLength;
134
120
  /**
135
121
  * Throws a ValidationError if the value provided has a length that exceeds the provided length.
136
122
  * Undefined and null values are skipped and not validated.
@@ -139,12 +125,11 @@ exports.isMaxLength = isMaxLength;
139
125
  * @param length the maximum length of the variable
140
126
  * @param o the value to check
141
127
  */
142
- function maxLength(name, length, o) {
128
+ export function maxLength(name, length, o) {
143
129
  if (!isMaxLength(length, o)) {
144
- throw new errors_1.ValidationError(`length of ${name} may not exceed ${length}`);
130
+ throw new ValidationError(`length of ${name} may not exceed ${length}`);
145
131
  }
146
132
  }
147
- exports.maxLength = maxLength;
148
133
  /**
149
134
  * Tests if a value has a length that is greater than the provided length.
150
135
  * Undefined and null values are skipped and not validated.
@@ -152,10 +137,9 @@ exports.maxLength = maxLength;
152
137
  * @param length the minimum length of the variable
153
138
  * @param o the value to check
154
139
  */
155
- function isMinLength(length, o) {
140
+ export function isMinLength(length, o) {
156
141
  return !(o !== undefined && o !== null && o.length < length);
157
142
  }
158
- exports.isMinLength = isMinLength;
159
143
  /**
160
144
  * Throws a ValidationError if the value provided has a length that is less than the provided length.
161
145
  * Undefined and null values are skipped and not validated.
@@ -164,22 +148,20 @@ exports.isMinLength = isMinLength;
164
148
  * @param length the minimum length of the variable
165
149
  * @param o the value to check
166
150
  */
167
- function minLength(name, length, o) {
151
+ export function minLength(name, length, o) {
168
152
  if (!isMinLength(length, o)) {
169
- throw new errors_1.ValidationError(`length of ${name} may not be less than ${length}`);
153
+ throw new ValidationError(`length of ${name} may not be less than ${length}`);
170
154
  }
171
155
  }
172
- exports.minLength = minLength;
173
156
  /**
174
157
  * Tests if a value provided is a number.
175
158
  * Undefined and null values are skipped and not validated.
176
159
  *
177
160
  * @param o the value to check
178
161
  */
179
- function isNumber(o) {
162
+ export function isNumber(o) {
180
163
  return o === undefined || o === null || !isNaN(+o);
181
164
  }
182
- exports.isNumber = isNumber;
183
165
  /**
184
166
  * Throws a ValidationError if the value provided is not a number.
185
167
  * Undefined and null values are skipped and not validated.
@@ -187,12 +169,11 @@ exports.isNumber = isNumber;
187
169
  * @param name the name of the variable
188
170
  * @param o the value to check
189
171
  */
190
- function number(name, o) {
172
+ export function number(name, o) {
191
173
  if (!isNumber(o)) {
192
- throw new errors_1.ValidationError(`${name} is not a number`);
174
+ throw new ValidationError(`${name} is not a number`);
193
175
  }
194
176
  }
195
- exports.number = number;
196
177
  /**
197
178
  * Tests if a value is less than the provided minimum value.
198
179
  * Undefined and null values are skipped and not validated.
@@ -200,10 +181,9 @@ exports.number = number;
200
181
  * @param minValue the minimum value allowed
201
182
  * @param o the value to check
202
183
  */
203
- function isMinValue(minValue, o) {
184
+ export function isMinValue(minValue, o) {
204
185
  return o === undefined || o === null || +o >= minValue;
205
186
  }
206
- exports.isMinValue = isMinValue;
207
187
  /**
208
188
  * Throws a ValidationError if the value is less than the provided minimum value.
209
189
  * Undefined and null values are skipped and not validated.
@@ -212,12 +192,11 @@ exports.isMinValue = isMinValue;
212
192
  * @param minValue the minimum value allowed
213
193
  * @param o the value to check
214
194
  */
215
- function minValue(name, minValue, o) {
195
+ export function minValue(name, minValue, o) {
216
196
  if (!isMinValue(minValue, o)) {
217
- throw new errors_1.ValidationError(`${name} may not be less than ${minValue}`);
197
+ throw new ValidationError(`${name} may not be less than ${minValue}`);
218
198
  }
219
199
  }
220
- exports.minValue = minValue;
221
200
  /**
222
201
  * Tests if a value is more than the provided maximum value.
223
202
  * Undefined and null values are skipped and not validated.
@@ -225,10 +204,9 @@ exports.minValue = minValue;
225
204
  * @param maxValue the maximum value allowed
226
205
  * @param o the value to check
227
206
  */
228
- function isMaxValue(maxValue, o) {
207
+ export function isMaxValue(maxValue, o) {
229
208
  return !(o !== undefined && o !== null && +o > maxValue);
230
209
  }
231
- exports.isMaxValue = isMaxValue;
232
210
  /**
233
211
  * Throws a ValidationError if the value is more than the provided maximum value.
234
212
  * Undefined and null values are skipped and not validated.
@@ -237,12 +215,11 @@ exports.isMaxValue = isMaxValue;
237
215
  * @param maxValue the maximum value allowed
238
216
  * @param o the value to check
239
217
  */
240
- function maxValue(name, maxValue, o) {
218
+ export function maxValue(name, maxValue, o) {
241
219
  if (!isMaxValue(maxValue, o)) {
242
- throw new errors_1.ValidationError(`${name} may not be greater than ${maxValue}`);
220
+ throw new ValidationError(`${name} may not be greater than ${maxValue}`);
243
221
  }
244
222
  }
245
- exports.maxValue = maxValue;
246
223
  /**
247
224
  * Tests if the value is between the provided minimum and maximum values inclusive.
248
225
  * Undefined and null values are skipped and not validated.
@@ -251,10 +228,9 @@ exports.maxValue = maxValue;
251
228
  * @param maxValue the maximum value allowed
252
229
  * @param o the value to check
253
230
  */
254
- function isBetweenValues(minValue, maxValue, o) {
231
+ export function isBetweenValues(minValue, maxValue, o) {
255
232
  return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));
256
233
  }
257
- exports.isBetweenValues = isBetweenValues;
258
234
  /**
259
235
  * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.
260
236
  * Undefined and null values are skipped and not validated.
@@ -264,14 +240,13 @@ exports.isBetweenValues = isBetweenValues;
264
240
  * @param maxValue the maximum value allowed
265
241
  * @param o the value to check
266
242
  */
267
- function betweenValues(name, minValue, maxValue, o) {
243
+ export function betweenValues(name, minValue, maxValue, o) {
268
244
  if (!isBetweenValues(minValue, maxValue, o)) {
269
- throw new errors_1.ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
245
+ throw new ValidationError(`${name} must be between ${minValue} and ${maxValue}`);
270
246
  }
271
247
  }
272
- exports.betweenValues = betweenValues;
273
248
  const isString = (value) => typeof value === 'string';
274
- function isValidString(options, value) {
249
+ export function isValidString(options, value) {
275
250
  if (options.required) {
276
251
  if (!isNotNull(value)) {
277
252
  return false;
@@ -306,8 +281,7 @@ function isValidString(options, value) {
306
281
  }
307
282
  return true;
308
283
  }
309
- exports.isValidString = isValidString;
310
- function validString(name, options, value) {
284
+ export function validString(name, options, value) {
311
285
  if (options.required) {
312
286
  notNull(name, value);
313
287
  }
@@ -315,7 +289,7 @@ function validString(name, options, value) {
315
289
  return;
316
290
  }
317
291
  if (!isString(value)) {
318
- throw new errors_1.ValidationError(`${name} must be a string`);
292
+ throw new ValidationError(`${name} must be a string`);
319
293
  }
320
294
  options.minLength && minLength(name, options.minLength, value);
321
295
  options.maxLength && maxLength(name, options.maxLength, value);
@@ -325,5 +299,4 @@ function validString(name, options, value) {
325
299
  options.email && email(name, value);
326
300
  options.number && number(name, value);
327
301
  }
328
- exports.validString = validString;
329
302
  //# sourceMappingURL=validators.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"validators.js","sourceRoot":"","sources":["validators.ts"],"names":[],"mappings":";;;AAAA,sCAA0C;AAE1C;;;;GAIG;AACH,SAAgB,SAAS,CAAC,CAAW;IACnC,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC;AACvC,CAAC;AAFD,8BAEC;AAED;;;;;;GAMG;AACH,SAAgB,OAAO,CACrB,IAAY,EACZ,CAAW;IAEX,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QACjB,MAAM,IAAI,wBAAe,CAAC,GAAG,IAAI,+BAA+B,CAAC,CAAC;KACnE;AACH,CAAC;AAPD,0BAOC;AAED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IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACpC,OAAO,KAAK,CAAC;KACd;IACD,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACtC,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,IAAY,EACZ,OAAgC,EAChC,KAAe;IAEf,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KACtB;SAAM,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE;QAChD,OAAO;KACR;IACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QACpB,MAAM,IAAI,eAAe,CAAC,GAAG,IAAI,mBAAmB,CAAC,CAAC;KACvD;IACD,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC/D,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC1C,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACpC,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import {ValidationError} from '../errors';\n\n/**\n * Tests if a value is null or undefined.\n *\n * @param o the value to check\n */\nexport function isNotNull(o?: unknown): o is NonNullable<unknown> {\n return o !== undefined && o !== null;\n}\n\n/**\n * Throws a ValidationError if the value is null or undefined.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notNull(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotNull(o)) {\n throw new ValidationError(`${name} may not be null or undefined`);\n }\n}\n\n/**\n * Tests if a value is empty, null, undefined or has a length of 0.\n *\n * @param o the value to check\n */\nexport function isNotEmpty(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined or the length is 0.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notEmpty(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotEmpty(o)) {\n throw new ValidationError(`${name} may not be empty`);\n }\n}\n\n/**\n * Tests if a value is null, undefined, has a length of 0 or contains only whitespace.\n *\n * @param o the value to check\n */\nexport function isNotBlank(o?: unknown): o is NonNullable<unknown> {\n return !(o === undefined || o === null || o.toString().trim().length === 0);\n}\n\n/**\n * Throws a ValidationError if the value is null, undefined, has a length of 0 or contains only whitespace.\n * This function also asserts the value to be NonNullable if the check passes.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function notBlank(\n name: string,\n o?: unknown\n): asserts o is NonNullable<unknown> {\n if (!isNotBlank(o)) {\n throw new ValidationError(`${name} may not be blank`);\n }\n}\n\n/**\n * Tests if a value does not match the regular expression provided.\n * Undefined and null values are skipped and not tested.\n *\n * @param regex the regular expression to test with\n * @param o the value to check\n */\nexport function isMatch(regex: RegExp, o?: string | null): o is string {\n if (o === undefined || o === null) {\n return true;\n }\n return o.match(regex) !== null;\n}\n\n/**\n * Throws a ValidationError if the value matches the regular expression provided.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param regex the regular expression to validate with\n * @param o the value to check\n */\nexport function match(name: string, regex: RegExp, o?: string | null) {\n if (!isMatch(regex, o)) {\n throw new ValidationError(`${name} must match ${regex}`);\n }\n}\n\n/**\n * Tests if a value is a valid email address.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isEmail(o?: string | null): o is string {\n const expression =\n /^(?=.{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])?)*$/;\n return !(o !== undefined && o !== null && !expression.test(o));\n}\n\n/**\n * Throws a ValidationError if the value provided is not an email.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function email(name: string, o?: string | null) {\n if (!isEmail(o)) {\n throw new ValidationError(`${name} is not a valid email address`);\n }\n}\n\n/**\n * Tests if a value has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function isMaxLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length > length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that exceeds the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the maximum length of the variable\n * @param o the value to check\n */\nexport function maxLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMaxLength(length, o)) {\n throw new ValidationError(`length of ${name} may not exceed ${length}`);\n }\n}\n\n/**\n * Tests if a value has a length that is greater than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function isMinLength(length: number, o?: string | unknown[] | null) {\n return !(o !== undefined && o !== null && o.length < length);\n}\n\n/**\n * Throws a ValidationError if the value provided has a length that is less than the provided length.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param length the minimum length of the variable\n * @param o the value to check\n */\nexport function minLength(\n name: string,\n length: number,\n o?: string | unknown[] | null\n) {\n if (!isMinLength(length, o)) {\n throw new ValidationError(\n `length of ${name} may not be less than ${length}`\n );\n }\n}\n\n/**\n * Tests if a value provided is a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param o the value to check\n */\nexport function isNumber(o?: string | null | number): boolean {\n return o === undefined || o === null || !isNaN(+o);\n}\n\n/**\n * Throws a ValidationError if the value provided is not a number.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param o the value to check\n */\nexport function number(name: string, o?: string | null | number) {\n if (!isNumber(o)) {\n throw new ValidationError(`${name} is not a number`);\n }\n}\n\n/**\n * Tests if a value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function isMinValue(minValue: number, o?: string | number | null) {\n return o === undefined || o === null || +o >= minValue;\n}\n\n/**\n * Throws a ValidationError if the value is less than the provided minimum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param o the value to check\n */\nexport function minValue(\n name: string,\n minValue: number,\n o?: number | string | null\n) {\n if (!isMinValue(minValue, o)) {\n throw new ValidationError(`${name} may not be less than ${minValue}`);\n }\n}\n\n/**\n * Tests if a value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isMaxValue(\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && +o > maxValue);\n}\n\n/**\n * Throws a ValidationError if the value is more than the provided maximum value.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function maxValue(\n name: string,\n maxValue: number,\n o?: number | string | null\n) {\n if (!isMaxValue(maxValue, o)) {\n throw new ValidationError(`${name} may not be greater than ${maxValue}`);\n }\n}\n\n/**\n * Tests if the value is between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function isBetweenValues(\n minValue: number,\n maxValue: number,\n o?: string | number | null\n): boolean {\n return !(o !== undefined && o !== null && (+o < minValue || +o > maxValue));\n}\n\n/**\n * Throws a ValidationError if the value is not between the provided minimum and maximum values inclusive.\n * Undefined and null values are skipped and not validated.\n *\n * @param name the name of the variable\n * @param minValue the minimum value allowed\n * @param maxValue the maximum value allowed\n * @param o the value to check\n */\nexport function betweenValues(\n name: string,\n minValue: number,\n maxValue: number,\n o?: string | number | null\n) {\n if (!isBetweenValues(minValue, maxValue, o)) {\n throw new ValidationError(\n `${name} must be between ${minValue} and ${maxValue}`\n );\n }\n}\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\nexport interface StringValidationOptions {\n readonly required: boolean;\n readonly minLength?: number;\n readonly maxLength?: number;\n readonly regex?: RegExp;\n readonly notBlank?: boolean;\n readonly notEmpty?: boolean;\n readonly email?: boolean;\n readonly number?: boolean;\n}\n\nexport function isValidString(\n options: StringValidationOptions,\n value?: unknown\n): value is string {\n if (options.required) {\n if (!isNotNull(value)) {\n return false;\n }\n } else if (value === undefined || value === null) {\n return true;\n }\n if (!isString(value)) {\n return false;\n }\n if (options.minLength && !isMinLength(options.minLength, value)) {\n return false;\n }\n if (options.maxLength && !isMaxLength(options.maxLength, value)) {\n return false;\n }\n if (options.regex && !isMatch(options.regex, value)) {\n return false;\n }\n if (options.notBlank && !isNotBlank(value)) {\n return false;\n }\n if (options.notEmpty && !isNotEmpty(value)) {\n return false;\n }\n if (options.email && !isEmail(value)) {\n return false;\n }\n if (options.number && !isNumber(value)) {\n return false;\n }\n return true;\n}\n\nexport function validString(\n name: string,\n options: StringValidationOptions,\n value?: unknown\n): void {\n if (options.required) {\n notNull(name, value);\n } else if (value === undefined || value === null) {\n return;\n }\n if (!isString(value)) {\n throw new ValidationError(`${name} must be a string`);\n }\n options.minLength && minLength(name, options.minLength, value);\n options.maxLength && maxLength(name, options.maxLength, value);\n options.regex && match(name, options.regex, value);\n options.notBlank && notBlank(name, value);\n options.notEmpty && notEmpty(name, value);\n options.email && email(name, value);\n options.number && number(name, value);\n}\n"]}
package/.prettierrc.js DELETED
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- ...require('gts/.prettierrc.json'),
3
- };
package/LICENSE DELETED
@@ -1,26 +0,0 @@
1
- Copyright 2023-2024 NR1E, Inc.
2
-
3
- Redistribution and use in source and binary forms, with or without
4
- modification, are permitted provided that the following conditions are met:
5
-
6
- 1. Redistributions of source code must retain the above copyright notice, this
7
- list of conditions and the following disclaimer.
8
-
9
- 2. Redistributions in binary form must reproduce the above copyright notice,
10
- this list of conditions and the following disclaimer in the documentation
11
- and/or other materials provided with the distribution.
12
-
13
- 3. Neither the name of the copyright holder nor the names of its contributors
14
- may be used to endorse or promote products derived from this software without
15
- specific prior written permission.
16
-
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md DELETED
@@ -1,14 +0,0 @@
1
- # Commons JS
2
-
3
- [![NPM Version][npm-image]][npm-url]
4
- [![TypeScript Style Guide][gts-image]][gts-url]
5
- [![GitHub Actions][github-image]][github-url]
6
-
7
- This project provides reusable components commonly needed in typescript projects.
8
-
9
- [github-url]: https://github.com/nr1etech/commons-js/actions
10
- [github-image]: https://github.com/nr1etech/commons-js/workflows/ci/badge.svg
11
- [npm-url]: https://npmjs.org/package/@nr1e/commons-js
12
- [npm-image]: https://img.shields.io/npm/v/@nre1/commons-js.svg
13
- [gts-image]: https://img.shields.io/badge/code%20style-google-blueviolet.svg
14
- [gts-url]: https://github.com/google/gts
package/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * as validator from './validator';
2
- export * as errors from './errors';
3
- export * as http from './http';
4
- export * as lang from './lang';
5
- export * as bitsnbytes from './bitsnbytes';
package/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.bitsnbytes = exports.lang = exports.http = exports.errors = exports.validator = void 0;
4
- exports.validator = require("./validator");
5
- exports.errors = require("./errors");
6
- exports.http = require("./http");
7
- exports.lang = require("./lang");
8
- exports.bitsnbytes = require("./bitsnbytes");
9
- //# sourceMappingURL=index.js.map
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AACzC,qCAAmC;AACnC,iCAA+B;AAC/B,iCAA+B;AAC/B,6CAA2C"}
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- testEnvironment: 'node',
3
- roots: ['<rootDir>'],
4
- testMatch: ['**/*.test.ts'],
5
- transform: {
6
- '^.+\\.tsx?$': 'ts-jest',
7
- },
8
- };