shelving 1.159.2 → 1.159.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/package.json +1 -1
- package/schema/ArraySchema.d.ts +0 -4
- package/schema/ArraySchema.js +2 -6
- package/schema/ChoiceSchema.d.ts +1 -1
- package/schema/ChoiceSchema.js +2 -2
- package/schema/ColorSchema.d.ts +1 -1
- package/schema/ColorSchema.js +2 -1
- package/schema/DataSchema.d.ts +1 -1
- package/schema/DataSchema.js +2 -2
- package/schema/DateSchema.d.ts +1 -1
- package/schema/DateSchema.js +2 -2
- package/schema/DateTimeSchema.d.ts +1 -1
- package/schema/DateTimeSchema.js +2 -2
- package/schema/DictionarySchema.d.ts +0 -4
- package/schema/DictionarySchema.js +2 -6
- package/schema/EmailSchema.d.ts +1 -1
- package/schema/EmailSchema.js +2 -1
- package/schema/EntitySchema.d.ts +1 -1
- package/schema/EntitySchema.js +2 -2
- package/schema/FileSchema.d.ts +1 -1
- package/schema/FileSchema.js +2 -2
- package/schema/KeySchema.d.ts +1 -1
- package/schema/KeySchema.js +2 -2
- package/schema/LinkSchema.d.ts +2 -2
- package/schema/LinkSchema.js +2 -1
- package/schema/NumberSchema.d.ts +1 -1
- package/schema/NumberSchema.js +4 -4
- package/schema/PhoneSchema.d.ts +1 -1
- package/schema/PhoneSchema.js +2 -1
- package/schema/Schema.d.ts +12 -4
- package/schema/Schema.js +16 -2
- package/schema/TimeSchema.d.ts +1 -1
- package/schema/TimeSchema.js +2 -2
- package/schema/UUIDSchema.d.ts +1 -1
- package/schema/UUIDSchema.js +2 -2
package/package.json
CHANGED
package/schema/ArraySchema.d.ts
CHANGED
|
@@ -3,8 +3,6 @@ import type { SchemaOptions } from "./Schema.js";
|
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `ArraySchema` */
|
|
5
5
|
export interface ArraySchemaOptions<T> extends SchemaOptions {
|
|
6
|
-
readonly one?: string;
|
|
7
|
-
readonly many?: string;
|
|
8
6
|
readonly value?: ImmutableArray;
|
|
9
7
|
readonly items: Schema<T>;
|
|
10
8
|
readonly min?: number;
|
|
@@ -40,8 +38,6 @@ export interface ArraySchemaOptions<T> extends SchemaOptions {
|
|
|
40
38
|
*/
|
|
41
39
|
export declare class ArraySchema<T> extends Schema<ImmutableArray<T>> {
|
|
42
40
|
readonly value: ImmutableArray<T>;
|
|
43
|
-
readonly one: string;
|
|
44
|
-
readonly many: string;
|
|
45
41
|
readonly items: Schema<T>;
|
|
46
42
|
readonly unique: boolean;
|
|
47
43
|
readonly min: number;
|
package/schema/ArraySchema.js
CHANGED
|
@@ -30,16 +30,12 @@ import { Schema } from "./Schema.js";
|
|
|
30
30
|
* schema.validate(["a", null], schema); // Throws Invalids({ "1": Invalid('Must be a string') });
|
|
31
31
|
*/
|
|
32
32
|
export class ArraySchema extends Schema {
|
|
33
|
-
one;
|
|
34
|
-
many;
|
|
35
33
|
items;
|
|
36
34
|
unique;
|
|
37
35
|
min;
|
|
38
36
|
max;
|
|
39
|
-
constructor({ items, one =
|
|
40
|
-
super({ title, placeholder, value, ...options });
|
|
41
|
-
this.one = one;
|
|
42
|
-
this.many = many;
|
|
37
|
+
constructor({ items, one = items.one, many = items.many, title = "Items", placeholder = `No ${many}`, unique = false, min = 0, max = Number.POSITIVE_INFINITY, value = [], ...options }) {
|
|
38
|
+
super({ one, many, title, placeholder, value, ...options });
|
|
43
39
|
this.items = items;
|
|
44
40
|
this.unique = unique;
|
|
45
41
|
this.min = min;
|
package/schema/ChoiceSchema.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOption
|
|
|
22
22
|
export declare class ChoiceSchema<K extends string> extends Schema<K> implements Iterable<ChoiceOption<K>> {
|
|
23
23
|
readonly value: K;
|
|
24
24
|
readonly options: ChoiceOptions<K>;
|
|
25
|
-
constructor({
|
|
25
|
+
constructor({ one, title, placeholder, options, value, ...rest }: ChoiceSchemaOptions<K>);
|
|
26
26
|
validate(unsafeValue?: unknown): K;
|
|
27
27
|
[Symbol.iterator](): Iterator<ChoiceOption<K>>;
|
|
28
28
|
keys(): ImmutableArray<K>;
|
package/schema/ChoiceSchema.js
CHANGED
|
@@ -20,8 +20,8 @@ export function isOption(options, option) {
|
|
|
20
20
|
/** Choose from an allowed set of values. */
|
|
21
21
|
export class ChoiceSchema extends Schema {
|
|
22
22
|
options;
|
|
23
|
-
constructor({
|
|
24
|
-
super({ value, placeholder, ...rest });
|
|
23
|
+
constructor({ one = "choice", title = "Choice", placeholder = `No ${one}`, options, value = requireFirst(isArray(options) ? options : getKeys(options)), ...rest }) {
|
|
24
|
+
super({ one, title, value, placeholder, ...rest });
|
|
25
25
|
this.options = options;
|
|
26
26
|
}
|
|
27
27
|
validate(unsafeValue = this.value) {
|
package/schema/ColorSchema.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { StringSchema, type StringSchemaOptions } from "./StringSchema.js";
|
|
|
9
9
|
* Colors are limited to 512 characters (this can be changed with `max`), but generally these won't be data: URIs so this is a reasonable limit.
|
|
10
10
|
*/
|
|
11
11
|
export declare class ColorSchema extends StringSchema {
|
|
12
|
-
constructor({ title, value, ...options }: Omit<StringSchemaOptions, "type" | "min" | "max" | "
|
|
12
|
+
constructor({ one, title, value, ...options }: Omit<StringSchemaOptions, "type" | "min" | "max" | "match" | "multiline">);
|
|
13
13
|
sanitize(insaneString: string): string;
|
|
14
14
|
}
|
|
15
15
|
/** Valid color hex string, e.g. `#00CCFF` (required because empty string is invalid). */
|
package/schema/ColorSchema.js
CHANGED
|
@@ -12,8 +12,9 @@ const NOT_HEX_REGEXP = /[^0-9A-F]/g;
|
|
|
12
12
|
* Colors are limited to 512 characters (this can be changed with `max`), but generally these won't be data: URIs so this is a reasonable limit.
|
|
13
13
|
*/
|
|
14
14
|
export class ColorSchema extends StringSchema {
|
|
15
|
-
constructor({ title = "Color", value = "#000000", ...options }) {
|
|
15
|
+
constructor({ one = "color", title = "Color", value = "#000000", ...options }) {
|
|
16
16
|
super({
|
|
17
|
+
one,
|
|
17
18
|
title,
|
|
18
19
|
value,
|
|
19
20
|
...options,
|
package/schema/DataSchema.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface DataSchemaOptions<T extends Data> extends SchemaOptions {
|
|
|
13
13
|
export declare class DataSchema<T extends Data> extends Schema<unknown> {
|
|
14
14
|
readonly value: T;
|
|
15
15
|
readonly props: Schemas<T>;
|
|
16
|
-
constructor({
|
|
16
|
+
constructor({ one, title, props, value: partialValue, ...options }: DataSchemaOptions<T>);
|
|
17
17
|
validate(unsafeValue?: unknown): T;
|
|
18
18
|
}
|
|
19
19
|
/** Set of named data schemas. */
|
package/schema/DataSchema.js
CHANGED
|
@@ -8,10 +8,10 @@ import { Schema } from "./Schema.js";
|
|
|
8
8
|
/** Validate a data object. */
|
|
9
9
|
export class DataSchema extends Schema {
|
|
10
10
|
props;
|
|
11
|
-
constructor({
|
|
11
|
+
constructor({ one = "item", title = "Item", props, value: partialValue, ...options }) {
|
|
12
12
|
// Build default value from props and partial value.
|
|
13
13
|
const value = { ...mapProps(props, _getSchemaValue), ...partialValue };
|
|
14
|
-
super({ title, value, ...options });
|
|
14
|
+
super({ one, title, value, ...options });
|
|
15
15
|
this.props = props;
|
|
16
16
|
}
|
|
17
17
|
validate(unsafeValue = this.value) {
|
package/schema/DateSchema.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare class DateSchema extends Schema<string> {
|
|
|
23
23
|
readonly max: Date | undefined;
|
|
24
24
|
readonly input: DateInputType;
|
|
25
25
|
readonly step: number | undefined;
|
|
26
|
-
constructor({ min, max, value, input, step, ...options }: DateSchemaOptions);
|
|
26
|
+
constructor({ one, min, max, value, input, step, ...options }: DateSchemaOptions);
|
|
27
27
|
validate(value?: unknown): string;
|
|
28
28
|
stringify(value: Date): string;
|
|
29
29
|
format(value: Date): string;
|
package/schema/DateSchema.js
CHANGED
|
@@ -9,8 +9,8 @@ export class DateSchema extends Schema {
|
|
|
9
9
|
max;
|
|
10
10
|
input;
|
|
11
11
|
step;
|
|
12
|
-
constructor({ min, max, value = "now", input = "date", step, ...options }) {
|
|
13
|
-
super({ title: "Date", value, ...options });
|
|
12
|
+
constructor({ one = "date", min, max, value = "now", input = "date", step, ...options }) {
|
|
13
|
+
super({ one, title: "Date", value, ...options });
|
|
14
14
|
this.min = getDate(min);
|
|
15
15
|
this.max = getDate(max);
|
|
16
16
|
this.input = input;
|
|
@@ -6,7 +6,7 @@ import { DateSchema, type DateSchemaOptions } from "./DateSchema.js";
|
|
|
6
6
|
* - If you wish to define an _abstract_ time without a timezone, e.g. a daily alarm, use `TimeSchema` instead.
|
|
7
7
|
*/
|
|
8
8
|
export declare class DateTimeSchema extends DateSchema {
|
|
9
|
-
constructor({ title, input, ...options }: DateSchemaOptions);
|
|
9
|
+
constructor({ one, title, input, ...options }: DateSchemaOptions);
|
|
10
10
|
format(value: Date): string;
|
|
11
11
|
stringify(value: Date): string;
|
|
12
12
|
}
|
package/schema/DateTimeSchema.js
CHANGED
|
@@ -8,8 +8,8 @@ import { NULLABLE } from "./NullableSchema.js";
|
|
|
8
8
|
* - If you wish to define an _abstract_ time without a timezone, e.g. a daily alarm, use `TimeSchema` instead.
|
|
9
9
|
*/
|
|
10
10
|
export class DateTimeSchema extends DateSchema {
|
|
11
|
-
constructor({ title = "Time", input = "datetime-local", ...options }) {
|
|
12
|
-
super({ title, input, ...options });
|
|
11
|
+
constructor({ one = "time", title = "Time", input = "datetime-local", ...options }) {
|
|
12
|
+
super({ one, title, input, ...options });
|
|
13
13
|
}
|
|
14
14
|
format(value) {
|
|
15
15
|
return formatDateTime(value);
|
|
@@ -3,8 +3,6 @@ import type { SchemaOptions } from "./Schema.js";
|
|
|
3
3
|
import { Schema } from "./Schema.js";
|
|
4
4
|
/** Allowed options for `DictionarySchema` */
|
|
5
5
|
export interface DictionarySchemaOptions<T> extends SchemaOptions {
|
|
6
|
-
readonly one?: string;
|
|
7
|
-
readonly many?: string;
|
|
8
6
|
readonly items: Schema<T>;
|
|
9
7
|
readonly value?: ImmutableDictionary | undefined;
|
|
10
8
|
readonly min?: number | undefined;
|
|
@@ -13,8 +11,6 @@ export interface DictionarySchemaOptions<T> extends SchemaOptions {
|
|
|
13
11
|
/** Validate a dictionary object (whose props are all the same with string keys). */
|
|
14
12
|
export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>> {
|
|
15
13
|
readonly value: ImmutableDictionary<T>;
|
|
16
|
-
readonly one: string;
|
|
17
|
-
readonly many: string;
|
|
18
14
|
readonly items: Schema<T>;
|
|
19
15
|
readonly min: number;
|
|
20
16
|
readonly max: number;
|
|
@@ -4,15 +4,11 @@ import { validateDictionary } from "../util/validate.js";
|
|
|
4
4
|
import { Schema } from "./Schema.js";
|
|
5
5
|
/** Validate a dictionary object (whose props are all the same with string keys). */
|
|
6
6
|
export class DictionarySchema extends Schema {
|
|
7
|
-
one;
|
|
8
|
-
many;
|
|
9
7
|
items;
|
|
10
8
|
min;
|
|
11
9
|
max;
|
|
12
|
-
constructor({ items, one =
|
|
13
|
-
super({ title, placeholder, value, ...options });
|
|
14
|
-
this.one = one;
|
|
15
|
-
this.many = many;
|
|
10
|
+
constructor({ items, one = items.one, many = items.many, placeholder = `No ${many}`, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = {}, ...options }) {
|
|
11
|
+
super({ one, many, title, placeholder, value, ...options });
|
|
16
12
|
this.items = items;
|
|
17
13
|
this.min = min;
|
|
18
14
|
this.max = max;
|
package/schema/EmailSchema.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
18
18
|
* - TLD is a segment of 2-63 characters, possibly in `xn--` international format.
|
|
19
19
|
*/
|
|
20
20
|
export declare class EmailSchema extends StringSchema {
|
|
21
|
-
constructor({ title, ...options }: Omit<StringSchemaOptions, "type" | "min" | "max" | "match" | "multiline">);
|
|
21
|
+
constructor({ one, title, ...options }: Omit<StringSchemaOptions, "type" | "min" | "max" | "match" | "multiline">);
|
|
22
22
|
sanitize(str: string): string;
|
|
23
23
|
}
|
|
24
24
|
/** Valid email, e.g. `test@test.com` */
|
package/schema/EmailSchema.js
CHANGED
|
@@ -19,8 +19,9 @@ const R_MATCH = /^[a-z0-9](?:[a-zA-Z0-9._+-]{0,62}[a-zA-Z0-9])?@(?:[a-z0-9](?:[a
|
|
|
19
19
|
* - TLD is a segment of 2-63 characters, possibly in `xn--` international format.
|
|
20
20
|
*/
|
|
21
21
|
export class EmailSchema extends StringSchema {
|
|
22
|
-
constructor({ title = "Email", ...options }) {
|
|
22
|
+
constructor({ one = "email address", title = "Email", ...options }) {
|
|
23
23
|
super({
|
|
24
|
+
one,
|
|
24
25
|
title,
|
|
25
26
|
...options,
|
|
26
27
|
input: "email",
|
package/schema/EntitySchema.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface EntitySchemaOptions<T extends string> extends StringSchemaOptio
|
|
|
8
8
|
/** Validate a file name matching one or more extensions. */
|
|
9
9
|
export declare class EntitySchema<T extends string> extends StringSchema {
|
|
10
10
|
readonly types: ImmutableArray<T> | undefined;
|
|
11
|
-
constructor({
|
|
11
|
+
constructor({ one, title, types, ...options }: EntitySchemaOptions<T>);
|
|
12
12
|
validate(unsafeValue?: unknown): Entity<T>;
|
|
13
13
|
}
|
|
14
14
|
/** Valid file, e.g. `challenge:a1b2c3` */
|
package/schema/EntitySchema.js
CHANGED
|
@@ -6,8 +6,8 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
6
6
|
/** Validate a file name matching one or more extensions. */
|
|
7
7
|
export class EntitySchema extends StringSchema {
|
|
8
8
|
types;
|
|
9
|
-
constructor({
|
|
10
|
-
super({ title, ...options });
|
|
9
|
+
constructor({ one = "entity", title = "Entity", types, ...options }) {
|
|
10
|
+
super({ one, title, ...options });
|
|
11
11
|
this.types = types;
|
|
12
12
|
}
|
|
13
13
|
validate(unsafeValue = this.value) {
|
package/schema/FileSchema.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface FileSchemaOptions extends StringSchemaOptions {
|
|
|
7
7
|
/** Validate a file name matching one or more extensions. */
|
|
8
8
|
export declare class FileSchema extends StringSchema {
|
|
9
9
|
readonly types: FileTypes | undefined;
|
|
10
|
-
constructor({
|
|
10
|
+
constructor({ one, title, types, ...options }: FileSchemaOptions);
|
|
11
11
|
validate(unsafeValue?: unknown): string;
|
|
12
12
|
}
|
|
13
13
|
/** Valid file, e.g. `file.txt` */
|
package/schema/FileSchema.js
CHANGED
|
@@ -6,8 +6,8 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
6
6
|
/** Validate a file name matching one or more extensions. */
|
|
7
7
|
export class FileSchema extends StringSchema {
|
|
8
8
|
types;
|
|
9
|
-
constructor({
|
|
10
|
-
super({ title, ...options });
|
|
9
|
+
constructor({ one = "file", title = "File", types, ...options }) {
|
|
10
|
+
super({ one, title, ...options });
|
|
11
11
|
this.types = types;
|
|
12
12
|
}
|
|
13
13
|
validate(unsafeValue = this.value) {
|
package/schema/KeySchema.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { StringSchema, type StringSchemaOptions } from "./StringSchema.js";
|
|
|
8
8
|
* - 32 characters is enough for UUIDs, as the 4 `-` hyphens are removed.
|
|
9
9
|
*/
|
|
10
10
|
export declare class KeySchema extends StringSchema {
|
|
11
|
-
constructor({ min, max, ...options }: StringSchemaOptions);
|
|
11
|
+
constructor({ one, min, max, ...options }: StringSchemaOptions);
|
|
12
12
|
sanitize(str: string): string;
|
|
13
13
|
}
|
|
14
14
|
/** Valid database key. */
|
package/schema/KeySchema.js
CHANGED
|
@@ -10,8 +10,8 @@ const R_NOT_CHAR = /[^a-zA-Z0-9]/g;
|
|
|
10
10
|
* - 32 characters is enough for UUIDs, as the 4 `-` hyphens are removed.
|
|
11
11
|
*/
|
|
12
12
|
export class KeySchema extends StringSchema {
|
|
13
|
-
constructor({ min = 1, max = 32, ...options }) {
|
|
14
|
-
super({ min, max, ...options });
|
|
13
|
+
constructor({ one = "key", min = 1, max = 32, ...options }) {
|
|
14
|
+
super({ one, min, max, ...options });
|
|
15
15
|
}
|
|
16
16
|
sanitize(str) {
|
|
17
17
|
return str.replace(R_NOT_CHAR, "");
|
package/schema/LinkSchema.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type AbsoluteLink } from "../util/link.js";
|
|
|
3
3
|
import type { StringSchemaOptions } from "./StringSchema.js";
|
|
4
4
|
import { StringSchema } from "./StringSchema.js";
|
|
5
5
|
/** Allowed options for `LinkSchema` */
|
|
6
|
-
export interface LinkSchemaOptions extends Omit<StringSchemaOptions, "
|
|
6
|
+
export interface LinkSchemaOptions extends Omit<StringSchemaOptions, "input" | "min" | "max" | "multiline"> {
|
|
7
7
|
readonly base?: AbsoluteLink | undefined;
|
|
8
8
|
readonly schemes?: ImmutableArray<string> | undefined;
|
|
9
9
|
readonly hosts?: ImmutableArray<string> | undefined;
|
|
@@ -18,7 +18,7 @@ export declare class LinkSchema extends StringSchema {
|
|
|
18
18
|
readonly base: AbsoluteLink | undefined;
|
|
19
19
|
readonly schemes: ImmutableArray<string> | undefined;
|
|
20
20
|
readonly hosts: ImmutableArray<string> | undefined;
|
|
21
|
-
constructor({ base, schemes, hosts,
|
|
21
|
+
constructor({ one, title, base, schemes, hosts, ...options }: LinkSchemaOptions);
|
|
22
22
|
validate(unsafeValue: unknown): AbsoluteLink;
|
|
23
23
|
}
|
|
24
24
|
/** Valid link, e.g. `https://www.google.com` */
|
package/schema/LinkSchema.js
CHANGED
|
@@ -12,8 +12,9 @@ export class LinkSchema extends StringSchema {
|
|
|
12
12
|
base;
|
|
13
13
|
schemes;
|
|
14
14
|
hosts;
|
|
15
|
-
constructor({
|
|
15
|
+
constructor({ one = "link", title = "Link", base, schemes, hosts, ...options }) {
|
|
16
16
|
super({
|
|
17
|
+
one,
|
|
17
18
|
title,
|
|
18
19
|
...options,
|
|
19
20
|
input: "url",
|
package/schema/NumberSchema.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class NumberSchema extends Schema<number> {
|
|
|
13
13
|
readonly min: number;
|
|
14
14
|
readonly max: number;
|
|
15
15
|
readonly step: number | undefined;
|
|
16
|
-
constructor({ min, max, step,
|
|
16
|
+
constructor({ one, title, min, max, step, value, ...options }: NumberSchemaOptions);
|
|
17
17
|
validate(unsafeValue?: unknown): number;
|
|
18
18
|
}
|
|
19
19
|
/** Valid number, e.g. `2048.12345` or `0` zero. */
|
package/schema/NumberSchema.js
CHANGED
|
@@ -8,8 +8,8 @@ export class NumberSchema extends Schema {
|
|
|
8
8
|
min;
|
|
9
9
|
max;
|
|
10
10
|
step;
|
|
11
|
-
constructor({ min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step,
|
|
12
|
-
super({ title, value, ...options });
|
|
11
|
+
constructor({ one = "number", title = "Number", min = Number.NEGATIVE_INFINITY, max = Number.POSITIVE_INFINITY, step, value = 0, ...options }) {
|
|
12
|
+
super({ one, title, value, ...options });
|
|
13
13
|
this.min = min;
|
|
14
14
|
this.max = max;
|
|
15
15
|
this.step = step;
|
|
@@ -19,10 +19,10 @@ export class NumberSchema extends Schema {
|
|
|
19
19
|
if (typeof optionalNumber !== "number")
|
|
20
20
|
throw new ValueFeedback("Must be number", unsafeValue);
|
|
21
21
|
const roundedNumber = typeof this.step === "number" ? roundStep(optionalNumber, this.step) : optionalNumber;
|
|
22
|
+
if (roundedNumber < this.min)
|
|
23
|
+
throw new ValueFeedback(!optionalNumber ? "Required" : `Minimum ${formatNumber(this.min)}`, roundedNumber);
|
|
22
24
|
if (roundedNumber > this.max)
|
|
23
25
|
throw new ValueFeedback(`Maximum ${formatNumber(this.max)}`, roundedNumber);
|
|
24
|
-
if (roundedNumber < this.min)
|
|
25
|
-
throw new ValueFeedback(`Minimum ${formatNumber(this.min)}`, roundedNumber);
|
|
26
26
|
return roundedNumber;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/schema/PhoneSchema.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
6
6
|
* - Falsy values are converted to `""` empty string.
|
|
7
7
|
*/
|
|
8
8
|
export declare class PhoneSchema extends StringSchema {
|
|
9
|
-
constructor({ title, ...options }: StringSchemaOptions);
|
|
9
|
+
constructor({ one, title, ...options }: Omit<StringSchemaOptions, "input" | "min" | "max" | "match" | "multiline">);
|
|
10
10
|
sanitize(insaneString: string): string;
|
|
11
11
|
}
|
|
12
12
|
/** Valid phone number, e.g. `+441234567890` */
|
package/schema/PhoneSchema.js
CHANGED
|
@@ -10,8 +10,9 @@ const PHONE_REGEXP = /^\+[1-9][0-9]{0,2}[0-9]{5,12}$/;
|
|
|
10
10
|
* - Falsy values are converted to `""` empty string.
|
|
11
11
|
*/
|
|
12
12
|
export class PhoneSchema extends StringSchema {
|
|
13
|
-
constructor({ title = "Phone", ...options }) {
|
|
13
|
+
constructor({ one = "phone number", title = "Phone", ...options }) {
|
|
14
14
|
super({
|
|
15
|
+
one,
|
|
15
16
|
title,
|
|
16
17
|
...options,
|
|
17
18
|
input: "tel",
|
package/schema/Schema.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import type { Data } from "../util/data.js";
|
|
|
2
2
|
import type { Validator } from "../util/validate.js";
|
|
3
3
|
/** Options allowed by a `Schema` instance. */
|
|
4
4
|
export type SchemaOptions = {
|
|
5
|
+
/** String for one of this thing, e.g. `product` or `item` or `sheep` */
|
|
6
|
+
readonly one?: string;
|
|
7
|
+
/** String for several of this thing, e.g. `products` or `items` or `sheep` (defaults to `one` + "s") */
|
|
8
|
+
readonly many?: string;
|
|
5
9
|
/** Title of the schema, e.g. for using as the title of a corresponding field. */
|
|
6
10
|
readonly title?: string | undefined;
|
|
7
11
|
/** Description of the schema, e.g. for using as a description in a corresponding field. */
|
|
@@ -17,15 +21,19 @@ export type SchemaOptions = {
|
|
|
17
21
|
* - `validate()` returns `Invalid` if value was not valid.
|
|
18
22
|
*/
|
|
19
23
|
export declare abstract class Schema<T = unknown> implements Validator<T> {
|
|
24
|
+
/** String for one of this thing, e.g. `product` or `item` or `sheep` */
|
|
25
|
+
readonly one: string;
|
|
26
|
+
/** String for several of this thing, e.g. `products` or `items` or `sheep` (defaults to `one` + "s") */
|
|
27
|
+
readonly many: string;
|
|
20
28
|
/** Title of the schema, e.g. for using as the title of a corresponding field. */
|
|
21
|
-
readonly title: string
|
|
29
|
+
readonly title: string;
|
|
22
30
|
/** Description of the schema, e.g. for using as a description in a corresponding field. */
|
|
23
|
-
readonly description: string
|
|
31
|
+
readonly description: string;
|
|
24
32
|
/** Placeholder of the schema, e.g. for using as a placeholder in a corresponding field. */
|
|
25
|
-
readonly placeholder: string
|
|
33
|
+
readonly placeholder: string;
|
|
26
34
|
/** Default value for the schema if `validate()` is called with an `undefined` value. */
|
|
27
35
|
readonly value: unknown;
|
|
28
|
-
constructor({ title, description, placeholder, value }: SchemaOptions);
|
|
36
|
+
constructor({ one, many, title, description, placeholder, value }: SchemaOptions);
|
|
29
37
|
/** Every schema must implement a `validate()` method. */
|
|
30
38
|
abstract validate(unsafeValue: unknown): T;
|
|
31
39
|
}
|
package/schema/Schema.js
CHANGED
|
@@ -7,6 +7,10 @@ import { getUndefined } from "../util/undefined.js";
|
|
|
7
7
|
* - `validate()` returns `Invalid` if value was not valid.
|
|
8
8
|
*/
|
|
9
9
|
export class Schema {
|
|
10
|
+
/** String for one of this thing, e.g. `product` or `item` or `sheep` */
|
|
11
|
+
one;
|
|
12
|
+
/** String for several of this thing, e.g. `products` or `items` or `sheep` (defaults to `one` + "s") */
|
|
13
|
+
many;
|
|
10
14
|
/** Title of the schema, e.g. for using as the title of a corresponding field. */
|
|
11
15
|
title;
|
|
12
16
|
/** Description of the schema, e.g. for using as a description in a corresponding field. */
|
|
@@ -15,7 +19,9 @@ export class Schema {
|
|
|
15
19
|
placeholder;
|
|
16
20
|
/** Default value for the schema if `validate()` is called with an `undefined` value. */
|
|
17
21
|
value;
|
|
18
|
-
constructor({ title, description, placeholder, value }) {
|
|
22
|
+
constructor({ one = "value", many = `${one}s`, title = "", description = "", placeholder = "", value }) {
|
|
23
|
+
this.one = one;
|
|
24
|
+
this.many = many;
|
|
19
25
|
this.title = title;
|
|
20
26
|
this.description = description;
|
|
21
27
|
this.placeholder = placeholder;
|
|
@@ -23,7 +29,15 @@ export class Schema {
|
|
|
23
29
|
}
|
|
24
30
|
}
|
|
25
31
|
// Unknown validator always passes through its input value as `unknown`
|
|
26
|
-
export const UNKNOWN = {
|
|
32
|
+
export const UNKNOWN = {
|
|
33
|
+
one: "none",
|
|
34
|
+
many: "none",
|
|
35
|
+
title: "",
|
|
36
|
+
description: "",
|
|
37
|
+
placeholder: "",
|
|
38
|
+
value: undefined,
|
|
39
|
+
validate: PASSTHROUGH,
|
|
40
|
+
};
|
|
27
41
|
// Undefined validator always returns `undefined`
|
|
28
42
|
export const UNDEFINED = { ...UNKNOWN, validate: getUndefined };
|
|
29
43
|
// Null validator always returns `null`
|
package/schema/TimeSchema.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateSchema, type DateSchemaOptions } from "./DateSchema.js";
|
|
2
2
|
/** Define a valid time in 24h hh:mm:ss.fff format, e.g. `23:59` or `24:00 */
|
|
3
3
|
export declare class TimeSchema extends DateSchema {
|
|
4
|
-
constructor({ title, input, ...options }: DateSchemaOptions);
|
|
4
|
+
constructor({ one, title, input, ...options }: DateSchemaOptions);
|
|
5
5
|
stringify(value: Date): string;
|
|
6
6
|
format(value: Date): string;
|
|
7
7
|
}
|
package/schema/TimeSchema.js
CHANGED
|
@@ -4,8 +4,8 @@ import { DateSchema } from "./DateSchema.js";
|
|
|
4
4
|
import { NULLABLE } from "./NullableSchema.js";
|
|
5
5
|
/** Define a valid time in 24h hh:mm:ss.fff format, e.g. `23:59` or `24:00 */
|
|
6
6
|
export class TimeSchema extends DateSchema {
|
|
7
|
-
constructor({ title = "Time", input = "time", ...options }) {
|
|
8
|
-
super({ title, input, ...options });
|
|
7
|
+
constructor({ one = "time", title = "Time", input = "time", ...options }) {
|
|
8
|
+
super({ one, title, input, ...options });
|
|
9
9
|
}
|
|
10
10
|
stringify(value) {
|
|
11
11
|
return requireTimeString(value);
|
package/schema/UUIDSchema.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { StringSchema, type StringSchemaOptions } from "./StringSchema.js";
|
|
|
5
5
|
* - Falsy values are converted to empty string.
|
|
6
6
|
*/
|
|
7
7
|
export declare class UUIDSchema extends StringSchema {
|
|
8
|
-
constructor(
|
|
8
|
+
constructor({ one, title, ...rest }?: Omit<StringSchemaOptions, "input" | "min" | "max" | "match" | "multiline">);
|
|
9
9
|
sanitize(str: string): string;
|
|
10
10
|
}
|
|
11
11
|
/** Any valid UUID (versions 1-5) */
|
package/schema/UUIDSchema.js
CHANGED
|
@@ -7,9 +7,9 @@ import { StringSchema } from "./StringSchema.js";
|
|
|
7
7
|
* - Falsy values are converted to empty string.
|
|
8
8
|
*/
|
|
9
9
|
export class UUIDSchema extends StringSchema {
|
|
10
|
-
constructor(
|
|
11
|
-
const { title = "UUID", ...rest } = options;
|
|
10
|
+
constructor({ one = "UUID", title = "UUID", ...rest } = {}) {
|
|
12
11
|
super({
|
|
12
|
+
one,
|
|
13
13
|
title,
|
|
14
14
|
...rest,
|
|
15
15
|
min: 32,
|