shelving 1.32.0 → 1.36.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/db/Pagination.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getLastItem, assertLength, assertNumber, yieldMerged, toMap, LOADING } from "../util/index.js";
1
+ import { getLastItem, assertNumber, yieldMerged, toMap, LOADING, assertMaximum } from "../util/index.js";
2
2
  import { State } from "../stream/index.js";
3
3
  import { ConditionError } from "../index.js";
4
4
  /**
@@ -40,7 +40,7 @@ export class Pagination extends State {
40
40
  };
41
41
  this.ref = ref;
42
42
  assertNumber(ref.limit); // Collection must have a numeric limit to paginate (otherwise you'd be retrieving the entire set of documents).
43
- assertLength(ref.sorts, 1, Infinity); // Collection must have at least one sort order to paginate.
43
+ assertMaximum(ref.sorts.size, 1); // Collection must have at least one sort order to paginate.
44
44
  this.limit = ref.limit;
45
45
  }
46
46
  /**
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.32.0",
14
+ "version": "1.36.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -63,20 +63,20 @@
63
63
  "@types/jest": "^27.0.3",
64
64
  "@types/react": "^17.0.37",
65
65
  "@types/react-dom": "^17.0.11",
66
- "@typescript-eslint/eslint-plugin": "^5.6.0",
67
- "@typescript-eslint/parser": "^5.6.0",
68
- "eslint": "^8.4.1",
66
+ "@typescript-eslint/eslint-plugin": "^5.7.0",
67
+ "@typescript-eslint/parser": "^5.7.0",
68
+ "eslint": "^8.5.0",
69
69
  "eslint-config-prettier": "^8.3.0",
70
70
  "eslint-plugin-import": "^2.25.3",
71
71
  "eslint-plugin-prettier": "^4.0.0",
72
72
  "firebase": "^9.6.1",
73
- "jest": "^27.4.4",
73
+ "jest": "^27.4.5",
74
74
  "jest-ts-webcompat-resolver": "^1.0.0",
75
75
  "prettier": "^2.5.1",
76
76
  "react": "^17.0.2",
77
77
  "react-dom": "^17.0.2",
78
- "ts-jest": "^27.1.1",
79
- "typescript": "^4.5.3"
78
+ "ts-jest": "^27.1.2",
79
+ "typescript": "^4.5.4"
80
80
  },
81
81
  "peerDependencies": {
82
82
  "@google-cloud/firestore": ">=4.0.0",
@@ -13,5 +13,6 @@ export declare class Filters<T extends Data> extends Rules<T, Filter<T>> impleme
13
13
  gt<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
14
14
  gte<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
15
15
  match(entry: Entry<T>): boolean;
16
+ get unfiltered(): this;
16
17
  transform(iterable: Results<T>): Results<T>;
17
18
  }
package/query/Filters.js CHANGED
@@ -3,6 +3,7 @@ import { ArrayContainsFilter, EqualFilter, GreaterThanEqualFilter, GreaterThanFi
3
3
  import { Rules } from "./Rules.js";
4
4
  /** A set of filters. */
