@configura/web-utilities 2.0.0-alpha.9 → 2.1.0-alpha.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/.eslintrc.json +5 -0
- package/dist/Observable/LogProducer.js +6 -4
- package/dist/Observable/Observable.js +1 -1
- package/dist/assert.d.ts +1 -1
- package/dist/filter.d.ts +0 -4
- package/dist/filter.js +0 -24
- package/dist/utilitiesUnits.js +13 -7
- package/package.json +2 -2
package/.eslintrc.json
ADDED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { LogObservable } from "./LogObservable.js";
|
|
2
|
+
function hasLoggerProperty(object) {
|
|
3
|
+
return typeof object === "object" && object !== null && "logger" in object;
|
|
4
|
+
}
|
|
5
|
+
// This has to be possible to do without the helper function and the HasLoggerProperty
|
|
6
|
+
// but can't figure out how right now
|
|
2
7
|
export function isLogProducer(object) {
|
|
3
|
-
return (
|
|
4
|
-
object !== null &&
|
|
5
|
-
"logger" in object &&
|
|
6
|
-
object.logger instanceof LogObservable);
|
|
8
|
+
return hasLoggerProperty(object) && object.logger instanceof LogObservable;
|
|
7
9
|
}
|
|
@@ -5,7 +5,7 @@ export class Observable {
|
|
|
5
5
|
this.listeners.push({ l: listener, c: context });
|
|
6
6
|
};
|
|
7
7
|
this.stopListen = (listener) => {
|
|
8
|
-
|
|
8
|
+
const index = this.listeners.findIndex((l) => l.l === listener);
|
|
9
9
|
if (index !== -1) {
|
|
10
10
|
this.listeners.splice(index, 1);
|
|
11
11
|
}
|
package/dist/assert.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Can for example be used like a type guard in TypeScript.
|
|
5
5
|
*/
|
|
6
|
-
export declare function assert(condition:
|
|
6
|
+
export declare function assert(condition: unknown, msg?: string): asserts condition;
|
|
7
7
|
/**
|
|
8
8
|
* @throws error with the supplied message, if the value === undefined.
|
|
9
9
|
*
|
package/dist/filter.d.ts
CHANGED
|
@@ -19,9 +19,5 @@ export declare type Matches<T> = {
|
|
|
19
19
|
[K in keyof T]: Match<T>;
|
|
20
20
|
};
|
|
21
21
|
export declare function validateFilter(mode: string, value: string): Filter;
|
|
22
|
-
export declare function match<K extends string, T extends {
|
|
23
|
-
[_ in K]: string;
|
|
24
|
-
}>(key: K, filter: Filter, items: T[]): Match<T>;
|
|
25
|
-
export declare function pick<T>(filter: Filter, items: T[]): T[];
|
|
26
22
|
export declare function notEmpty<TValue>(value: TValue | null | undefined): value is TValue;
|
|
27
23
|
//# sourceMappingURL=filter.d.ts.map
|
package/dist/filter.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { shuffle } from "./utilitiesArray.js";
|
|
2
1
|
export function validateFilter(mode, value) {
|
|
3
2
|
if (mode === "all") {
|
|
4
3
|
return { mode, value: "-" };
|
|
@@ -15,29 +14,6 @@ export function validateFilter(mode, value) {
|
|
|
15
14
|
return { mode: "exact", value: "-" };
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
export function match(key, filter, items) {
|
|
19
|
-
const values = Array.from(new Set(items.map((p) => p[key])));
|
|
20
|
-
if (filter.mode === "exact") {
|
|
21
|
-
let { value } = filter;
|
|
22
|
-
let matching = items;
|
|
23
|
-
if (value !== "-") {
|
|
24
|
-
matching = items.filter((p) => p[key] === value);
|
|
25
|
-
}
|
|
26
|
-
return { values, matching };
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return { values, matching: items };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function pick(filter, items) {
|
|
33
|
-
if (filter.mode === "random") {
|
|
34
|
-
items = shuffle(items);
|
|
35
|
-
}
|
|
36
|
-
if ((filter.mode === "first" || filter.mode === "random") && filter.value > 0) {
|
|
37
|
-
items = items.slice(0, filter.value);
|
|
38
|
-
}
|
|
39
|
-
return items;
|
|
40
|
-
}
|
|
41
17
|
export function notEmpty(value) {
|
|
42
18
|
return value !== null && value !== undefined;
|
|
43
19
|
}
|
package/dist/utilitiesUnits.js
CHANGED
|
@@ -9,16 +9,17 @@ export const isEqualLength = (l, r) => l.length === convertLength(r.length, r.un
|
|
|
9
9
|
* @throws an error if the supplied string isn't a known length unit
|
|
10
10
|
*/
|
|
11
11
|
export function toLengthUnit(unit) {
|
|
12
|
+
// The list below must EXACTLY match isLengthUnit(string)
|
|
12
13
|
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
13
14
|
if (unit === "inch") {
|
|
14
15
|
unit = "in";
|
|
15
16
|
}
|
|
16
|
-
if (unit === "
|
|
17
|
+
if (unit === "in" ||
|
|
18
|
+
unit === "ft" ||
|
|
19
|
+
unit === "mm" ||
|
|
17
20
|
unit === "cm" ||
|
|
18
21
|
unit === "dm" ||
|
|
19
|
-
unit === "m"
|
|
20
|
-
unit === "in" ||
|
|
21
|
-
unit === "ft") {
|
|
22
|
+
unit === "m") {
|
|
22
23
|
return unit;
|
|
23
24
|
}
|
|
24
25
|
throw new Error(`Unknown length unit ${unit}`);
|
|
@@ -27,10 +28,15 @@ export function toLengthUnit(unit) {
|
|
|
27
28
|
* As we accept inch as an alias for in we can't make this a typeguard
|
|
28
29
|
*/
|
|
29
30
|
export function isLengthUnit(unit) {
|
|
30
|
-
|
|
31
|
+
// The list below must EXACTLY match toLengthUnit(string)
|
|
32
|
+
unit = unit === null || unit === void 0 ? void 0 : unit.toLowerCase();
|
|
33
|
+
return (unit === "inch" ||
|
|
31
34
|
unit === "in" ||
|
|
32
|
-
unit === "
|
|
33
|
-
unit === "
|
|
35
|
+
unit === "ft" ||
|
|
36
|
+
unit === "mm" ||
|
|
37
|
+
unit === "cm" ||
|
|
38
|
+
unit === "dm" ||
|
|
39
|
+
unit === "m");
|
|
34
40
|
}
|
|
35
41
|
export function convertLength(l, from, to) {
|
|
36
42
|
if (from === to) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configura/web-utilities",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0-alpha.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "883ad6e31a55f05124dd0a6b2047c36ef6e6cea1"
|
|
26
26
|
}
|