valgen 4.2.2 → 4.2.4
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 +14 -0
- package/cjs/core/context.js +2 -2
- package/cjs/rules/is-array.js +4 -4
- package/cjs/rules/is-object.js +2 -0
- package/esm/core/context.js +2 -2
- package/esm/rules/is-array.js +4 -4
- package/esm/rules/is-object.js +2 -0
- package/package.json +1 -1
- package/typings/rules/is-object.d.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# v4.2.4
|
|
2
|
+
[2023-11-20]
|
|
3
|
+
|
|
4
|
+
### Changes
|
|
5
|
+
|
|
6
|
+
* Added json parsing feature to isObject validator ([`0cd128a`](https://github.com/panates/valgen/commit/0cd128ab8bae6e834230004c4b7bf857ce67b76f))
|
|
7
|
+
|
|
8
|
+
# v4.2.3
|
|
9
|
+
[2023-11-20]
|
|
10
|
+
|
|
11
|
+
### Changes
|
|
12
|
+
|
|
13
|
+
* Optimized error messages ([`21e29dc`](https://github.com/panates/valgen/commit/21e29dc2eff846fbeccb7737ffe41496bca583c5))
|
|
14
|
+
|
|
1
15
|
# v4.2.2
|
|
2
16
|
[2023-11-15]
|
|
3
17
|
|
package/cjs/core/context.js
CHANGED
|
@@ -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.
|
|
55
|
-
v = '`' + (this.
|
|
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])
|
package/cjs/rules/is-array.js
CHANGED
|
@@ -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.
|
|
29
|
+
// itemContext.location = location + '[' + i + ']';
|
|
30
|
+
itemContext.location = context.label
|
|
31
31
|
? context.label + `[${i}]`
|
|
32
|
-
:
|
|
32
|
+
: `<Array>[${i}]`;
|
|
33
33
|
itemContext.index = i;
|
|
34
34
|
v = itemValidator(v, itemContext);
|
|
35
35
|
out.push(v);
|
package/cjs/rules/is-object.js
CHANGED
|
@@ -32,6 +32,8 @@ function isObject(schema, options) {
|
|
|
32
32
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
33
33
|
});
|
|
34
34
|
const _rule = (0, index_js_1.validator)('isObject', function (input, context, _this) {
|
|
35
|
+
if (typeof input === 'string' && context.coerce)
|
|
36
|
+
input = JSON.parse(input);
|
|
35
37
|
if (!(input && typeof input === 'object')) {
|
|
36
38
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
37
39
|
return;
|
package/esm/core/context.js
CHANGED
|
@@ -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.
|
|
52
|
-
v = '`' + (this.
|
|
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])
|
package/esm/rules/is-array.js
CHANGED
|
@@ -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.
|
|
26
|
+
// itemContext.location = location + '[' + i + ']';
|
|
27
|
+
itemContext.location = context.label
|
|
28
28
|
? context.label + `[${i}]`
|
|
29
|
-
:
|
|
29
|
+
: `<Array>[${i}]`;
|
|
30
30
|
itemContext.index = i;
|
|
31
31
|
v = itemValidator(v, itemContext);
|
|
32
32
|
out.push(v);
|
package/esm/rules/is-object.js
CHANGED
|
@@ -29,6 +29,8 @@ export function isObject(schema, options) {
|
|
|
29
29
|
throw new TypeError(`Invalid definition in validation schema (${k})`);
|
|
30
30
|
});
|
|
31
31
|
const _rule = validator('isObject', function (input, context, _this) {
|
|
32
|
+
if (typeof input === 'string' && context.coerce)
|
|
33
|
+
input = JSON.parse(input);
|
|
32
34
|
if (!(input && typeof input === 'object')) {
|
|
33
35
|
context.fail(_this, `{{label}} must be an object`, input);
|
|
34
36
|
return;
|
package/package.json
CHANGED
|
@@ -19,4 +19,4 @@ export interface ObjectValidator<T extends object = object, I = object> extends
|
|
|
19
19
|
* Converts properties according to schema rules if coerce option is set to 'true'.
|
|
20
20
|
* @validator isObject
|
|
21
21
|
*/
|
|
22
|
-
export declare function isObject<T extends object = object, I = object>(schema: ObjectSchema, options?: IsObjectOptions<T>): ObjectValidator<T, I>;
|
|
22
|
+
export declare function isObject<T extends object = object, I = object | string>(schema: ObjectSchema, options?: IsObjectOptions<T>): ObjectValidator<T, I>;
|