@chocbite/ts-lib-state 1.1.3 → 1.1.5
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/index.d.ts +21 -4
- package/dist/index.js +7 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -262,14 +262,12 @@ type EnumHelperEntry = {
|
|
|
262
262
|
type StateEnumHelperList<K extends PropertyKey> = {
|
|
263
263
|
[P in K]: EnumHelperEntry;
|
|
264
264
|
};
|
|
265
|
-
interface StateEnumRelated<L extends StateEnumHelperList<
|
|
265
|
+
interface StateEnumRelated<L extends StateEnumHelperList<PropertyKey> = StateEnumHelperList<PropertyKey>> extends StateRelatedBase {
|
|
266
266
|
list: State<L>;
|
|
267
|
-
map<K extends keyof L, R>(func: (key: K, val: EnumHelperEntry) => R): Promise<R[]>;
|
|
268
267
|
}
|
|
269
|
-
declare class StateEnumHelper<L extends StateEnumHelperList<
|
|
268
|
+
declare class StateEnumHelper<L extends StateEnumHelperList<PropertyKey> = StateEnumHelperList<PropertyKey>, K extends PropertyKey = keyof L, R extends StateRelatedBase = StateEnumRelated<L>> extends StateHelper<K, OptionSome<R>> implements StateEnumRelated<L> {
|
|
270
269
|
readonly list: State<L>;
|
|
271
270
|
constructor(list: State<L>, writable?: State<boolean>);
|
|
272
|
-
map<K extends keyof L, R>(func: (key: K, val: EnumHelperEntry) => R): Promise<R[]>;
|
|
273
271
|
limit(value: K): Promise<Result<K, string>>;
|
|
274
272
|
check(value: K): Promise<Result<K, string>>;
|
|
275
273
|
related(): OptionSome<R>;
|
|
@@ -1152,12 +1150,31 @@ declare const state: {
|
|
|
1152
1150
|
description?: string;
|
|
1153
1151
|
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1154
1152
|
};
|
|
1153
|
+
[x: number]: {
|
|
1154
|
+
name: string;
|
|
1155
|
+
description?: string;
|
|
1156
|
+
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1157
|
+
};
|
|
1158
|
+
[x: symbol]: {
|
|
1159
|
+
name: string;
|
|
1160
|
+
description?: string;
|
|
1161
|
+
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1162
|
+
};
|
|
1155
1163
|
}, K extends PropertyKey = keyof L, R extends StateRelatedBase = StateEnumRelated<L>>(list: State<L>, writable?: State<boolean>): StateEnumHelper<L, K, R>;
|
|
1156
1164
|
list<K extends PropertyKey>(list: { [P in K]: {
|
|
1157
1165
|
name: string;
|
|
1158
1166
|
description?: string;
|
|
1159
1167
|
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1160
1168
|
}; }): typeof list;
|
|
1169
|
+
map<K extends PropertyKey, R>(list: { [P in K]: {
|
|
1170
|
+
name: string;
|
|
1171
|
+
description?: string;
|
|
1172
|
+
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1173
|
+
}; }, func: (key: K, val: {
|
|
1174
|
+
name: string;
|
|
1175
|
+
description?: string;
|
|
1176
|
+
icon?: _chocbite_ts_lib_svg.SVGFunc;
|
|
1177
|
+
}) => R): R[];
|
|
1161
1178
|
};
|
|
1162
1179
|
await_value: <T>(value: T, state: State<T>, timeout?: number) => Promise<boolean>;
|
|
1163
1180
|
compare: (state1: State<any>, state2: State<any>) => Promise<boolean>;
|
package/dist/index.js
CHANGED
|
@@ -1576,13 +1576,6 @@ var StateEnumHelper = class extends StateHelper {
|
|
|
1576
1576
|
super(writable);
|
|
1577
1577
|
this.list = list;
|
|
1578
1578
|
}
|
|
1579
|
-
async map(func) {
|
|
1580
|
-
const list = await this.list;
|
|
1581
|
-
if (list.err) return [];
|
|
1582
|
-
return Object.keys(list.value).map(
|
|
1583
|
-
(key) => func(key, list.value[key])
|
|
1584
|
-
);
|
|
1585
|
-
}
|
|
1586
1579
|
async limit(value) {
|
|
1587
1580
|
return ok5(value);
|
|
1588
1581
|
}
|
|
@@ -1604,6 +1597,13 @@ var enums = {
|
|
|
1604
1597
|
/**Creates an enum description list, passing the enum as a generic type to this function makes things look a bit nicer */
|
|
1605
1598
|
list(list) {
|
|
1606
1599
|
return list;
|
|
1600
|
+
},
|
|
1601
|
+
/**Maps over an enum description list
|
|
1602
|
+
* @param list enum description list
|
|
1603
|
+
* @param func function to apply to each entry
|
|
1604
|
+
* @returns array of results*/
|
|
1605
|
+
map(list, func) {
|
|
1606
|
+
return Object.keys(list).map((key) => func(key, list[key]));
|
|
1607
1607
|
}
|
|
1608
1608
|
};
|
|
1609
1609
|
async function await_value(value, state2, timeout = 500) {
|