shelving 1.154.1 → 1.155.0
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/DateSchema.d.ts +8 -1
- package/schema/DateSchema.js +10 -6
- package/schema/DateTimeSchema.d.ts +1 -3
- package/schema/DateTimeSchema.js +3 -0
- package/schema/TimeSchema.d.ts +3 -13
- package/schema/TimeSchema.js +8 -21
- package/util/array.d.ts +1 -1
- package/util/array.js +1 -1
package/package.json
CHANGED
package/schema/DateSchema.d.ts
CHANGED
|
@@ -10,13 +10,20 @@ export interface DateSchemaOptions extends SchemaOptions {
|
|
|
10
10
|
readonly min?: Nullish<PossibleDate>;
|
|
11
11
|
readonly max?: Nullish<PossibleDate>;
|
|
12
12
|
readonly input?: DateInputType | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Rounding step (in milliseconds, because that's the base unit for time).
|
|
15
|
+
* - E.g. `1000 * 60` will round to the nearest minute.
|
|
16
|
+
* - Note: HTML `<input>` `step` attributes are in _seconds_, so you may need to convert units.
|
|
17
|
+
*/
|
|
18
|
+
readonly step?: number | undefined;
|
|
13
19
|
}
|
|
14
20
|
export declare class DateSchema extends Schema<string> {
|
|
15
21
|
readonly value: PossibleDate;
|
|
16
22
|
readonly min: Date | undefined;
|
|
17
23
|
readonly max: Date | undefined;
|
|
18
24
|
readonly input: DateInputType;
|
|
19
|
-
|
|
25
|
+
readonly step: number | undefined;
|
|
26
|
+
constructor({ min, max, value, input, step, ...options }: DateSchemaOptions);
|
|
20
27
|
validate(value?: unknown): string;
|
|
21
28
|
stringify(value: Date): string;
|
|
22
29
|
format(value: Date): string;
|
package/schema/DateSchema.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { ValueFeedback } from "../feedback/Feedback.js";
|
|
2
2
|
import { getDate, requireDateString } from "../util/date.js";
|
|
3
3
|
import { formatDate } from "../util/format.js";
|
|
4
|
+
import { roundStep } from "../util/number.js";
|
|
4
5
|
import { NULLABLE } from "./NullableSchema.js";
|
|
5
6
|
import { Schema } from "./Schema.js";
|
|
6
7
|
export class DateSchema extends Schema {
|
|
7
8
|
min;
|
|
8
9
|
max;
|
|
9
10
|
input;
|
|
10
|
-
|
|
11
|
+
step;
|
|
12
|
+
constructor({ min, max, value = "now", input = "date", step, ...options }) {
|
|
11
13
|
super({ title: "Date", value, ...options });
|
|
12
14
|
this.min = getDate(min);
|
|
13
15
|
this.max = getDate(max);
|
|
14
16
|
this.input = input;
|
|
17
|
+
this.step = step;
|
|
15
18
|
}
|
|
16
19
|
validate(value = this.value) {
|
|
17
20
|
const date = getDate(value);
|
|
18
21
|
if (!date)
|
|
19
22
|
throw new ValueFeedback(value ? "Invalid date" : "Required", value);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const rounded = typeof this.step === "number" ? new Date(roundStep(date.getTime(), this.step)) : date;
|
|
24
|
+
if (this.min && rounded < this.min)
|
|
25
|
+
throw new ValueFeedback(`Minimum ${this.format(this.min)}`, rounded);
|
|
26
|
+
if (this.max && rounded > this.max)
|
|
27
|
+
throw new ValueFeedback(`Maximum ${this.format(this.max)}`, rounded);
|
|
28
|
+
return this.stringify(rounded);
|
|
25
29
|
}
|
|
26
30
|
stringify(value) {
|
|
27
31
|
return requireDateString(value);
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { DateSchema, type DateSchemaOptions } from "./DateSchema.js";
|
|
2
|
-
/** Allowed options for `DateSchema` */
|
|
3
|
-
export interface DateTimeSchemaOptions extends DateSchemaOptions {
|
|
4
|
-
}
|
|
5
2
|
/**
|
|
6
3
|
* Define a valid UTC date in ISO 8601 format, e.g. `2005-09-12T18:15:00.000Z`
|
|
7
4
|
* - The date includes the `Z` suffix to indicate UTC time, this ensures consistent transfer of the date between client and server.
|
|
@@ -9,6 +6,7 @@ export interface DateTimeSchemaOptions extends DateSchemaOptions {
|
|
|
9
6
|
* - If you wish to define an _abstract_ time without a timezone, e.g. a daily alarm, use `TimeSchema` instead.
|
|
10
7
|
*/
|
|
11
8
|
export declare class DateTimeSchema extends DateSchema {
|
|
9
|
+
constructor({ title, input, ...options }: DateSchemaOptions);
|
|
12
10
|
format(value: Date): string;
|
|
13
11
|
stringify(value: Date): string;
|
|
14
12
|
}
|
package/schema/DateTimeSchema.js
CHANGED
|
@@ -8,6 +8,9 @@ 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 });
|
|
13
|
+
}
|
|
11
14
|
format(value) {
|
|
12
15
|
return formatDateTime(value);
|
|
13
16
|
}
|
package/schema/TimeSchema.d.ts
CHANGED
|
@@ -1,19 +1,9 @@
|
|
|
1
|
-
import { type PossibleDate } from "../util/date.js";
|
|
2
1
|
import { DateSchema, type DateSchemaOptions } from "./DateSchema.js";
|
|
3
|
-
/** Allowed options for `TimeSchama` */
|
|
4
|
-
export interface TimeSchemaOptions extends DateSchemaOptions {
|
|
5
|
-
step?: number | undefined;
|
|
6
|
-
}
|
|
7
2
|
/** Define a valid time in 24h hh:mm:ss.fff format, e.g. `23:59` or `24:00 */
|
|
8
3
|
export declare class TimeSchema extends DateSchema {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* - Note: `<input type="time">` elements expect `step=""` to be in _seconds_ so you need to multiply this by `1000`
|
|
13
|
-
*/
|
|
14
|
-
readonly step: number | undefined;
|
|
15
|
-
constructor({ title, step, ...options }: TimeSchemaOptions);
|
|
16
|
-
validate(unsafeValue?: unknown): string;
|
|
4
|
+
constructor({ title, input, ...options }: DateSchemaOptions);
|
|
5
|
+
stringify(value: Date): string;
|
|
6
|
+
format(value: Date): string;
|
|
17
7
|
}
|
|
18
8
|
/** Valid time, e.g. `2005-09-12` (required because falsy values are invalid). */
|
|
19
9
|
export declare const TIME: TimeSchema;
|
package/schema/TimeSchema.js
CHANGED
|
@@ -1,30 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getDate, requireTimeString } from "../util/date.js";
|
|
1
|
+
import { requireTimeString } from "../util/date.js";
|
|
3
2
|
import { formatTime } from "../util/format.js";
|
|
4
|
-
import { roundStep } from "../util/number.js";
|
|
5
3
|
import { DateSchema } from "./DateSchema.js";
|
|
6
4
|
import { NULLABLE } from "./NullableSchema.js";
|
|
7
5
|
/** Define a valid time in 24h hh:mm:ss.fff format, e.g. `23:59` or `24:00 */
|
|
8
6
|
export class TimeSchema extends DateSchema {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* - Note: `<input type="time">` elements expect `step=""` to be in _seconds_ so you need to multiply this by `1000`
|
|
12
|
-
*/
|
|
13
|
-
step;
|
|
14
|
-
constructor({ title = "Time", step, ...options }) {
|
|
15
|
-
super({ title, ...options });
|
|
16
|
-
this.step = step;
|
|
7
|
+
constructor({ title = "Time", input = "time", ...options }) {
|
|
8
|
+
super({ title, input, ...options });
|
|
17
9
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (this.max && rounded > this.max)
|
|
24
|
-
throw new ValueFeedback(`Maximum ${formatTime(this.max)}`, rounded);
|
|
25
|
-
if (this.min && rounded < this.min)
|
|
26
|
-
throw new ValueFeedback(`Minimum ${formatTime(this.min)}`, rounded);
|
|
27
|
-
return requireTimeString(rounded);
|
|
10
|
+
stringify(value) {
|
|
11
|
+
return requireTimeString(value);
|
|
12
|
+
}
|
|
13
|
+
format(value) {
|
|
14
|
+
return formatTime(value);
|
|
28
15
|
}
|
|
29
16
|
}
|
|
30
17
|
/** Valid time, e.g. `2005-09-12` (required because falsy values are invalid). */
|
package/util/array.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export declare function isArrayItem<T>(list: PossibleArray<T>, item: unknown): i
|
|
|
66
66
|
export declare function assertArrayItem<T>(arr: PossibleArray<T>, item: unknown, caller?: AnyCaller): asserts item is T;
|
|
67
67
|
/** Add multiple items to an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
|
68
68
|
export declare function withArrayItems<T>(list: PossibleArray<T>, ...add: T[]): ImmutableArray<T>;
|
|
69
|
-
/** Pick multiple items from an array (immutably) and return a new array
|
|
69
|
+
/** Pick multiple items from an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
|
70
70
|
export declare function pickArrayItems<T>(items: PossibleArray<T>, ...pick: T[]): ImmutableArray<T>;
|
|
71
71
|
/** Remove multiple items from an array (immutably) and return a new array without those items (or the same array if no changes were made). */
|
|
72
72
|
export declare function omitArrayItems<T>(items: PossibleArray<T>, ...omit: T[]): ImmutableArray<T>;
|
package/util/array.js
CHANGED
|
@@ -42,7 +42,7 @@ export function withArrayItems(list, ...add) {
|
|
|
42
42
|
function _doesNotInclude(value) {
|
|
43
43
|
return !this.includes(value);
|
|
44
44
|
}
|
|
45
|
-
/** Pick multiple items from an array (immutably) and return a new array
|
|
45
|
+
/** Pick multiple items from an array (immutably) and return a new array with those items (or the same array if no changes were made). */
|
|
46
46
|
export function pickArrayItems(items, ...pick) {
|
|
47
47
|
const arr = Array.from(pickItems(items, ...pick));
|
|
48
48
|
return isArray(items) && arr.length === items.length ? items : arr;
|