shelving 1.60.0 → 1.62.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 CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.60.0",
14
+ "version": "1.62.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -61,8 +61,8 @@
61
61
  "devDependencies": {
62
62
  "@google-cloud/firestore": "^5.0.2",
63
63
  "@types/jest": "^27.5.1",
64
- "@types/react": "^17.0.45",
65
- "@types/react-dom": "^17.0.17",
64
+ "@types/react": "^18.0.9",
65
+ "@types/react-dom": "^18.0.4",
66
66
  "@typescript-eslint/eslint-plugin": "^5.23.0",
67
67
  "@typescript-eslint/parser": "^5.23.0",
68
68
  "eslint": "^8.15.0",
@@ -70,12 +70,12 @@
70
70
  "eslint-plugin-import": "^2.26.0",
71
71
  "eslint-plugin-prettier": "^4.0.0",
72
72
  "firebase": "^9.8.1",
73
- "jest": "^27.5.1",
73
+ "jest": "^28.1.0",
74
74
  "jest-ts-webcompat-resolver": "^1.0.0",
75
75
  "prettier": "^2.6.2",
76
- "react": "^17.0.2",
77
- "react-dom": "^17.0.2",
78
- "ts-jest": "^27.1.4",
76
+ "react": "^18.1.0",
77
+ "react-dom": "^18.1.0",
78
+ "ts-jest": "^28.0.2",
79
79
  "typescript": "^4.6.4"
80
80
  },
