valgen 4.2.1 → 4.2.3

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,17 @@
1
+ # v4.2.3
2
+ [2023-11-20]
3
+
4
+ ### Changes
5
+
6
+ * Optimized error messages ([`21e29dc`](https://github.com/panates/valgen/commit/21e29dc2eff846fbeccb7737ffe41496bca583c5))
7
+
8
+ # v4.2.2
9
+ [2023-11-15]
10
+
11
+ ### Changes
12
+
13
+ * Changed "trim" option ([`b5eff4f`](https://github.com/panates/valgen/commit/b5eff4ffd61eb78ea244dfe2c66ca86275b9578c))
14
+
1
15
  # v4.2.1
2
16
  [2023-11-15]
3
17
 
@@ -51,8 +51,8 @@ class Context {
51
51
  return x;
52
52
  const k = m[1];
53
53
  let v = issue[k];
54
- if (!v && m[1] === 'label' && (this.label || this.property))
55
- v = '`' + (this.label || this.property) + '`';
54
+ if (!v && m[1] === 'label' && (this.location || this.property))
55
+ v = '`' + (this.location || this.property) + '`';
56
56
  if (v != null)
57
57
  return v;
58
58
  if (m[2])
@@ -17,7 +17,7 @@ function isArray(itemValidator, options) {
17
17
  }
18
18
  if (!itemValidator)
19
19
  return input;
20
- const location = context.location || '';
20
+ // const location = context.location || '';
21
21
  const itemContext = context.extend();
22
22
  let i;
23
23
  let v;
@@ -26,10 +26,10 @@ function isArray(itemValidator, options) {
26
26
  for (i = 0; i < l; i++) {
27
27
  v = input[i];
28
28
  itemContext.scope = input;
29
- itemContext.location = location + '[' + i + ']';
30
- itemContext.label = context.label
29
+ // itemContext.location = location + '[' + i + ']';
30
+ itemContext.location = context.label
31
31
  ? context.label + `[${i}]`
32
- : `Item at (${i})`;
32
+ : `<Array>[${i}]`;
33
33
  itemContext.index = i;
34
34
  v = itemValidator(v, itemContext);
35
35
  out.push(v);
@@ -74,10 +74,10 @@ function isDateString(options) {
74
74
  s += '-' + m[3];
75
75
  else
76
76
  return s;
77
- if (trim === 'time' || !m[4])
77
+ if (trim === 'date' || !m[4])
78
78
  return s;
79
79
  s += 'T' + m[4];
80
- if (trim === 'timezone')
80
+ if (trim === 'time')
81
81
  return s;
82
82
  if (m[9])
83
83
  s += m[9];
@@ -89,13 +89,9 @@ function isDateString(options) {
89
89
  else if (input != null) {
90
90
  const d = (0, dayjs_1.default)(input);
91
91
  if (d.isValid()) {
92
- if (!context.coerce)
93
- return input;
94
- if (trim === 'timezone')
95
- return d.millisecond() ? d.format('YYYY-MM-DDTHH:mm:ss.SSS') : d.format('YYYY-MM-DDTHH:mm:ss');
96
- if (trim === 'time')
92
+ if (trim === 'date')
97
93
  return d.format('YYYY-MM-DD');
98
- return d.toISOString();
94
+ return d.millisecond() ? d.format('YYYY-MM-DDTHH:mm:ss.SSS') : d.format('YYYY-MM-DDTHH:mm:ss');
99
95
  }
100
96
  }
101
97
  context.fail(_this, `{{label}} is not a valid date string`, input, { ...options });
@@ -48,8 +48,8 @@ export class Context {
48
48
  return x;
49
49
  const k = m[1];
50
50
  let v = issue[k];
51
- if (!v && m[1] === 'label' && (this.label || this.property))
52
- v = '`' + (this.label || this.property) + '`';
51
+ if (!v && m[1] === 'label' && (this.location || this.property))
52
+ v = '`' + (this.location || this.property) + '`';
53
53
  if (v != null)
54
54
  return v;
55
55
  if (m[2])
@@ -14,7 +14,7 @@ export function isArray(itemValidator, options) {
14
14
  }
15
15
  if (!itemValidator)
16
16
  return input;
17
- const location = context.location || '';
17
+ // const location = context.location || '';
18
18
  const itemContext = context.extend();
19
19
  let i;
20
20
  let v;
@@ -23,10 +23,10 @@ export function isArray(itemValidator, options) {
23
23
  for (i = 0; i < l; i++) {
24
24
  v = input[i];
25
25
  itemContext.scope = input;
26
- itemContext.location = location + '[' + i + ']';
27
- itemContext.label = context.label
26
+ // itemContext.location = location + '[' + i + ']';
27
+ itemContext.location = context.label
28
28
  ? context.label + `[${i}]`
29
- : `Item at (${i})`;
29
+ : `<Array>[${i}]`;
30
30
  itemContext.index = i;
31
31
  v = itemValidator(v, itemContext);
32
32
  out.push(v);
@@ -67,10 +67,10 @@ export function isDateString(options) {
67
67
  s += '-' + m[3];
68
68
  else
69
69
  return s;
70
- if (trim === 'time' || !m[4])
70
+ if (trim === 'date' || !m[4])
71
71
  return s;
72
72
  s += 'T' + m[4];
73
- if (trim === 'timezone')
73
+ if (trim === 'time')
74
74
  return s;
75
75
  if (m[9])
76
76
  s += m[9];
@@ -82,13 +82,9 @@ export function isDateString(options) {
82
82
  else if (input != null) {
83
83
  const d = dayjs(input);
84
84
  if (d.isValid()) {
85
- if (!context.coerce)
86
- return input;
87
- if (trim === 'timezone')
88
- return d.millisecond() ? d.format('YYYY-MM-DDTHH:mm:ss.SSS') : d.format('YYYY-MM-DDTHH:mm:ss');
89
- if (trim === 'time')
85
+ if (trim === 'date')
90
86
  return d.format('YYYY-MM-DD');
91
- return d.toISOString();
87
+ return d.millisecond() ? d.format('YYYY-MM-DDTHH:mm:ss.SSS') : d.format('YYYY-MM-DDTHH:mm:ss');
92
88
  }
93
89
  }
94
90
  context.fail(_this, `{{label}} is not a valid date string`, input, { ...options });
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.2.1",
4
+ "version": "4.2.3",
5
5
  "author": "Panates",
6
6
  "contributors": [
7
7
  "Eray Hanoglu <e.hanoglu@panates.com>"
@@ -10,7 +10,7 @@ export interface IsDateOptions extends ValidationOptions {
10
10
  export declare function isDate(options?: IsDateOptions): import("../core/validator.js").Validator<Date, string | number | Date, import("../core/types.js").ExecutionOptions>;
11
11
  export interface IsDateStringOptions extends ValidationOptions {
12
12
  precision?: 'year' | 'month' | 'date' | 'time';
13
- trim?: 'time' | 'timezone';
13
+ trim?: 'date' | 'time';
14
14
  }
15
15
  /**
16
16
  * Validates if value is DFS (date formatted string).