5
5
  export class Filters extends Rules {
6
+ // Implement `Filterable`
6
7
  is(key, value) {
7
8
  return { __proto__: Object.getPrototypeOf(this), ...this, _rules: [...this._rules, new EqualFilter(key, value)] };
8
9
  }
@@ -33,6 +34,10 @@ export class Filters extends Rules {
33
34
  return false;
34
35
  return true;
35
36
  }
37
+ get unfiltered() {
38
+ return { __proto__: Object.getPrototypeOf(this), ...this, _rules: [] };
39
+ }
40
+ // Implement `Rule`
36
41
  transform(iterable) {
37
42
  return this._rules.length ? yieldFiltered(iterable, this) : iterable;
38
43
  }
package/query/Query.d.ts CHANGED
@@ -17,9 +17,11 @@ export declare class Query<T extends Data> extends Rule<T> implements Queryable<
17
17
  lte<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
18
18
  gt<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
19
19
  gte<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
20
+ get unfiltered(): this;
20
21
  match(entry: Entry<T>): boolean;
21
- asc(key?: QueryKey<T>): this;
22
- desc(key?: QueryKey<T>): this;
22
+ asc(key: QueryKey<T>): this;
23
+ desc(key: QueryKey<T>): this;
24
+ get unsorted(): this;
23
25
  rank(left: Entry<T>, right: Entry<T>): number;
24
26
  /** Return a new instance of this class with a limit defined. */
25
27
  max(limit: number | null): this;
package/query/Query.js CHANGED
@@ -40,16 +40,22 @@ export class Query extends Rule {
40
40
  gte(key, value) {
41
41
  return { __proto__: Object.getPrototypeOf(this), ...this, filters: this.filters.gte(key, value) };
42
42
  }
43
+ get unfiltered() {
44
+ return { __proto__: Object.getPrototypeOf(this), ...this, filters: this.filters.unfiltered };
45
+ }
43
46
  match(entry) {
44
47
  return this.filters.match(entry);
45
48
  }
46
49
  // Implement `Sortable`
47
- asc(key = "id") {
50
+ asc(key) {
48
51
  return { __proto__: Object.getPrototypeOf(this), ...this, sorts: this.sorts.asc(key) };
49
52
  }
50
- desc(key = "id") {
53
+ desc(key) {
51
54
  return { __proto__: Object.getPrototypeOf(this), ...this, sorts: this.sorts.desc(key) };
52
55
  }
56
+ get unsorted() {
57
+ return { __proto__: Object.getPrototypeOf(this), ...this, sorts: this.sorts.unsorted };
58
+ }
53
59
  rank(left, right) {
54
60
  return this.sorts.rank(left, right);
55
61
  }
package/query/Rules.d.ts CHANGED
@@ -8,7 +8,7 @@ export declare abstract class Rules<T extends Data, R extends Rule<T>> extends R
8
8
  /** Get the last rule. */
9
9
  get last(): R | undefined;
10
10
  /** Get the number of rules. */
11
- get length(): number;
11
+ get size(): number;
12
12
  constructor(...rules: R[]);
13
13
  toString(): string;
14
14
  /** Iterate over the rules. */
package/query/Rules.js CHANGED
@@ -15,7 +15,7 @@ export class Rules extends Rule {
15
15
  return this._rules[this._rules.length - 1];
16
16
  }
17
17
  /** Get the number of rules. */
18
- get length() {
18
+ get size() {
19
19
  return this._rules.length;
20
20
  }
21
21
  toString() {
package/query/Sorts.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Rules } from "./Rules.js";
6
6
  export declare class Sorts<T extends Data> extends Rules<T, Sort<T>> implements Sortable<T> {
7
7
  asc(key: QueryKey<T>): this;
8
8
  desc(key: QueryKey<T>): this;
9
+ get unsorted(): this;
9
10
  rank(left: Entry<T>, right: Entry<T>): number;
10
11
  transform(iterable: Results<T>): Results<T>;
11
12
  }
package/query/Sorts.js CHANGED
@@ -3,20 +3,25 @@ import { AscendingSort, DescendingSort } from "./Sort.js";
3
3
  import { Rules } from "./Rules.js";
4
4
  /** A set of sorts. */
5
5
  export class Sorts extends Rules {
6
+ // Implement `Sortable`
6
7
  asc(key) {
7
8
  return { __proto__: Object.getPrototypeOf(this), ...this, _rules: [...this._rules, new AscendingSort(key)] };
8
9
  }
9
10
  desc(key) {
10
11
  return { __proto__: Object.getPrototypeOf(this), ...this, _rules: [...this._rules, new DescendingSort(key)] };
11
12
  }
13
+ get unsorted() {
14
+ return { __proto__: Object.getPrototypeOf(this), ...this, _rules: [] };
15
+ }
12
16
  rank(left, right) {
13
- for (const rule of this) {
17
+ for (const rule of this._rules) {
14
18
  const l = rule.rank(left, right);
15
19
  if (l !== 0)
16
20
  return l;
17
21
  }
18
22
  return 0;
19
23
  }
24
+ // Implement `Rule`
20
25
  transform(iterable) {
21
26
  return this._rules.length ? sortItems(iterable, this) : iterable;
22
27
  }
package/query/types.d.ts CHANGED
@@ -16,6 +16,9 @@ export interface Filterable<T extends Data> extends Matchable<Entry<T>, void> {
16
16
  lte<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
17
17
  gt<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
18
18
  gte<K extends QueryKey<T>>(key: K, value: K extends "id" ? string : T[K]): this;
19
+ /** Return a new instance of this class with no sorts specified. */
20
+ unfiltered: this;
21
+ /** Match an entry against the filters specified for this object. */
19
22
  match(entry: Entry<T>): boolean;
20
23
  }
21
24
  /**
@@ -24,9 +27,11 @@ export interface Filterable<T extends Data> extends Matchable<Entry<T>, void> {
24
27
  */
25
28
  export interface Sortable<T extends Data> extends Rankable<Entry<T>> {
26
29
  /** Return a new instance of this class with an ascending order sort defined. */
27
- asc(key?: QueryKey<T>): this;
30
+ asc(key: QueryKey<T>): this;
28
31
  /** Return a new instance of this class with a descending order sort defined. */
29
- desc(key?: QueryKey<T>): this;
32
+ desc(key: QueryKey<T>): this;
33
+ /** Return a new instance of this class with no sorts specified. */
34
+ unsorted: this;
30
35
  }
31
36
  /** Possible operator references. */
32
37
  export declare type SortDirection = "ASC" | "DESC";
package/util/array.d.ts CHANGED
@@ -163,3 +163,15 @@ export declare function removeItems<T>(arr: MutableArray<T>, items: Iterable<T>)
163
163
  export declare function uniqueArray<T>(input: Iterable<T>): ImmutableArray<T>;
164
164
  /** Apply a limit to an array. */
165
165
  export declare function limitArray<T>(arr: ImmutableArray<T>, limit: number): ImmutableArray<T>;
166
+ /** Does an array have the specified minimum length. */
167
+ export declare function isMinimumLength<T>(arr: ImmutableArray<T>, min?: 1): arr is [T, ...T[]];
168
+ export declare function isMinimumLength<T>(arr: ImmutableArray<T>, min: 2): arr is [T, T, ...T[]];
169
+ export declare function isMinimumLength<T>(arr: ImmutableArray<T>, min: 3): arr is [T, T, T, ...T[]];
170
+ export declare function isMinimumLength<T>(arr: ImmutableArray<T>, min: 4): arr is [T, T, T, T, ...T[]];
171
+ export declare function isMinimumLength<T>(arr: ImmutableArray<T>, min: number): arr is [T, T, T, T, T, ...T[]];
172
+ /** Get an array if it has the specified minimum length. */
173
+ export declare function getMinimumLength<T>(arr: ImmutableArray<T>, min?: 1): [T, ...T[]];
174
+ export declare function getMinimumLength<T>(arr: ImmutableArray<T>, min: 2): [T, T, ...T[]];
175
+ export declare function getMinimumLength<T>(arr: ImmutableArray<T>, min: 3): [T, T, T, ...T[]];
176
+ export declare function getMinimumLength<T>(arr: ImmutableArray<T>, min: 4): [T, T, T, T, ...T[]];
177
+ export declare function getMinimumLength<T>(arr: ImmutableArray<T>, min: number): [T, T, T, T, T, ...T[]];
package/util/array.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { AssertionError } from "../error/index.js";
1
2
  /** Is an unknown value an array? */
2
3
  export const isArray = (v) => v instanceof Array;
3
4
  /** Is an unknown value an item in a specified array? */
@@ -244,3 +245,11 @@ export function uniqueArray(input) {
244
245
  export function limitArray(arr, limit) {
245
246
  return limit > arr.length ? arr : arr.slice(0, limit);
246
247
  }
248
+ export function isMinimumLength(arr, min = 1) {
249
+ return arr.length >= min;
250
+ }
251
+ export function getMinimumLength(arr, min = 1) {
252
+ if (arr.length >= min)
253
+ return arr;
254
+ throw new AssertionError(`Must have minimum length ${min}`, arr);
255
+ }
package/util/assert.d.ts CHANGED
@@ -24,15 +24,21 @@ export declare function assertProp<K extends string | number | symbol, T extends
24
24
  [L in K]: unknown;
25
25
  }>(value: T | unknown, key: K): asserts value is T;
26
26
  /** Assert that a value is an array. */
27
- export declare function assertArray<T extends ImmutableArray>(value: T | unknown): asserts value is T;
27
+ export declare function assertArray<T>(value: ImmutableArray<T> | unknown): asserts value is ImmutableArray<T>;
28
28
  /** Assert that a value has a specific length (or length is in a specific range). */
29
- export declare function assertLength<T extends {
30
- length: number;
31
- }>(value: T | unknown, min: number, max?: number): asserts value is T;
29
+ export declare function assertMinimumLength<T>(value: ImmutableArray<T> | unknown, min?: 1): asserts value is [T, ...T[]];
30
+ export declare function assertMinimumLength<T>(value: ImmutableArray<T> | unknown, min: 2): asserts value is [T, T, ...T[]];
31
+ export declare function assertMinimumLength<T>(value: ImmutableArray<T> | unknown, min: 3): asserts value is [T, T, T, ...T[]];
32
+ export declare function assertMinimumLength<T>(value: ImmutableArray<T> | unknown, min: 4): asserts value is [T, T, T, T, ...T[]];
33
+ export declare function assertMinimumLength<T>(value: ImmutableArray<T> | unknown, min: number): asserts value is [T, T, T, T, T, ...T[]];
34
+ /** Assert that a value has a specific length (or length is in a specific range). */
35
+ export declare function assertLength<T>(value: ImmutableArray<T> | unknown, min: number, max?: number): asserts value is ImmutableArray<T>;
36
+ /** Assert that a value is a number greater than. */
37
+ export declare function assertBetween(value: number | unknown, min: number, max: number): asserts value is number;
32
38
  /** Assert that a value is a number greater than. */
33
- export declare function assertGreater(value: number | unknown, target: number): asserts value is number;
39
+ export declare function assertMaximum(value: number | unknown, max: number): asserts value is number;
34
40
  /** Assert that a value is a number less than. */
35
- export declare function assertLess(value: number | unknown, target: number): asserts value is number;
41
+ export declare function assertMinimum(value: number | unknown, min: number): asserts value is number;
36
42
  /** Assert that a value is an instance of something. */
37
43
  export declare function assertInstance<T>(value: T | unknown, type: Class<T>): asserts value is T;
38
44
  /** Assert that a value is a function. */
@@ -42,8 +48,8 @@ export declare function assertValue<T>(value: T | typeof NOVALUE): asserts value
42
48
  /** Assert that a value is not the `NOVALUE` constant. */
43
49
  export declare function assertDefined<T>(value: T | undefined): asserts value is T;
44
50
  /** Expect a synchronous value. */
45
- export declare function assertSync<T>(value: Promise<T> | T): asserts value is T;
51
+ export declare function assertSynchronous<T>(value: Promise<T> | T): asserts value is T;
46
52
  /** Expect an asynchronous value. */
47
- export declare function assertAsync<T>(value: PromiseLike<T> | T): asserts value is PromiseLike<T>;
53
+ export declare function assertAsynchronous<T>(value: PromiseLike<T> | T): asserts value is PromiseLike<T>;
48
54
  /** Expect a promise. */
49
55
  export declare function assertPromise<T>(value: Promise<T> | T): asserts value is Promise<T>;
package/util/assert.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { AssertionError } from "../error/index.js";
2
2
  import { debug } from "./debug.js";
3
3
  import { isObject } from "./object.js";
4
+ import { isArray } from "./array.js";
4
5
  import { NOVALUE } from "./constants.js";
5
6
  import { isAsync } from "./async.js";
6
7
  /** Assert a boolean condition is true. */
@@ -53,20 +54,29 @@ export function assertArray(value) {
53
54
  if (!(value instanceof Array))
54
55
  throw new AssertionError(`Must be array`, value);
55
56
  }
57
+ export function assertMinimumLength(value, min = 1) {
58
+ if (!isArray(value) || value.length < min)
59
+ throw new AssertionError(`Must be array with minimum length ${min}`, value);
60
+ }
56
61
  /** Assert that a value has a specific length (or length is in a specific range). */
57
62
  export function assertLength(value, min, max = min) {
58
- if (!isObject(value) || typeof value.length !== "number" || value.length < min || value.length > max)
59
- throw new AssertionError(`Must have length ${min}–${max}`, value);
63
+ if (!isArray(value) || value.length < min || value.length > max)
64
+ throw new AssertionError(`Must be array with length ${min}-${max}`, value);
65
+ }
66
+ /** Assert that a value is a number greater than. */
67
+ export function assertBetween(value, min, max) {
68
+ if (typeof value !== "number" || value < min || value > max)
69
+ throw new AssertionError(`Must be number between ${min}-${max}`, value);
60
70
  }
61
71
  /** Assert that a value is a number greater than. */
62
- export function assertGreater(value, target) {
63
- if (typeof value !== "number" || value <= target)
64
- throw new AssertionError(`Must be greater than ${target}`, value);
72
+ export function assertMaximum(value, max) {
73
+ if (typeof value !== "number" || value > max)
74
+ throw new AssertionError(`Must be number with maximum ${max}`, value);
65
75
  }
66
76
  /** Assert that a value is a number less than. */
67
- export function assertLess(value, target) {
68
- if (typeof value !== "number" || value >= target)
69
- throw new AssertionError(`Must be less than ${target}`, value);
77
+ export function assertMinimum(value, min) {
78
+ if (typeof value !== "number" || value < min)
79
+ throw new AssertionError(`Must be number with minimum ${min}`, value);
70
80
  }
71
81
  /** Assert that a value is an instance of something. */
72
82
  export function assertInstance(value, type) {
@@ -89,12 +99,12 @@ export function assertDefined(value) {
89
99
  throw new AssertionError("Must be defined", value);
90
100
  }
91
101
  /** Expect a synchronous value. */
92
- export function assertSync(value) {
102
+ export function assertSynchronous(value) {
93
103
  if (isAsync(value))
94
104
  throw new AssertionError("Must be synchronous", value);
95
105
  }
96
106
  /** Expect an asynchronous value. */
97
- export function assertAsync(value) {
107
+ export function assertAsynchronous(value) {
98
108
  if (!isAsync(value))
99
109
  throw new AssertionError("Must be asynchronous", value);
100
110
  }
package/util/filter.d.ts CHANGED
@@ -12,32 +12,28 @@ export declare type Matcher<L, R> = Matchable<L, R> | ((item: L, target: R) => b
12
12
  /** Match two values using a `Matcher`. */
13
13
  export declare function match<L>(item: L, matcher: Matcher<L, void>): boolean;
14
14
  export declare function match<L, R>(item: L, matcher: Matcher<L, R>, target: R): boolean;
15
- /** Match whether an item is equal to a target. */
16
15
  export declare const IS: (item: unknown, target: unknown) => boolean;
17
- /** Match whether an item is not equal to match a target. */
18
16
  export declare const NOT: (item: unknown, target: unknown) => boolean;
19
- /** Match whether an item exists in an array of targets. */
20
17
  export declare const IN: (item: unknown, targets: ImmutableArray<unknown>) => boolean;
21
- /** Match whether an array of items contains a target. */
22
18
  export declare const CONTAINS: (items: unknown, target: unknown) => boolean;
23
- /** Match whether an item is less than a target. */
24
19
  export declare const LT: (item: unknown, target: unknown) => boolean;
25
- /** Match whether an item is less than or equal to a target. */
26
20
  export declare const LTE: (item: unknown, target: unknown) => boolean;
27
- /** Match whether an item is greater than a target. */
28
21
  export declare const GT: (item: unknown, target: unknown) => boolean;
29
- /** Match whether an item is greater than or equal to a target. */
30
22
  export declare const GTE: (item: unknown, target: unknown) => boolean;
31
- /** Match whether the key of an entry is equal to a target. */
32
- export declare const KEY_IS: ([item]: Entry<unknown>, target: string) => boolean;
33
- /** Match whether the key of an entry is in an array of targets. */
34
- export declare const KEY_IN: ([item]: Entry<unknown>, targets: ImmutableArray<string>) => boolean;
35
- /** Match whether the value of an entry is equal to a target. */
36
- export declare const VALUE_IS: ([, item]: Entry<unknown>, target: unknown) => boolean;
37
- /** Match whether the value of an entry is in an array of targets. */
38
- export declare const VALUE_IN: ([, item]: Entry<unknown>, targets: ImmutableArray<unknown>) => boolean;
39
- /** Match whether the value of an entry is defined. */
40
- export declare const VALUE_DEFINED: ([, item]: Entry<unknown>) => boolean;
23
+ export declare const KEY_IS: ([key]: Entry<unknown>, target: string) => boolean;
24
+ export declare const KEY_NOT: ([key]: Entry<unknown>, targets: ImmutableArray<string>) => boolean;
25
+ export declare const KEY_IN: ([key]: Entry<unknown>, targets: ImmutableArray<string>) => boolean;
26
+ export declare const KEY_LT: ([key]: Entry<unknown>, target: unknown) => boolean;
27
+ export declare const KEY_LTE: ([key]: Entry<unknown>, target: unknown) => boolean;
28
+ export declare const KEY_GT: ([key]: Entry<unknown>, target: unknown) => boolean;
29
+ export declare const KEY_GTE: ([key]: Entry<unknown>, target: unknown) => boolean;
30
+ export declare const VALUE_IS: ([, value]: Entry<unknown>, target: unknown) => boolean;
31
+ export declare const VALUE_NOT: ([, value]: Entry<unknown>, target: unknown) => boolean;
32
+ export declare const VALUE_IN: ([, value]: Entry<unknown>, targets: ImmutableArray<unknown>) => boolean;
33
+ export declare const VALUE_LT: ([, value]: Entry<unknown>, target: unknown) => boolean;
34
+ export declare const VALUE_LTE: ([, value]: Entry<unknown>, target: unknown) => boolean;
35
+ export declare const VALUE_GT: ([, value]: Entry<unknown>, target: unknown) => boolean;
36
+ export declare const VALUE_GTE: ([, value]: Entry<unknown>, target: unknown) => boolean;
41
37
  /** Filter an iterable set of items using a matcher (and optionally a target value). */
42
38
  export declare function yieldFiltered<L>(input: Iterable<L>, matcher: Matcher<L, void>): Iterable<L>;
43
39
  export declare function yieldFiltered<L, R>(input: Iterable<L>, matcher: Matcher<L, R>, target: R): Iterable<L>;
package/util/filter.js CHANGED
@@ -3,32 +3,31 @@ import { transform } from "./transform.js";
3
3
  export function match(item, matcher, target) {
4
4
  return typeof matcher === "function" ? matcher(item, target) : matcher.match(item, target);
5
5
  }
6
- /** Match whether an item is equal to a target. */
6
+ // Regular matchers.
7
7
  export const IS = (item, target) => item === target;
8
- /** Match whether an item is not equal to match a target. */
9
8
  export const NOT = (item, target) => item !== target;
10
- /** Match whether an item exists in an array of targets. */
11
9
  export const IN = (item, targets) => targets.includes(item);
12
- /** Match whether an array of items contains a target. */
13
10
  export const CONTAINS = (items, target) => items instanceof Array && items.includes(target);
14
- /** Match whether an item is less than a target. */
15
11
  export const LT = (item, target) => ASC(item, target) < 0;
16
- /** Match whether an item is less than or equal to a target. */
17
12
  export const LTE = (item, target) => ASC(item, target) <= 0;
18
- /** Match whether an item is greater than a target. */
19
13
  export const GT = (item, target) => ASC(item, target) > 0;
20
- /** Match whether an item is greater than or equal to a target. */
21
14
  export const GTE = (item, target) => ASC(item, target) >= 0;
22
- /** Match whether the key of an entry is equal to a target. */
23
- export const KEY_IS = ([item], target) => item === target;
24
- /** Match whether the key of an entry is in an array of targets. */
25
- export const KEY_IN = ([item], targets) => targets.includes(item);
26
- /** Match whether the value of an entry is equal to a target. */
27
- export const VALUE_IS = ([, item], target) => item === target;
28
- /** Match whether the value of an entry is in an array of targets. */
29
- export const VALUE_IN = ([, item], targets) => targets.includes(item);
30
- /** Match whether the value of an entry is defined. */
31
- export const VALUE_DEFINED = ([, item]) => item !== undefined;
15
+ // Entry key matchers.
16
+ export const KEY_IS = ([key], target) => IS(key, target);
17
+ export const KEY_NOT = ([key], targets) => IN(key, targets);
18
+ export const KEY_IN = ([key], targets) => IN(key, targets);
19
+ export const KEY_LT = ([key], target) => LT(key, target);
20
+ export const KEY_LTE = ([key], target) => LTE(key, target);
21
+ export const KEY_GT = ([key], target) => GT(key, target);
22
+ export const KEY_GTE = ([key], target) => GTE(key, target);
23
+ // Entry value matchers.
24
+ export const VALUE_IS = ([, value], target) => IS(value, target);
25
+ export const VALUE_NOT = ([, value], target) => NOT(value, target);
26
+ export const VALUE_IN = ([, value], targets) => IN(value, targets);
27
+ export const VALUE_LT = ([, value], target) => LT(value, target);
28
+ export const VALUE_LTE = ([, value], target) => LTE(value, target);
29
+ export const VALUE_GT = ([, value], target) => GT(value, target);
30
+ export const VALUE_GTE = ([, value], target) => GTE(value, target);
32
31
  export function* yieldFiltered(input, matcher, target) {
33
32
  for (const item of input)
34
33
  if (match(item, matcher, target))
package/util/number.d.ts CHANGED
@@ -11,6 +11,11 @@ export declare const IS_NUMBER: (v: unknown) => v is number;
11
11
  * - Everything else returns `null`
12
12
  */
13
13
  export declare function toNumber(value: unknown): number | null;
14
+ /**
15
+ * Assertively convert an unknown value to a finite number.
16
+ * @throws `AssertionError` if the value cannot be converted.
17
+ */
18
+ export declare function getNumber(value: unknown): number;
14
19
  /**
15
20
  * Round numbers to a given step.
16
21
  *
package/util/number.js CHANGED
@@ -21,6 +21,16 @@ export function toNumber(value) {
21
21
  return null;
22
22
  }
23
23
  const NUMERIC = /[^0-9-.]/g;
24
+ /**
25
+ * Assertively convert an unknown value to a finite number.
26
+ * @throws `AssertionError` if the value cannot be converted.
27
+ */
28
+ export function getNumber(value) {
29
+ const num = toNumber(value);
30
+ if (num === null)
31
+ throw new AssertionError("Must be number", value);
32
+ return num;
33
+ }
24
34
  /**
25
35
  * Round numbers to a given step.
26
36
  *