81
81
  "peerDependencies": {
@@ -36,5 +36,5 @@ export declare function useDocument<T extends Data>(ref: DocumentReference<T> |
36
36
  export declare function useAsyncDocumentData<T extends Data>(ref: DocumentReference<T>, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>>;
37
37
  export declare function useAsyncDocumentData<T extends Data>(ref: DocumentReference<T> | undefined, maxAge?: number | true): DocumentData<T> | PromiseLike<DocumentData<T>> | undefined;
38
38
  /** Use the data of a document or `undefined` if the query has no matching results. */
39
- export declare function useDocumentData<T extends Data>(ref: DocumentReference<T>, maxAge?: number | true): T;
40
- export declare function useDocumentData<T extends Data>(ref: DocumentReference<T> | undefined, maxAge?: number | true): T | undefined;
39
+ export declare function useDocumentData<T extends Data>(ref: DocumentReference<T>, maxAge?: number | true): DocumentData<T>;
40
+ export declare function useDocumentData<T extends Data>(ref: DocumentReference<T> | undefined, maxAge?: number | true): DocumentData<T> | undefined;
package/util/iterate.js CHANGED
@@ -29,7 +29,7 @@ export function countItems(items) {
29
29
  export function countIterations(items) {
30
30
  let count = 0;
31
31
  for (const unused of items)
32
- count++; // eslint-disable-line @typescript-eslint/no-unused-vars
32
+ count++;
33
33
  return count;
34
34
  }
35
35
  /**
@@ -46,7 +46,7 @@ export function hasItems(items) {
46
46
  */
47
47
  export function hasIterations(items) {
48
48
  for (const unused of items)
49
- return true; // eslint-disable-line @typescript-eslint/no-unused-vars
49
+ return true;
50
50
  return false;
51
51
  }
52
52
  /**
package/util/object.js CHANGED
@@ -38,7 +38,7 @@ export const withEntries = withProps;
38
38
  */
39
39
  export function withoutEntry(input, key, value) {
40
40
  if (isKey(input, key) && (value === undefined || input[key] === value)) {
41
- const { [key]: unused, ...output } = input; // eslint-disable-line @typescript-eslint/no-unused-vars
41
+ const { [key]: unused, ...output } = input;
42
42
  return output;
43
43
  }
44
44
  return input;
@@ -1,5 +1,5 @@
1
1
  import { ConditionError } from "../error/index.js";
2
- import { BLACKHOLE, dispatch } from "./function.js";
2
+ import { dispatch } from "./function.js";
3
3
  import { logError } from "./error.js";
4
4
  import { isData } from "./data.js";
5
5
  import { transform } from "./transform.js";
@@ -164,5 +164,5 @@ export function awaitNext(source) {
164
164
  }
165
165
  /** Get a promise that resolves when a source subscribable is complete. */
166
166
  export function awaitComplete(source) {
167
- return new Promise((complete, error) => new ThroughObserver({ next: BLACKHOLE, complete, error }).from(source));
167
+ return new Promise((complete, error) => new ThroughObserver({ complete, error }).from(source));
168
168
  }
package/util/string.d.ts CHANGED
@@ -81,3 +81,9 @@ export declare function yieldWords(value: string): Generator<string, void, void>
81
81
  export declare const isUppercaseLetter: (str: string) => boolean;
82
82
  /** Is the first character of a string a lowercase letter? */
83
83
  export declare const isLowercaseLetter: (str: string) => boolean;
84
+ /**
85
+ * Limit a string to a given length.
86
+ * - Stops at the last space inside `maxLength`
87
+ * - Appends an `…` ellipses after the string (but only if a limit is applied).
88
+ */
89
+ export declare function limitString(str: string, maxLength: number, append?: string): string;
package/util/string.js CHANGED
@@ -139,3 +139,14 @@ const MATCH_WORD = /[^\s"]+|"([^"]*)"/g; // Runs of characters without spaces, o
139
139
  export const isUppercaseLetter = (str) => isBetween(str.charCodeAt(0), 65, 90);
140
140
  /** Is the first character of a string a lowercase letter? */
141
141
  export const isLowercaseLetter = (str) => isBetween(str.charCodeAt(0), 97, 122);
142
+ /**
143
+ * Limit a string to a given length.
144
+ * - Stops at the last space inside `maxLength`
145
+ * - Appends an `…` ellipses after the string (but only if a limit is applied).
146
+ */
147
+ export function limitString(str, maxLength, append = "…") {
148
+ if (str.length < maxLength)
149
+ return str;
150
+ const lastSpace = str.lastIndexOf(" ", maxLength);
151
+ return `${str.slice(0, lastSpace > 0 ? lastSpace : maxLength).trimEnd()}${append}`;
152
+ }
package/util/units.d.ts CHANGED
@@ -53,3 +53,8 @@ export declare const formatUnits: (num: number, unit: UnitReference, maxPrecisio
53
53
  * @param maxPrecision Number of decimal places to round the number to e.g. `2`
54
54
  */
55
55
  export declare const formatFullUnits: (num: number, unit: UnitReference, maxPrecision?: number | undefined, minPrecision?: number | undefined) => string;
56
+ /**
57
+ * Format a percentage.
58
+ * - Combines `getPercent()` and `formatUnits()` for convenience.
59
+ */
60
+ export declare const formatPercent: (numerator: number, denumerator: number, maxPrecision?: number | undefined, minPrecision?: number | undefined) => string;
package/util/units.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AssertionError } from "../error/index.js";
2
- import { formatFullQuantity, formatQuantity, MILLION } from "./number.js";
2
+ import { formatFullQuantity, formatQuantity, getPercent, MILLION } from "./number.js";
3
3
  import { NNBSP } from "./string.js";
4
4
  /** One second in millseconds. */
5
5
  export const SECOND = 1000;
@@ -80,3 +80,8 @@ export const formatUnits = (num, unit, maxPrecision, minPrecision) => formatQuan
80
80
  * @param maxPrecision Number of decimal places to round the number to e.g. `2`
81
81
  */
82
82
  export const formatFullUnits = (num, unit, maxPrecision, minPrecision) => formatFullQuantity(num, UNITS[unit].singular || unit, UNITS[unit].plural || `${unit}s`, maxPrecision, minPrecision);
83
+ /**
84
+ * Format a percentage.
85
+ * - Combines `getPercent()` and `formatUnits()` for convenience.
86
+ */
87
+ export const formatPercent = (numerator, denumerator, maxPrecision, minPrecision) => formatQuantity(getPercent(numerator, denumerator), UNITS.percent.suffix, maxPrecision, minPrecision);