shelving 1.86.0 → 1.86.2

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.
Files changed (97) hide show
  1. package/api/Resource.d.ts +2 -2
  2. package/constraint/Constraints.js +7 -6
  3. package/constraint/FilterConstraint.d.ts +4 -4
  4. package/constraint/FilterConstraint.js +17 -17
  5. package/constraint/QueryConstraints.d.ts +1 -1
  6. package/constraint/QueryConstraints.js +8 -8
  7. package/constraint/SortConstraint.d.ts +4 -4
  8. package/constraint/SortConstraint.js +3 -3
  9. package/db/Change.d.ts +4 -4
  10. package/db/Item.d.ts +4 -4
  11. package/error/ThroughError.js +1 -1
  12. package/markup/index.d.ts +1 -0
  13. package/markup/index.js +1 -0
  14. package/markup/options.d.ts +2 -2
  15. package/markup/regexp.d.ts +2 -2
  16. package/markup/render.js +19 -20
  17. package/markup/rule.d.ts +80 -0
  18. package/markup/rule.js +63 -0
  19. package/markup/rules.d.ts +17 -67
  20. package/markup/rules.js +88 -160
  21. package/package.json +17 -17
  22. package/react/useItem.js +10 -10
  23. package/react/useQuery.js +29 -29
  24. package/schema/AllowSchema.d.ts +4 -4
  25. package/schema/AllowSchema.js +3 -3
  26. package/schema/ArraySchema.d.ts +1 -1
  27. package/schema/BooleanSchema.d.ts +1 -1
  28. package/schema/DataSchema.d.ts +2 -2
  29. package/schema/DateSchema.d.ts +1 -1
  30. package/schema/DictionarySchema.d.ts +1 -1
  31. package/schema/LinkSchema.d.ts +1 -1
  32. package/schema/NumberSchema.d.ts +1 -1
  33. package/schema/NumberSchema.js +4 -4
  34. package/schema/Schema.d.ts +1 -1
  35. package/schema/StringSchema.d.ts +3 -3
  36. package/schema/ThroughSchema.d.ts +1 -1
  37. package/schema/TimeSchema.d.ts +1 -1
  38. package/state/State.d.ts +1 -1
  39. package/state/State.js +6 -6
  40. package/test/basics.d.ts +2 -2
  41. package/test/index.d.ts +1 -1
  42. package/test/people.d.ts +2 -2
  43. package/update/ArrayUpdate.d.ts +2 -1
  44. package/update/ArrayUpdate.js +9 -8
  45. package/update/DataUpdate.d.ts +1 -1
  46. package/update/DataUpdate.js +7 -6
  47. package/update/DictionaryUpdate.d.ts +1 -1
  48. package/update/DictionaryUpdate.js +8 -7
  49. package/util/array.d.ts +4 -4
  50. package/util/async.js +8 -8
  51. package/util/class.d.ts +3 -3
  52. package/util/clone.js +4 -3
  53. package/util/color.d.ts +2 -2
  54. package/util/color.js +6 -6
  55. package/util/data.d.ts +7 -14
  56. package/util/data.js +1 -19
  57. package/util/date.d.ts +3 -3
  58. package/util/debug.d.ts +1 -0
  59. package/util/debug.js +5 -5
  60. package/util/dictionary.d.ts +5 -5
  61. package/util/duration.d.ts +17 -0
  62. package/util/duration.js +52 -0
  63. package/util/entry.d.ts +3 -3
  64. package/util/equal.js +6 -3
  65. package/util/function.d.ts +8 -8
  66. package/util/hydrate.d.ts +3 -3
  67. package/util/hydrate.js +2 -2
  68. package/util/index.d.ts +1 -0
  69. package/util/index.js +1 -0
  70. package/util/iterate.d.ts +1 -1
  71. package/util/jsx.d.ts +3 -3
  72. package/util/lazy.d.ts +1 -1
  73. package/util/map.d.ts +15 -19
  74. package/util/map.js +11 -13
  75. package/util/match.d.ts +2 -2
  76. package/util/merge.d.ts +1 -1
  77. package/util/null.d.ts +1 -1
  78. package/util/number.d.ts +4 -2
  79. package/util/number.js +8 -6
  80. package/util/object.d.ts +24 -11
  81. package/util/object.js +30 -4
  82. package/util/regexp.d.ts +2 -3
  83. package/util/serialise.js +2 -2
  84. package/util/set.d.ts +4 -4
  85. package/util/sort.d.ts +2 -2
  86. package/util/source.js +2 -2
  87. package/util/string.d.ts +1 -1
  88. package/util/string.js +3 -3
  89. package/util/template.d.ts +2 -2
  90. package/util/template.js +9 -9
  91. package/util/time.d.ts +2 -2
  92. package/util/time.js +3 -3
  93. package/util/transform.d.ts +5 -5
  94. package/util/units.d.ts +39 -50
  95. package/util/units.js +36 -74
  96. package/util/url.d.ts +2 -2
  97. package/util/validate.d.ts +5 -5
