shelving 1.158.1 → 1.158.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/ArraySchema.d.ts +5 -1
- package/schema/ArraySchema.js +5 -1
- package/schema/DictionarySchema.d.ts +5 -1
- package/schema/DictionarySchema.js +5 -1
- package/util/format.d.ts +1 -1
- package/util/format.js +2 -2
- package/util/sequence.d.ts +2 -0
- package/util/sequence.js +5 -0
- package/util/units.d.ts +5 -5
- package/util/units.js +28 -28
package/package.json
CHANGED
package/schema/ArraySchema.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ 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;
|
|
6
8
|
readonly value?: ImmutableArray;
|
|
7
9
|
readonly items: Schema<T>;
|
|
8
10
|
readonly min?: number;
|
|
@@ -38,11 +40,13 @@ export interface ArraySchemaOptions<T> extends SchemaOptions {
|
|
|
38
40
|
*/
|
|
39
41
|
export declare class ArraySchema<T> extends Schema<ImmutableArray<T>> {
|
|
40
42
|
readonly value: ImmutableArray;
|
|
43
|
+
readonly one: string;
|
|
44
|
+
readonly many: string;
|
|
41
45
|
readonly items: Schema<T>;
|
|
42
46
|
readonly unique: boolean;
|
|
43
47
|
readonly min: number;
|
|
44
48
|
readonly max: number;
|
|
45
|
-
constructor({ items, unique, min, max, title, value, ...options }: ArraySchemaOptions<T>);
|
|
49
|
+
constructor({ items, one, many, unique, min, max, title, value, ...options }: ArraySchemaOptions<T>);
|
|
46
50
|
validate(unsafeValue?: unknown): ImmutableArray<T>;
|
|
47
51
|
}
|
|
48
52
|
/** Valid array with specifed items. */
|
package/schema/ArraySchema.js
CHANGED
|
@@ -30,12 +30,16 @@ 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;
|
|
33
35
|
items;
|
|
34
36
|
unique;
|
|
35
37
|
min;
|
|
36
38
|
max;
|
|
37
|
-
constructor({ items, unique = false, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = [], ...options }) {
|
|
39
|
+
constructor({ items, one = "item", many = `${one}s`, unique = false, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = [], ...options }) {
|
|
38
40
|
super({ title, value, ...options });
|
|
41
|
+
this.one = one;
|
|
42
|
+
this.many = many;
|
|
39
43
|
this.items = items;
|
|
40
44
|
this.unique = unique;
|
|
41
45
|
this.min = min;
|
|
@@ -3,6 +3,8 @@ 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;
|
|
6
8
|
readonly items: Schema<T>;
|
|
7
9
|
readonly value?: ImmutableDictionary | undefined;
|
|
8
10
|
readonly min?: number | undefined;
|
|
@@ -11,10 +13,12 @@ export interface DictionarySchemaOptions<T> extends SchemaOptions {
|
|
|
11
13
|
/** Validate a dictionary object (whose props are all the same with string keys). */
|
|
12
14
|
export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>> {
|
|
13
15
|
readonly value: ImmutableDictionary;
|
|
16
|
+
readonly one: string;
|
|
17
|
+
readonly many: string;
|
|
14
18
|
readonly items: Schema<T>;
|
|
15
19
|
readonly min: number;
|
|
16
20
|
readonly max: number;
|
|
17
|
-
constructor({ items, min, max, title, value, ...options }: DictionarySchemaOptions<T>);
|
|
21
|
+
constructor({ items, one, many, min, max, title, value, ...options }: DictionarySchemaOptions<T>);
|
|
18
22
|
validate(unsafeValue?: unknown): ImmutableDictionary<T>;
|
|
19
23
|
}
|
|
20
24
|
/** Valid dictionary object with specifed items. */
|
|
@@ -4,11 +4,15 @@ 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;
|
|
7
9
|
items;
|
|
8
10
|
min;
|
|
9
11
|
max;
|
|
10
|
-
constructor({ items, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = {}, ...options }) {
|
|
12
|
+
constructor({ items, one = "item", many = "items", min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = {}, ...options }) {
|
|
11
13
|
super({ title, value, ...options });
|
|
14
|
+
this.one = one;
|
|
15
|
+
this.many = many;
|
|
12
16
|
this.items = items;
|
|
13
17
|
this.min = min;
|
|
14
18
|
this.max = max;
|
package/util/format.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function formatQuantity(num: number, suffix: string, options?: In
|
|
|
9
9
|
/** Format a number (based on the user's browser language settings). */
|
|
10
10
|
export declare function formatNumber(num: number, options?: Intl.NumberFormatOptions): string;
|
|
11
11
|
/** Format a number with a longer full-word suffix. */
|
|
12
|
-
export declare function pluralizeQuantity(num: number,
|
|
12
|
+
export declare function pluralizeQuantity(num: number, one: string, many: string, options?: Intl.NumberFormatOptions): string;
|
|
13
13
|
/**
|
|
14
14
|
* Format a percentage (combines `getPercent()` and `formatQuantity()` for convenience).
|
|
15
15
|
* - Defaults to showing no decimal places.
|
package/util/format.js
CHANGED
|
@@ -22,12 +22,12 @@ export function formatNumber(num, options) {
|
|
|
22
22
|
return new Intl.NumberFormat(undefined, options).format(num).replace(/ /, NNBSP);
|
|
23
23
|
}
|
|
24
24
|
/** Format a number with a longer full-word suffix. */
|
|
25
|
-
export function pluralizeQuantity(num,
|
|
25
|
+
export function pluralizeQuantity(num, one, many, options) {
|
|
26
26
|
const qty = formatNumber(num, {
|
|
27
27
|
...options,
|
|
28
28
|
style: "decimal",
|
|
29
29
|
});
|
|
30
|
-
return `${qty}${NNBSP}${num === 1 ?
|
|
30
|
+
return `${qty}${NNBSP}${num === 1 ? one : many}`;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Format a percentage (combines `getPercent()` and `formatQuantity()` for convenience).
|
package/util/sequence.d.ts
CHANGED
|
@@ -15,3 +15,5 @@ export declare function repeatDelay(ms: number): AsyncIterable<number>;
|
|
|
15
15
|
export declare function callSequence<T>(sequence: AsyncIterable<T>, callback: AsyncValueCallback<T>): AsyncIterable<T>;
|
|
16
16
|
/** Pull values from a sequence until the returned function is called. */
|
|
17
17
|
export declare function runSequence<T>(sequence: AsyncIterable<T>, onNext?: ValueCallback<T>, onError?: ErrorCallback): StopCallback;
|
|
18
|
+
/** Merge several sequences (calls the sequences in series). */
|
|
19
|
+
export declare function mergeSequences<T>(...sequences: AsyncIterable<T>[]): AsyncIterable<T>;
|
package/util/sequence.js
CHANGED
|
@@ -71,3 +71,8 @@ async function _runSequence(sequence, stopped, onNext, onError) {
|
|
|
71
71
|
// Continue iteration.
|
|
72
72
|
return _runSequence(sequence, stopped, onNext, onError);
|
|
73
73
|
}
|
|
74
|
+
/** Merge several sequences (calls the sequences in series). */
|
|
75
|
+
export async function* mergeSequences(...sequences) {
|
|
76
|
+
for await (const sequence of sequences)
|
|
77
|
+
yield* sequence;
|
|
78
|
+
}
|
package/util/units.d.ts
CHANGED
|
@@ -10,9 +10,9 @@ type UnitProps<T extends string> = {
|
|
|
10
10
|
/** Short abbreviation for this unit, e.g. `km` (defaults to first letter of `id`). */
|
|
11
11
|
readonly abbr?: string;
|
|
12
12
|
/** Singular name for this unit, e.g. `kilometer` (defaults to `id` + "s"). */
|
|
13
|
-
readonly
|
|
13
|
+
readonly one?: string;
|
|
14
14
|
/** Plural name for this unit, e.g. `kilometers` (defaults to `id`). */
|
|
15
|
-
readonly
|
|
15
|
+
readonly many?: string;
|
|
16
16
|
/** Conversions to other units (typically needs at least the base conversion, unless it's already the base unit). */
|
|
17
17
|
readonly to?: Conversions<T>;
|
|
18
18
|
/** Possible options for formatting these units with `Intl.NumberFormat` (`.unit` can be specified if different from key, but is not required). */
|
|
@@ -28,9 +28,9 @@ export declare class Unit<K extends string> {
|
|
|
28
28
|
/** Short abbreviation for this unit, e.g. `km` (defaults to first letter of `id`). */
|
|
29
29
|
readonly abbr: string;
|
|
30
30
|
/** Singular name for this unit, e.g. `kilometer` (defaults to `id`). */
|
|
31
|
-
readonly
|
|
31
|
+
readonly one: string;
|
|
32
32
|
/** Plural name for this unit, e.g. `kilometers` (defaults to `singular` + "s"). */
|
|
33
|
-
readonly
|
|
33
|
+
readonly many: string;
|
|
34
34
|
/** Possible options for formatting these units with `Intl.NumberFormat` (`.unit` can be specified if different from key, but is not required). */
|
|
35
35
|
readonly options: Readonly<Intl.NumberFormatOptions> | undefined;
|
|
36
36
|
/** Title for this unit (uses format `abbr (plural)`, e.g. `fl oz (US fluid ounces)`) */
|
|
@@ -41,7 +41,7 @@ export declare class Unit<K extends string> {
|
|
|
41
41
|
/** String key for this unit, e.g. `kilometer` */
|
|
42
42
|
key: K,
|
|
43
43
|
/** Props to configure this unit. */
|
|
44
|
-
{ abbr,
|
|
44
|
+
{ abbr, one, many, options, to }: UnitProps<K>);
|
|
45
45
|
/** Convert an amount from this unit to another unit. */
|
|
46
46
|
to(amount: number, targetKey?: K): number;
|
|
47
47
|
/** Convert an amount from another unit to this unit. */
|
package/util/units.js
CHANGED
|
@@ -18,14 +18,14 @@ export class Unit {
|
|
|
18
18
|
/** Short abbreviation for this unit, e.g. `km` (defaults to first letter of `id`). */
|
|
19
19
|
abbr;
|
|
20
20
|
/** Singular name for this unit, e.g. `kilometer` (defaults to `id`). */
|
|
21
|
-
|
|
21
|
+
one;
|
|
22
22
|
/** Plural name for this unit, e.g. `kilometers` (defaults to `singular` + "s"). */
|
|
23
|
-
|
|
23
|
+
many;
|
|
24
24
|
/** Possible options for formatting these units with `Intl.NumberFormat` (`.unit` can be specified if different from key, but is not required). */
|
|
25
25
|
options;
|
|
26
26
|
/** Title for this unit (uses format `abbr (plural)`, e.g. `fl oz (US fluid ounces)`) */
|
|
27
27
|
get title() {
|
|
28
|
-
return `${this.abbr} (${this.
|
|
28
|
+
return `${this.abbr} (${this.many})`;
|
|
29
29
|
}
|
|
30
30
|
constructor(
|
|
31
31
|
/** `UnitList` this unit belongs to. */
|
|
@@ -33,12 +33,12 @@ export class Unit {
|
|
|
33
33
|
/** String key for this unit, e.g. `kilometer` */
|
|
34
34
|
key,
|
|
35
35
|
/** Props to configure this unit. */
|
|
36
|
-
{ abbr = key.slice(0, 1),
|
|
36
|
+
{ abbr = key.slice(0, 1), one = key.replace(/-/, " "), many = `${one}s`, options, to }) {
|
|
37
37
|
this.list = list;
|
|
38
38
|
this.key = key;
|
|
39
39
|
this.abbr = abbr;
|
|
40
|
-
this.
|
|
41
|
-
this.
|
|
40
|
+
this.one = one;
|
|
41
|
+
this.many = many;
|
|
42
42
|
this.options = options;
|
|
43
43
|
this._to = to;
|
|
44
44
|
}
|
|
@@ -89,7 +89,7 @@ export class Unit {
|
|
|
89
89
|
// Otherwise, use the default number format.
|
|
90
90
|
// If unitDisplay is "long" use the singular/plural form.
|
|
91
91
|
const o = { style: "decimal", unitDisplay: "short", ...this.options, ...options };
|
|
92
|
-
return o.unitDisplay === "long" ? pluralizeQuantity(amount, this.
|
|
92
|
+
return o.unitDisplay === "long" ? pluralizeQuantity(amount, this.one, this.many, o) : formatQuantity(amount, this.abbr, o);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
@@ -155,7 +155,7 @@ const US_IN3_PER_GAL = 231;
|
|
|
155
155
|
const IMP_ML_PER_GAL = 4546090 / 1000;
|
|
156
156
|
/** Percentage units. */
|
|
157
157
|
export const PERCENT_UNITS = new UnitList({
|
|
158
|
-
percent: { abbr: "%",
|
|
158
|
+
percent: { abbr: "%", many: "percent" },
|
|
159
159
|
});
|
|
160
160
|
/** Point units. */
|
|
161
161
|
export const POINT_UNITS = new UnitList({
|
|
@@ -177,7 +177,7 @@ export const MASS_UNITS = new UnitList({
|
|
|
177
177
|
// Imperial.
|
|
178
178
|
ounce: { abbr: "oz", to: { milligram: MG_PER_LB / OZ_PER_LB } },
|
|
179
179
|
pound: { abbr: "lb", to: { milligram: MG_PER_LB, ounce: OZ_PER_LB } },
|
|
180
|
-
stone: { abbr: "st",
|
|
180
|
+
stone: { abbr: "st", many: "stone", to: { milligram: MG_PER_LB * LB_PER_ST, pound: LB_PER_ST, ounce: OZ_PER_LB * LB_PER_ST } },
|
|
181
181
|
});
|
|
182
182
|
const TIME_OPTIONS = {
|
|
183
183
|
roundingMode: "trunc",
|
|
@@ -202,8 +202,8 @@ export const LENGTH_UNITS = new UnitList({
|
|
|
202
202
|
meter: { to: { millimeter: MM_PER_M } },
|
|
203
203
|
kilometer: { abbr: "km", to: { millimeter: MM_PER_KM } },
|
|
204
204
|
// Imperial.
|
|
205
|
-
inch: { abbr: "in",
|
|
206
|
-
foot: { abbr: "ft",
|
|
205
|
+
inch: { abbr: "in", many: "inches", to: { millimeter: MM_PER_IN } },
|
|
206
|
+
foot: { abbr: "ft", many: "feet", to: { millimeter: IN_PER_FT * MM_PER_IN, inch: IN_PER_FT } },
|
|
207
207
|
yard: { abbr: "yd", to: { millimeter: IN_PER_YD * MM_PER_IN, inch: IN_PER_YD, foot: FT_PER_YD } },
|
|
208
208
|
furlong: { abbr: "fur", to: { millimeter: IN_PER_YD * MM_PER_IN * YD_PER_FUR, foot: YD_PER_FUR * FT_PER_YD, yard: YD_PER_FUR } },
|
|
209
209
|
mile: { abbr: "mi", to: { millimeter: MM_PER_MI, yard: YD_PER_MI, foot: FT_PER_MI, inch: IN_PER_MI } },
|
|
@@ -211,15 +211,15 @@ export const LENGTH_UNITS = new UnitList({
|
|
|
211
211
|
/** Speed units. */
|
|
212
212
|
export const SPEED_UNITS = new UnitList({
|
|
213
213
|
// Metric.
|
|
214
|
-
"meter-per-second": { abbr: "m/s",
|
|
214
|
+
"meter-per-second": { abbr: "m/s", one: "meter per second", many: "meters per second", to: { "kilometer-per-hour": 3.6 } },
|
|
215
215
|
"kilometer-per-hour": {
|
|
216
216
|
abbr: "kph",
|
|
217
|
-
|
|
218
|
-
|
|
217
|
+
one: "kilometer per hour",
|
|
218
|
+
many: "kilometers per hour",
|
|
219
219
|
to: { "meter-per-second": MM_PER_KM / HOUR },
|
|
220
220
|
},
|
|
221
221
|
// Imperial.
|
|
222
|
-
"mile-per-hour": { abbr: "mph",
|
|
222
|
+
"mile-per-hour": { abbr: "mph", one: "mile per hour", many: "miles per hour", to: { "meter-per-second": MM_PER_MI / HOUR } },
|
|
223
223
|
});
|
|
224
224
|
/** Area units. */
|
|
225
225
|
export const AREA_UNITS = new UnitList({
|
|
@@ -230,10 +230,10 @@ export const AREA_UNITS = new UnitList({
|
|
|
230
230
|
"square-kilometer": { abbr: "km²", to: { "square-millimeter": MM_PER_KM ** 2 } },
|
|
231
231
|
hectare: { abbr: "ha", to: { "square-millimeter": (MM_PER_M * 100) ** 2 } },
|
|
232
232
|
// Imperial.
|
|
233
|
-
"square-inch": { abbr: "in²",
|
|
233
|
+
"square-inch": { abbr: "in²", many: "square inches", to: { "square-millimeter": MM2_PER_IN2 } },
|
|
234
234
|
"square-foot": {
|
|
235
235
|
abbr: "ft²",
|
|
236
|
-
|
|
236
|
+
many: "square feet",
|
|
237
237
|
to: { "square-millimeter": IN_PER_FT ** 2 * MM2_PER_IN2, "square-inch": IN_PER_FT ** 2 },
|
|
238
238
|
},
|
|
239
239
|
"square-yard": {
|
|
@@ -255,19 +255,19 @@ export const VOLUME_UNITS = new UnitList({
|
|
|
255
255
|
// US.
|
|
256
256
|
"us-fluid-ounce": {
|
|
257
257
|
abbr: `fl${NNBSP}oz`,
|
|
258
|
-
|
|
259
|
-
|
|
258
|
+
one: "US fluid ounce",
|
|
259
|
+
many: "US fluid ounces",
|
|
260
260
|
to: { milliliter: (US_IN3_PER_GAL * ML_PER_IN3) / 128 },
|
|
261
261
|
},
|
|
262
|
-
"us-pint": { abbr: "pt",
|
|
262
|
+
"us-pint": { abbr: "pt", one: "US pint", to: { milliliter: (US_IN3_PER_GAL * ML_PER_IN3) / 8, "us-fluid-ounce": 16 } },
|
|
263
263
|
"us-quart": {
|
|
264
264
|
abbr: "qt",
|
|
265
|
-
|
|
265
|
+
one: "US quart",
|
|
266
266
|
to: { milliliter: (US_IN3_PER_GAL * ML_PER_IN3) / 4, "us-pint": 2, "us-fluid-ounce": 32 },
|
|
267
267
|
},
|
|
268
268
|
"us-gallon": {
|
|
269
269
|
abbr: "gal",
|
|
270
|
-
|
|
270
|
+
one: "US gallon",
|
|
271
271
|
to: { milliliter: US_IN3_PER_GAL * ML_PER_IN3, "us-quart": 4, "us-pint": 8, "us-fluid-ounce": 128 },
|
|
272
272
|
},
|
|
273
273
|
// Imperial.
|
|
@@ -278,8 +278,8 @@ export const VOLUME_UNITS = new UnitList({
|
|
|
278
278
|
abbr: "gal",
|
|
279
279
|
to: { milliliter: IMP_ML_PER_GAL, "imperial-quart": 4, "imperial-pint": 8, "imperial-fluid-ounce": 160 },
|
|
280
280
|
},
|
|
281
|
-
"cubic-inch": { abbr: "in³",
|
|
282
|
-
"cubic-foot": { abbr: "ft³",
|
|
281
|
+
"cubic-inch": { abbr: "in³", many: "cubic inches", to: { milliliter: ML_PER_IN3 } },
|
|
282
|
+
"cubic-foot": { abbr: "ft³", many: "cubic feet", to: { milliliter: IN_PER_FT ** 3 * ML_PER_IN3, "cubic-inch": IN_PER_FT ** 3 } },
|
|
283
283
|
"cubic-yard": {
|
|
284
284
|
abbr: "yd³",
|
|
285
285
|
to: { milliliter: IN_PER_YD ** 3 * ML_PER_IN3, "cubic-foot": FT_PER_YD ** 3, "cubic-inch": IN_PER_YD ** 3 },
|
|
@@ -289,10 +289,10 @@ export const VOLUME_UNITS = new UnitList({
|
|
|
289
289
|
export const TEMPERATURE_UNITS = new UnitList({
|
|
290
290
|
celsius: {
|
|
291
291
|
abbr: "°C",
|
|
292
|
-
|
|
293
|
-
|
|
292
|
+
one: "degree Celsius",
|
|
293
|
+
many: "degrees Celsius",
|
|
294
294
|
to: { fahrenheit: n => n * (9 / 5) + 32, kelvin: n => n + 273.15 },
|
|
295
295
|
},
|
|
296
|
-
fahrenheit: { abbr: "°F",
|
|
297
|
-
kelvin: { abbr: "°K",
|
|
296
|
+
fahrenheit: { abbr: "°F", one: "degree Fahrenheit", many: "degrees Fahrenheit", to: { celsius: n => (n - 32) * (5 / 9) } },
|
|
297
|
+
kelvin: { abbr: "°K", one: "degree Kelvin", many: "degrees Kelvin", to: { celsius: n => n - 273.15 } },
|
|
298
298
|
});
|