shelving 1.49.3 → 1.50.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 +6 -6
- package/util/color.d.ts +2 -1
- package/util/color.js +8 -6
- package/util/iterate.d.ts +5 -0
- package/util/iterate.js +6 -0
- package/util/random.js +2 -2
- package/util/string.d.ts +2 -2
- package/util/string.js +7 -7
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"state-management",
|
|
12
12
|
"query-builder"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.50.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.4.0",
|
|
64
64
|
"@types/react": "^17.0.38",
|
|
65
65
|
"@types/react-dom": "^17.0.11",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
67
|
-
"@typescript-eslint/parser": "^5.
|
|
68
|
-
"eslint": "^8.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
|
67
|
+
"@typescript-eslint/parser": "^5.10.1",
|
|
68
|
+
"eslint": "^8.8.0",
|
|
69
69
|
"eslint-config-prettier": "^8.3.0",
|
|
70
70
|
"eslint-plugin-import": "^2.25.4",
|
|
71
71
|
"eslint-plugin-prettier": "^4.0.0",
|
|
72
|
-
"firebase": "^9.6.
|
|
72
|
+
"firebase": "^9.6.5",
|
|
73
73
|
"jest": "^27.4.7",
|
|
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
78
|
"ts-jest": "^27.1.3",
|
|
79
|
-
"typescript": "^4.5.
|
|
79
|
+
"typescript": "^4.5.5"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
82
|
"@google-cloud/firestore": ">=4.0.0",
|
package/util/color.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Things that can be converted to a `Color` instance. */
|
|
2
2
|
export declare type PossibleColor = Color | string;
|
|
3
|
+
export declare type PossibleOptionalColor = PossibleColor | null;
|
|
3
4
|
/** Represent a color. */
|
|
4
5
|
export declare class Color {
|
|
5
6
|
readonly r: number;
|
|
@@ -20,7 +21,7 @@ export declare class Color {
|
|
|
20
21
|
/** Convert a number or string to a color channel number that's within bounds (strings like `0a` or `ff` are parsed as hexadecimal). */
|
|
21
22
|
export declare function getColorChannel(channel: number | string): number;
|
|
22
23
|
/** Convert a possible color to a `Color` instance or `null` */
|
|
23
|
-
export declare function toColor(color:
|
|
24
|
+
export declare function toColor(color: unknown): Color | null;
|
|
24
25
|
/** Convert a possible color to a `Color` instance */
|
|
25
26
|
export declare function getColor(input: PossibleColor): Color;
|
|
26
27
|
/** Is a color light? */
|
package/util/color.js
CHANGED
|
@@ -49,12 +49,14 @@ export function getColorChannel(channel) {
|
|
|
49
49
|
export function toColor(color) {
|
|
50
50
|
if (color instanceof Color)
|
|
51
51
|
return color;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
if (typeof color === "string") {
|
|
53
|
+
const hex3 = color.match(HEX3);
|
|
54
|
+
if (hex3)
|
|
55
|
+
return new Color(hex3[1], hex3[2], hex3[3]);
|
|
56
|
+
const hex6 = color.match(HEX6);
|
|
57
|
+
if (hex6)
|
|
58
|
+
return new Color(hex6[1], hex6[2], hex6[3], hex6[4]);
|
|
59
|
+
}
|
|
58
60
|
return null;
|
|
59
61
|
}
|
|
60
62
|
/** Convert a possible color to a `Color` instance */
|
package/util/iterate.d.ts
CHANGED
|
@@ -52,6 +52,11 @@ export declare function yieldRange(start: number, end: number): Generator<number
|
|
|
52
52
|
* - Checks `items.size` or `items.length` first to see if the limit is necessary.
|
|
53
53
|
*/
|
|
54
54
|
export declare function limitItems<T>(items: Iterable<T>, limit: number): TypedIterable<T, void, void>;
|
|
55
|
+
/**
|
|
56
|
+
* Reduce an iterable set of items using a reducer function.
|
|
57
|
+
*/
|
|
58
|
+
export declare function reduceItems<T, R>(items: Iterable<T>, reducer: (previous: R, item: T) => R, initial: R): R;
|
|
59
|
+
export declare function reduceItems<T, R>(items: Iterable<T>, reducer: (previous: R | undefined, item: T) => R, initial?: R): R | undefined;
|
|
55
60
|
/** Yield items from a source iterable until we hit a maximum iteration count. */
|
|
56
61
|
export declare function yieldUntilLimit<T>(source: Iterable<T>, limit: number): Generator<T, void, void>;
|
|
57
62
|
/** Infinite iterator that yields the result of calling a function with a given set of arguments. */
|
package/util/iterate.js
CHANGED
|
@@ -70,6 +70,12 @@ export function limitItems(items, limit) {
|
|
|
70
70
|
const size = (_a = getKnownSize(items)) !== null && _a !== void 0 ? _a : Infinity;
|
|
71
71
|
return size <= limit ? items : yieldUntilLimit(items, limit);
|
|
72
72
|
}
|
|
73
|
+
export function reduceItems(items, reducer, initial) {
|
|
74
|
+
let current = initial;
|
|
75
|
+
for (const item of items)
|
|
76
|
+
current = reducer(current, item);
|
|
77
|
+
return current;
|
|
78
|
+
}
|
|
73
79
|
/** Yield items from a source iterable until we hit a maximum iteration count. */
|
|
74
80
|
export function* yieldUntilLimit(source, limit) {
|
|
75
81
|
const iterator = source[Symbol.iterator]();
|
package/util/random.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { yieldUntilLimit, yieldCall } from "./iterate.js";
|
|
2
|
-
import {
|
|
2
|
+
import { joinStrings } from "./string.js";
|
|
3
3
|
import { getDefined } from "./undefined.js";
|
|
4
4
|
/** Generate a random integer between two numbers. */
|
|
5
5
|
export const getRandom = (min, max) => Math.round(Math.random() * (max - min) + min);
|
|
@@ -8,7 +8,7 @@ export const getRandom = (min, max) => Math.round(Math.random() * (max - min) +
|
|
|
8
8
|
* - Not designed to be cryptographically random!
|
|
9
9
|
* - Will probably clash — if you're making a random ID, check for existence of the record before saving.
|
|
10
10
|
*/
|
|
11
|
-
export const getRandomKey = (length = 16) =>
|
|
11
|
+
export const getRandomKey = (length = 16) => joinStrings(yieldUntilLimit(yieldCall(getRandomCharacter, KEY_CHARS), length));
|
|
12
12
|
const KEY_CHARS = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
13
13
|
/** Get a random character from a string. */
|
|
14
14
|
export const getRandomCharacter = (str) => str[getRandom(0, str.length - 1)];
|
package/util/string.d.ts
CHANGED
|
@@ -16,8 +16,6 @@ export declare const isString: (v: unknown) => v is string;
|
|
|
16
16
|
* -
|
|
17
17
|
*/
|
|
18
18
|
export declare function toString(value: unknown): string;
|
|
19
|
-
/** Concatenate a set of potential strings together. */
|
|
20
|
-
export declare function concatStrings(values: Iterable<unknown>): string;
|
|
21
19
|
/**
|
|
22
20
|
* Convert an unknown value into a title string for user-facing use.
|
|
23
21
|
* - Strings return the string.
|
|
@@ -32,6 +30,8 @@ export declare function concatStrings(values: Iterable<unknown>): string;
|
|
|
32
30
|
* - Everything else returns `"Unknown"`
|
|
33
31
|
*/
|
|
34
32
|
export declare function toTitle(value: unknown): string;
|
|
33
|
+
/** Concatenate an iterable set of strings together. */
|
|
34
|
+
export declare function joinStrings(strs: Iterable<string>, joiner?: string): string;
|
|
35
35
|
/**
|
|
36
36
|
* Sanitize unexpected characters from a string by:
|
|
37
37
|
* - Stripping control characters.
|
package/util/string.js
CHANGED
|
@@ -32,13 +32,6 @@ export function toString(value) {
|
|
|
32
32
|
return value.name || "function";
|
|
33
33
|
return typeof value; // "symbol" etc.
|
|
34
34
|
}
|
|
35
|
-
/** Concatenate a set of potential strings together. */
|
|
36
|
-
export function concatStrings(values) {
|
|
37
|
-
let output = "";
|
|
38
|
-
for (const value of values)
|
|
39
|
-
output += toString(value);
|
|
40
|
-
return output;
|
|
41
|
-
}
|
|
42
35
|
/**
|
|
43
36
|
* Convert an unknown value into a title string for user-facing use.
|
|
44
37
|
* - Strings return the string.
|
|
@@ -73,6 +66,13 @@ export function toTitle(value) {
|
|
|
73
66
|
return "None";
|
|
74
67
|
return "Unknown";
|
|
75
68
|
}
|
|
69
|
+
/** Concatenate an iterable set of strings together. */
|
|
70
|
+
export function joinStrings(strs, joiner = "") {
|
|
71
|
+
let output = "";
|
|
72
|
+
for (const str of strs)
|
|
73
|
+
output += `${output.length ? joiner : ""}${str}`;
|
|
74
|
+
return output;
|
|
75
|
+
}
|
|
76
76
|
/**
|
|
77
77
|
* Sanitize unexpected characters from a string by:
|
|
78
78
|
* - Stripping control characters.
|