package/util/units.js CHANGED
@@ -1,39 +1,40 @@
1
1
  import { ConditionError } from "../error/ConditionError.js";
2
2
  import { DAY, HOUR, MILLION, MINUTE, MONTH, NNBSP, SECOND, WEEK, YEAR } from "./constants.js";
3
3
  import { getProps } from "./object.js";
4
- import { getDuration } from "./date.js";
5
- import { ImmutableRequiredMap } from "./map.js";
6
- import { formatFullQuantity, formatQuantity, getPercent } from "./number.js";
4
+ import { ImmutableMap, getMapItem } from "./map.js";
5
+ import { cramQuantity, formatFullQuantity, formatQuantity } from "./number.js";
7
6
  /** Convert an amount using a `Conversion. */
8
7
  const _convert = (amount, conversion) => (typeof conversion === "function" ? conversion(amount) : conversion === 1 ? amount : amount * conversion);
8
+ /** Get a `Unit` instance from a `UnitList` instance */
9
+ const _getUnit = (list, unit) => (typeof unit === "string" ? getMapItem(list, unit) : unit);
9
10
  /** Represent a unit. */
10
11
  export class Unit {
12
+ /** Title for this unit (uses format `abbr (plural)`, e.g. `fl oz (US fluid ounces)`) */
13
+ get title() {
14
+ return `${this.abbr} (${this.plural})`;
15
+ }
11
16
  constructor(
12
17
  /** `UnitList` this unit belongs to. */
13
18
  list,
14
- /** Key for this unit, e.g. `kilometer` */
15
- id,
19
+ /** String key for this unit, e.g. `kilometer` */
20
+ key,
16
21
  /** Props to configure this unit. */
17
- { abbr = id.slice(0, 1), singular = id.replace(/-/, " "), plural = `${singular}s`, precision = null, to }) {
22
+ { abbr = key.slice(0, 1), singular = key.replace(/-/, " "), plural = `${singular}s`, precision = null, to }) {
18
23
  this.list = list;
19
- this.id = id;
24
+ this.key = key;
20
25
  this.abbr = abbr;
21
26
  this.singular = singular;
22
27
  this.plural = plural;
23
28
  this.precision = precision;
24
29
  this._to = to;
25
30
  }
26
- /** Title for this unit (uses format `abbr (plural)`, e.g. `fl oz (US fluid ounces)`) */
27
- get title() {
28
- return `${this.abbr} (${this.plural})`;
29
- }
30
31
  /** Convert an amount from this unit to another unit. */
31
- to(amount, id = this.list.base) {
32
- return this._toUnit(amount, _getUnit(this.list, id));
32
+ to(amount, unit = this.list.base) {
33
+ return this._toUnit(amount, _getUnit(this.list, unit));
33
34
  }
34
35
  /** Convert an amount from another unit to this unit. */
35
- from(amount, id = this.list.base) {
36
- return _getUnit(this.list, id)._toUnit(amount, this);
36
+ from(amount, unit = this.list.base) {
37
+ return _getUnit(this.list, unit)._toUnit(amount, this);
37
38
  }
38
39
  /** Convert an amount from this unit to another unit (must specify another `Unit` instance). */
39
40
  _toUnit(amount, unit) {
@@ -42,33 +43,40 @@ export class Unit {
42
43
  if (unit === this)
43
44
  return amount;
44
45
  // Exact conversion.
45
- const thisToUnit = (_a = this._to) === null || _a === void 0 ? void 0 : _a[unit.id];
46
+ const thisToUnit = (_a = this._to) === null || _a === void 0 ? void 0 : _a[unit.key];
46
47
  if (thisToUnit)
47
48
  return _convert(amount, thisToUnit);
48
49
  // Invert number conversion (can't do this for function conversions).
49
- const unitToThis = (_b = unit._to) === null || _b === void 0 ? void 0 : _b[this.id];
50
+ const unitToThis = (_b = unit._to) === null || _b === void 0 ? void 0 : _b[this.key];
50
51
  if (typeof unitToThis === "number")
51
52
  return amount / unitToThis;
52
53
  // Two step conversion via base.
53
54
  const base = this.list.base;
54
- const thisToBase = (_c = this._to) === null || _c === void 0 ? void 0 : _c[base.id];
55
+ const thisToBase = (_c = this._to) === null || _c === void 0 ? void 0 : _c[base.key];
55
56
  if (thisToBase)
56
57
  return base._toUnit(_convert(amount, thisToBase), unit);
57
58
  // Cannot convert.
58
- throw new ConditionError(`Cannot convert "${this.id}" to "${unit.id}"`);
59
+ throw new ConditionError(`Cannot convert "${this.key}" to "${unit.key}"`);
59
60
  }
60
- /** Format a number with a given unit of measure, e.g. `12 kg` or `29.5 l` */
61
+ /** Format an amount with a given unit of measure, e.g. `12 kg` or `29.5 l` */
61
62
  format(amount, precision = this.precision) {
62
63
  return formatQuantity(amount, this.abbr, precision);
63
64
  }
64
- /** Format a number with a given unit of measure, e.g. `12 kilograms` or `29.5 liters` or `1 degree` */
65
+ /** Format an amount with a given unit of measure, e.g. `12 kilograms` or `29.5 liters` or `1 degree` */
65
66
  formatFull(amount, precision = this.precision) {
66
67
  return formatFullQuantity(amount, this.singular, this.plural, precision);
67
68
  }
69
+ /** Cram an amount with a given unit of measure, e.g. `1.25M mi` */
70
+ cram(amount) {
71
+ return cramQuantity(amount, this.abbr);
72
+ }
68
73
  }
69
- const _getUnit = (list, id) => (typeof id === "string" ? list.get(id) : id);
70
- /** Represent a list of units. */
71
- export class UnitList extends ImmutableRequiredMap {
74
+ /**
75
+ * Represent a list of units.
76
+ * - Has a known base unit at `.base`
77
+ * - Cannot have additional units added after it is created.
78
+ */
79
+ export class UnitList extends ImmutableMap {
72
80
  constructor(units) {
73
81
  super();
74
82
  for (const [id, props] of getProps(units)) {
@@ -78,6 +86,10 @@ export class UnitList extends ImmutableRequiredMap {
78
86
  Map.prototype.set.call(this, id, unit);
79
87
  }
80
88
  }
89
+ /** Convert an amount from a unit to another unit. */
90
+ convert(amount, sourceUnit, targetUnit) {
91
+ return _getUnit(this, sourceUnit).to(amount, targetUnit);
92
+ }
81
93
  }
82
94
  // Distance constants.
83
95
  const IN_PER_FT = 12;
@@ -206,53 +218,3 @@ export const TEMPERATURE_UNITS = new UnitList({
206
218
  fahrenheit: { abbr: "°F", singular: "degree Fahrenheit", plural: "degrees Fahrenheit", to: { celsius: n => (n - 32) * (5 / 9) } },
207
219
  kelvin: { abbr: "°K", singular: "degree Kelvin", plural: "degrees Kelvin", to: { celsius: n => n - 273.15 } },
208
220
  });
209
- /** Format a percentage (combines `getPercent()` and `formatUnits()` for convenience). */
210
- export const formatPercent = (numerator, denumerator, precision) => formatQuantity(getPercent(numerator, denumerator), "%", precision);
211
- /** Get the ID for a time unit based on the amount in milliseconds. */
212
- function _getTimeUnitIdentifier(ms) {
213
- const abs = Math.abs(ms);
214
- if (abs > 18 * MONTH)
215
- return "year";
216
- if (abs > 10 * WEEK)
217
- return "month";
218
- if (abs > 2 * WEEK)
219
- return "week";
220
- if (abs > DAY)
221
- return "day";
222
- if (abs > HOUR)
223
- return "hour";
224
- if (abs > 9949)
225
- return "minute";
226
- if (abs > SECOND)
227
- return "second";
228
- return "millisecond";
229
- }
230
- /** Format a full format of a duration of time using the most reasonable units e.g. `5 years` or `1 week` or `4 minutes` or `12 milliseconds`. */
231
- export function formatFullDuration(ms, precision) {
232
- const unit = TIME_UNITS.get(_getTimeUnitIdentifier(ms));
233
- return unit.formatFull(unit.from(ms), precision);
234
- }
235
- /** Format a description of a duration of time using the most reasonable units e.g. `5y` or `4m` or `12ms`. */
236
- export function formatDuration(ms, precision) {
237
- const unit = TIME_UNITS.get(_getTimeUnitIdentifier(ms));
238
- return unit.format(unit.from(ms), precision);
239
- }
240
- /** format when a data happens/happened. */
241
- function _formatWhen(formatter, target, current) {
242
- const ms = getDuration(target, current);
243
- const abs = Math.abs(ms);
244
- const duration = formatter(ms);
245
- return abs < 10 * SECOND ? "just now" : ms > 0 ? `in ${duration}` : `${duration} ago`;
246
- }
247
- /** Full when a date happens/happened, e.g. `in 10 days` or `2 hours ago` */
248
- export const formatFullWhen = (target, current) => _formatWhen(formatFullDuration, target, current);
249
- /** Compact when a date happens/happened, e.g. `in 10d` or `2h ago` or `in 1w` */
250
- export const formatWhen = (target, current) => _formatWhen(formatDuration, target, current);
251
- /** Full when a date happens, e.g. `10 days` or `2 hours` or `-1 week` */
252
- export const formatFullUntil = (target, current) => formatFullDuration(getDuration(target, current));
253
- /** Compact when a date happens, e.g. `10d` or `2h` or `-1w` */
254
- export const formatUntil = (target, current) => formatDuration(getDuration(target, current));
255
- /** Full when a date happened, e.g. `10 days` or `2 hours` or `-1 week` */
256
- export const formatFullAgo = (target, current) => formatFullDuration(getDuration(current, target));
257
- /** Compact when a date will happen, e.g. `10d` or `2h` or `-1w` */
258
- export const formatAgo = (target, current) => formatDuration(getDuration(current, target));
package/util/url.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /** Things that can be converted to a URL instance. */
2
- export declare type PossibleURL = string | URL;
3
- export declare type PossibleOptionalURL = PossibleURL | null;
2
+ export type PossibleURL = string | URL;
3
+ export type PossibleOptionalURL = PossibleURL | null;
4
4
  /** Is an unknown value a URL? */
5
5
  export declare const isURL: (v: URL | unknown) => v is URL;
6
6
  /** Assert that an unknown value is a URL. */
@@ -17,17 +17,17 @@ export interface Validatable<T> {
17
17
  validate(unsafeValue: unknown): T;
18
18
  }
19
19
  /** Function that can validate a value. */
20
- export declare type Validate<T> = (unsafeValue: unknown) => T;
20
+ export type Validate<T> = (unsafeValue: unknown) => T;
21
21
  /** Something that can validate a value. */
22
- export declare type Validator<T = unknown> = Validatable<T> | Validate<T>;
22
+ export type Validator<T = unknown> = Validatable<T> | Validate<T>;
23
23
  /** Extract the type from a validator. */
24
- export declare type ValidatorType<X> = X extends Validator<infer Y> ? Y : never;
24
+ export type ValidatorType<X> = X extends Validator<infer Y> ? Y : never;
25
25
  /** A set of named validators in `{ name: Validator }` format. */
26
- export declare type Validators<T extends Data = Data> = {
26
+ export type Validators<T extends Data = Data> = {
27
27
  readonly [K in keyof T]: Validator<T[K]>;
28
28
  };
29
29
  /** Extract the type from a set of validators. */
30
- export declare type ValidatorsType<T> = {
30
+ export type ValidatorsType<T> = {
31
31
  readonly [K in keyof T]: ValidatorType<T[K]>;
32
32
  };
33
33
  /** Validate an unknown value with a validator. */