shelving 1.185.1 → 1.185.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/package.json +1 -1
- package/schema/ChoiceSchema.d.ts +1 -1
- package/schema/ChoiceSchema.js +3 -3
- package/schema/DateSchema.d.ts +1 -1
- package/schema/DateSchema.js +6 -6
- package/schema/FileSchema.js +2 -2
- package/schema/NumberSchema.d.ts +3 -3
- package/schema/NumberSchema.js +16 -17
- package/schema/StringSchema.d.ts +2 -2
- package/schema/StringSchema.js +13 -13
- package/schema/URISchema.js +2 -2
- package/schema/URLSchema.js +2 -2
package/package.json
CHANGED
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOption
|
|
|
20
20
|
}
|
|
21
21
|
/** Choose from an allowed set of values. */
|
|
22
22
|
export declare class ChoiceSchema<K extends string> extends Schema<K> implements Iterable<ChoiceOption<K>> {
|
|
23
|
-
readonly value: K;
|
|
23
|
+
readonly value: K | undefined;
|
|
24
24
|
readonly options: ChoiceOptions<K>;
|
|
25
25
|
constructor({ one, title, placeholder, options, value, ...rest }: ChoiceSchemaOptions<K>);
|
|
26
26
|
validate(unsafeValue?: unknown): K;
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isArray
|
|
1
|
+
import { isArray } from "../util/array.js";
|
|
2
2
|
import { getKeys, getProps, isProp } from "../util/object.js";
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Get the options for a choice field as an array. */
|
|
@@ -19,14 +19,14 @@ export function isOption(options, option) {
|
|
|
19
19
|
/** Choose from an allowed set of values. */
|
|
20
20
|
export class ChoiceSchema extends Schema {
|
|
21
21
|
options;
|
|
22
|
-
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value
|
|
22
|
+
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value, ...rest }) {
|
|
23
23
|
super({ one, title, value, placeholder, ...rest });
|
|
24
24
|
this.options = options;
|
|
25
25
|
}
|
|
26
26
|
validate(unsafeValue = this.value) {
|
|
27
27
|
if (typeof unsafeValue === "string" && isOption(this.options, unsafeValue))
|
|
28
28
|
return unsafeValue;
|
|
29
|
-
throw
|
|
29
|
+
throw unsafeValue ? `Unknown ${this.one}` : "Required";
|
|
30
30
|
}
|
|
31
31
|
// Implement iterable.
|
|
32
32
|
*[Symbol.iterator]() {
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface DateSchemaOptions extends SchemaOptions {
|
|
|
18
18
|
readonly step?: number | undefined;
|
|
19
19
|
}
|
|
20
20
|
export declare class DateSchema extends Schema<string> {
|
|
21
|
-
readonly value: PossibleDate;
|
|
21
|
+
readonly value: PossibleDate | undefined;
|
|
22
22
|
readonly min: Date | undefined;
|
|
23
23
|
readonly max: Date | undefined;
|
|
24
24
|
readonly input: DateInputType;
|
package/schema/DateSchema.js
CHANGED
|
@@ -8,7 +8,7 @@ export class DateSchema extends Schema {
|
|
|
8
8
|
max;
|
|
9
9
|
input;
|
|
10
10
|
step;
|
|
11
|
-
constructor({ one = "date", min, max, value
|
|
11
|
+
constructor({ one = "date", min, max, value, input = "date", step, ...options }) {
|
|
12
12
|
super({ one, title: "Date", value, ...options });
|
|
13
13
|
this.min = getDate(min);
|
|
14
14
|
this.max = getDate(max);
|
|
@@ -18,13 +18,13 @@ export class DateSchema extends Schema {
|
|
|
18
18
|
validate(value = this.value) {
|
|
19
19
|
const date = getDate(value);
|
|
20
20
|
if (!date)
|
|
21
|
-
throw value ?
|
|
22
|
-
const
|
|
23
|
-
if (this.min &&
|
|
21
|
+
throw value ? `Invalid ${this.one} format` : "Required";
|
|
22
|
+
const stepped = typeof this.step === "number" ? new Date(roundStep(date.getTime(), this.step)) : date;
|
|
23
|
+
if (this.min && stepped < this.min)
|
|
24
24
|
throw `Minimum ${this.format(this.min)}`;
|
|
25
|
-
if (this.max &&
|
|
25
|
+
if (this.max && stepped > this.max)
|
|
26
26
|
throw `Maximum ${this.format(this.max)}`;
|
|
27
|
-
return this.stringify(
|
|
27
|
+
return this.stringify(stepped);
|
|
28
28
|
}
|
|
29
29
|
stringify(value) {
|
|
30
30
|
return requireDateString(value);
|
package/schema/FileSchema.js
CHANGED
|
@@ -13,9 +13,9 @@ export class FileSchema extends StringSchema {
|
|
|
13
13
|
const path = super.validate(unsafeValue);
|
|
14
14
|
const extension = getFileExtension(path);
|
|
15
15
|
if (!extension)
|
|
16
|
-
throw
|
|
16
|
+
throw `Must have extension`;
|
|
17
17
|
if (this.types && !isProp(this.types, extension))
|
|
18
|
-
throw
|
|
18
|
+
throw `Invalid extension`;
|
|
19
19
|
return path;
|
|
20
20
|
}
|
|
21
21
|
}
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ export interface NumberSchemaOptions extends SchemaOptions {
|
|
|
9
9
|
}
|
|
10
10
|
/** Schema that defines a valid number. */
|
|
11
11
|
export declare class NumberSchema extends Schema<number> {
|
|
12
|
-
readonly value: number;
|
|
12
|
+
readonly value: number | undefined;
|
|
13
13
|
readonly min: number;
|
|
14
14
|
readonly max: number;
|
|
15
15
|
readonly step: number | undefined;
|
|
16
16
|
constructor({ one, title, min, max, step, value, ...options }: NumberSchemaOptions);
|
|
17
|
-
validate(
|
|
17
|
+
validate(value?: unknown): number;
|
|
18
18
|
}
|
|
19
|
-
/** Valid number, e.g. `2048.12345` or `0` zero. */
|
|
19
|
+
/** Valid number, e.g. `2048.12345` or `0` zero and a default value of zero. */
|
|
20
20
|
export declare const NUMBER: NumberSchema;
|
|
21
21
|
/** Valid optional number, e.g. `2048.12345` or `0` zero, or `null` */
|
|
22
22
|
export declare const NULLABLE_NUMBER: import("./NullableSchema.js").NullableSchema<number>;
|
package/schema/NumberSchema.js
CHANGED
|
@@ -7,38 +7,38 @@ export class NumberSchema extends Schema {
|
|
|
7
7
|
min;
|
|
8
8
|
max;
|
|
9
9
|
step;
|
|
10
|
-
constructor({ one = "number", title = "Number", min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step, value
|
|
10
|
+
constructor({ one = "number", title = "Number", min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step, value, ...options }) {
|
|
11
11
|
super({ one, title, value, ...options });
|
|
12
12
|
this.min = min;
|
|
13
13
|
this.max = max;
|
|
14
14
|
this.step = step;
|
|
15
15
|
}
|
|
16
|
-
validate(
|
|
17
|
-
const
|
|
18
|
-
if (typeof
|
|
19
|
-
throw
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
throw !
|
|
23
|
-
if (
|
|
16
|
+
validate(value = this.value) {
|
|
17
|
+
const number = getNumber(value);
|
|
18
|
+
if (typeof number !== "number")
|
|
19
|
+
throw value ? `Must be ${this.one}` : "Required";
|
|
20
|
+
const stepped = typeof this.step === "number" ? roundStep(number, this.step) : number;
|
|
21
|
+
if (stepped < this.min)
|
|
22
|
+
throw !number ? "Required" : `Minimum ${formatNumber(this.min)}`;
|
|
23
|
+
if (stepped > this.max)
|
|
24
24
|
throw `Maximum ${formatNumber(this.max)}`;
|
|
25
|
-
return
|
|
25
|
+
return stepped;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/** Valid number, e.g. `2048.12345` or `0` zero. */
|
|
28
|
+
/** Valid number, e.g. `2048.12345` or `0` zero and a default value of zero. */
|
|
29
29
|
export const NUMBER = new NumberSchema({ title: "Number" });
|
|
30
30
|
/** Valid optional number, e.g. `2048.12345` or `0` zero, or `null` */
|
|
31
31
|
export const NULLABLE_NUMBER = NULLABLE(NUMBER);
|
|
32
32
|
/** Valid integer number, e.g. `2048` or `0` zero. */
|
|
33
|
-
export const INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER
|
|
33
|
+
export const INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: Number.MAX_SAFE_INTEGER });
|
|
34
34
|
/** Valid positive integer number, e.g. `1,2,3` (not including zero). */
|
|
35
|
-
export const POSITIVE_INTEGER = new NumberSchema({ step: 1, min: 1, max: Number.MAX_SAFE_INTEGER
|
|
35
|
+
export const POSITIVE_INTEGER = new NumberSchema({ step: 1, min: 1, max: Number.MAX_SAFE_INTEGER });
|
|
36
36
|
/** Valid non-negative integer number, e.g. `0,1,2,3` (including zero). */
|
|
37
|
-
export const NON_NEGATIVE_INTEGER = new NumberSchema({ step: 1, min: 0, max: Number.MAX_SAFE_INTEGER
|
|
37
|
+
export const NON_NEGATIVE_INTEGER = new NumberSchema({ step: 1, min: 0, max: Number.MAX_SAFE_INTEGER });
|
|
38
38
|
/** Valid negative integer number, e.g. `-1,-2,-3` (not including zero). */
|
|
39
|
-
export const NEGATIVE_INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: -1
|
|
39
|
+
export const NEGATIVE_INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: -1 });
|
|
40
40
|
/** Valid non-positive integer number, e.g. `0,-1,-2,-3` (including zero). */
|
|
41
|
-
export const NON_POSITIVE_INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: 0
|
|
41
|
+
export const NON_POSITIVE_INTEGER = new NumberSchema({ step: 1, min: Number.MIN_SAFE_INTEGER, max: 0 });
|
|
42
42
|
/** Valid optional integer number, e.g. `2048` or `0` zero, or `null` */
|
|
43
43
|
export const NULLABLE_INTEGER = NULLABLE(INTEGER);
|
|
44
44
|
/** Valid Unix timestamp (including milliseconds). */
|
|
@@ -47,7 +47,6 @@ export const TIMESTAMP = new NumberSchema({
|
|
|
47
47
|
step: 1,
|
|
48
48
|
min: Number.MIN_SAFE_INTEGER,
|
|
49
49
|
max: Number.MAX_SAFE_INTEGER,
|
|
50
|
-
value: 0,
|
|
51
50
|
});
|
|
52
51
|
/** Valid Unix timestamp (including milliseconds). */
|
|
53
52
|
export const NULLABLE_TIMESTAMP = NULLABLE_INTEGER;
|
package/schema/StringSchema.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ export declare class StringSchema extends Schema<string> {
|
|
|
35
35
|
readonly multiline: boolean;
|
|
36
36
|
readonly match: RegExp | undefined;
|
|
37
37
|
readonly case: "upper" | "lower" | undefined;
|
|
38
|
-
constructor({ min, max, value, multiline, match, case: _case, input, ...options }: StringSchemaOptions);
|
|
39
|
-
validate(
|
|
38
|
+
constructor({ one, min, max, value, multiline, match, case: _case, input, ...options }: StringSchemaOptions);
|
|
39
|
+
validate(value?: unknown): string;
|
|
40
40
|
/** Sanitize the string by removing unwanted characters. */
|
|
41
41
|
sanitize(str: string): string;
|
|
42
42
|
}
|
package/schema/StringSchema.js
CHANGED
|
@@ -23,8 +23,8 @@ export class StringSchema extends Schema {
|
|
|
23
23
|
multiline;
|
|
24
24
|
match;
|
|
25
25
|
case;
|
|
26
|
-
constructor({ min = 0, max = Number.POSITIVE_INFINITY, value = "", multiline = false, match, case: _case, input = "text", ...options }) {
|
|
27
|
-
super({ value, ...options });
|
|
26
|
+
constructor({ one = "string", min = 0, max = Number.POSITIVE_INFINITY, value = "", multiline = false, match, case: _case, input = "text", ...options }) {
|
|
27
|
+
super({ one, value, ...options });
|
|
28
28
|
this.min = min;
|
|
29
29
|
this.max = max;
|
|
30
30
|
this.multiline = multiline;
|
|
@@ -32,18 +32,18 @@ export class StringSchema extends Schema {
|
|
|
32
32
|
this.case = _case;
|
|
33
33
|
this.input = input;
|
|
34
34
|
}
|
|
35
|
-
validate(
|
|
36
|
-
const
|
|
37
|
-
if (typeof
|
|
38
|
-
throw
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
41
|
-
throw
|
|
42
|
-
if (
|
|
35
|
+
validate(value = this.value) {
|
|
36
|
+
const str = typeof value === "number" ? value.toString() : value;
|
|
37
|
+
if (typeof str !== "string")
|
|
38
|
+
throw value ? `Must be ${this.one}` : "Required";
|
|
39
|
+
const sane = this.sanitize(str);
|
|
40
|
+
if (this.match && !this.match.test(sane))
|
|
41
|
+
throw str.length ? `Invalid ${this.one}` : "Required";
|
|
42
|
+
if (sane.length < this.min)
|
|
43
|
+
throw str.length ? `Minimum ${this.min} characters` : "Required";
|
|
44
|
+
if (sane.length > this.max)
|
|
43
45
|
throw `Maximum ${this.max} characters`;
|
|
44
|
-
|
|
45
|
-
throw saneString ? "Invalid format" : "Required";
|
|
46
|
-
return saneString;
|
|
46
|
+
return sane;
|
|
47
47
|
}
|
|
48
48
|
/** Sanitize the string by removing unwanted characters. */
|
|
49
49
|
sanitize(str) {
|
package/schema/URISchema.js
CHANGED
|
@@ -25,9 +25,9 @@ export class URISchema extends StringSchema {
|
|
|
25
25
|
const str = super.validate(unsafeValue);
|
|
26
26
|
const uri = getURI(str);
|
|
27
27
|
if (!uri)
|
|
28
|
-
throw str ?
|
|
28
|
+
throw str ? `Invalid ${this.one} format` : "Required";
|
|
29
29
|
if (this.schemes && !this.schemes.includes(uri.protocol))
|
|
30
|
-
throw
|
|
30
|
+
throw `Invalid ${this.one} scheme`;
|
|
31
31
|
return uri.href;
|
|
32
32
|
}
|
|
33
33
|
}
|
package/schema/URLSchema.js
CHANGED
|
@@ -28,9 +28,9 @@ export class URLSchema extends StringSchema {
|
|
|
28
28
|
const str = super.validate(unsafeValue);
|
|
29
29
|
const url = getURL(str, this.base);
|
|
30
30
|
if (!url)
|
|
31
|
-
throw str ?
|
|
31
|
+
throw str ? `Invalid ${this.one} format` : "Required";
|
|
32
32
|
if (this.schemes && !this.schemes.includes(url.protocol))
|
|
33
|
-
throw
|
|
33
|
+
throw `Invalid ${this.one} scheme`;
|
|
34
34
|
return url.href;
|
|
35
35
|
}
|
|
36
36
|
}
|