@configura/web-utilities 2.0.0 → 2.1.0-alpha.1
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/dist/filter.d.ts +0 -4
- package/dist/filter.js +0 -24
- package/package.json +2 -2
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
|
-
const { 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@configura/web-utilities",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-alpha.1",
|
|
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": "0eec1ba88fc2fa4d0f3f9a36173818f721752786"
|
|
26
26
|
}
|