valgen 4.0.0 → 4.0.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # v4.0.1
2
+ [2023-10-24]
3
+
4
+ ### Changes
5
+
6
+ * Added "coerce" option to isNull and isUndefined rules ([`8c02040`](https://github.com/panates/valgen/commit/8c02040264174e26c840fce351da8b69e664d626))
7
+
1
8
  # v4.0.0
2
9
  [2023-08-17]
3
10
 
@@ -8,6 +8,8 @@ const index_js_1 = require("../core/index.js");
8
8
  */
9
9
  function isNull(options) {
10
10
  return (0, index_js_1.validator)('isNull', function (input, context, _this) {
11
+ if (context.coerce)
12
+ return null;
11
13
  if (input === null)
12
14
  return input;
13
15
  context.fail(_this, `{{label}} is not null`, input);
@@ -28,10 +30,12 @@ function isDefined(options) {
28
30
  exports.isDefined = isDefined;
29
31
  /**
30
32
  * Validates if value is "undefined"
31
- * @validator isNotDefined
33
+ * @validator isUndefined
32
34
  */
33
35
  function isUndefined(options) {
34
36
  return (0, index_js_1.validator)('isUndefined', function (input, context, _this) {
37
+ if (context.coerce)
38
+ return undefined;
35
39
  if (input === undefined)
36
40
  return;
37
41
  context.fail(_this, `{{label}} defined`, input);
@@ -5,6 +5,8 @@ import { validator } from '../core/index.js';
5
5
  */
6
6
  export function isNull(options) {
7
7
  return validator('isNull', function (input, context, _this) {
8
+ if (context.coerce)
9
+ return null;
8
10
  if (input === null)
9
11
  return input;
10
12
  context.fail(_this, `{{label}} is not null`, input);
@@ -23,10 +25,12 @@ export function isDefined(options) {
23
25
  }
24
26
  /**
25
27
  * Validates if value is "undefined"
26
- * @validator isNotDefined
28
+ * @validator isUndefined
27
29
  */
28
30
  export function isUndefined(options) {
29
31
  return validator('isUndefined', function (input, context, _this) {
32
+ if (context.coerce)
33
+ return undefined;
30
34
  if (input === undefined)
31
35
  return;
32
36
  context.fail(_this, `{{label}} defined`, input);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "valgen",
3
3
  "description": "Fast runtime type validator, converter and io (encoding/decoding) library",
4
- "version": "4.0.0",
4
+ "version": "4.0.1",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -12,9 +12,9 @@
12
12
  "url": "https://github.com/panates/valgen.git"
13
13
  },
14
14
  "dependencies": {
15
- "@types/validator": "^13.11.1",
15
+ "@types/validator": "^13.11.5",
16
16
  "dayjs": "^2.0.0-alpha.4",
17
- "ts-gems": "^2.4.1",
17
+ "ts-gems": "^2.5.0",
18
18
  "validator": "^13.11.0"
19
19
  },
20
20
  "type": "module",
@@ -11,6 +11,6 @@ export declare function isNull(options?: ValidationOptions): import("../core/val
11
11
  export declare function isDefined(options?: ValidationOptions): import("../core/validator.js").Validator<any, unknown, import("../core/types.js").ExecutionOptions>;
12
12
  /**
13
13
  * Validates if value is "undefined"
14
- * @validator isNotDefined
14
+ * @validator isUndefined
15
15
  */
16
16
  export declare function isUndefined(options?: ValidationOptions): import("../core/validator.js").Validator<any, unknown, import("../core/types.js").ExecutionOptions>;