@tixyel/streamelements 6.0.3 → 6.2.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/dist/index.d.ts +114 -10
- package/dist/index.es.js +1272 -889
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -1740,15 +1740,12 @@ type UseStorageOptions<T> = {
|
|
|
1740
1740
|
data: T;
|
|
1741
1741
|
};
|
|
1742
1742
|
declare class useStorage<T extends JSONObject> extends EventProvider<UseStorageEvents<T>> {
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
*/
|
|
1743
|
+
private SE_API;
|
|
1744
|
+
/** The unique identifier for the storage instance. */
|
|
1746
1745
|
id: string;
|
|
1747
1746
|
loaded: boolean;
|
|
1748
1747
|
data: T;
|
|
1749
1748
|
constructor(options: UseStorageOptions<T>);
|
|
1750
|
-
SE_API: StreamElements.SE_API | null;
|
|
1751
|
-
private start;
|
|
1752
1749
|
/**
|
|
1753
1750
|
* Saves the current data to storage.
|
|
1754
1751
|
* @param data Data to save (defaults to current)
|
|
@@ -2041,6 +2038,7 @@ declare namespace Helper {
|
|
|
2041
2038
|
* @param amount - Number to balance
|
|
2042
2039
|
* @param min - Minimum value
|
|
2043
2040
|
* @param max - Maximum value
|
|
2041
|
+
* @param decimals - Number of decimal places to round to (default is 0)
|
|
2044
2042
|
* @returns - Balanced number
|
|
2045
2043
|
* @example
|
|
2046
2044
|
* ```javascript
|
|
@@ -2048,7 +2046,7 @@ declare namespace Helper {
|
|
|
2048
2046
|
* console.log(balancedValue); // 100
|
|
2049
2047
|
* ```
|
|
2050
2048
|
*/
|
|
2051
|
-
function balance(amount: number, min?: number, max?: number): number;
|
|
2049
|
+
function balance(amount: number, min?: number, max?: number, decimals?: number): number;
|
|
2052
2050
|
/**
|
|
2053
2051
|
* Rounds a number to a specified number of decimal places
|
|
2054
2052
|
* @param value - Number to round
|
|
@@ -2056,11 +2054,27 @@ declare namespace Helper {
|
|
|
2056
2054
|
* @returns Rounded number
|
|
2057
2055
|
* @example
|
|
2058
2056
|
* ```javascript
|
|
2059
|
-
* const roundedValue = Simulation.number.
|
|
2057
|
+
* const roundedValue = Simulation.number.round(3.14159, 3);
|
|
2060
2058
|
* console.log(roundedValue); // 3.142
|
|
2061
2059
|
* ```
|
|
2062
2060
|
*/
|
|
2063
2061
|
function round(value: number, decimals?: number): number;
|
|
2062
|
+
/**
|
|
2063
|
+
* Generate random number
|
|
2064
|
+
* @param min - Minimum value
|
|
2065
|
+
* @param max - Maximum value
|
|
2066
|
+
* @param float - Number of decimal places (0 for integer)
|
|
2067
|
+
* @returns - Random number
|
|
2068
|
+
* @example
|
|
2069
|
+
* ```javascript
|
|
2070
|
+
* const intNumber = number.random(1, 10);
|
|
2071
|
+
* console.log(intNumber); // e.g. 7
|
|
2072
|
+
*
|
|
2073
|
+
* const floatNumber = number.random(1, 10, 2);
|
|
2074
|
+
* console.log(floatNumber); // e.g. 3.14
|
|
2075
|
+
* ```
|
|
2076
|
+
*/
|
|
2077
|
+
const random: typeof Helper.random.number;
|
|
2064
2078
|
}
|
|
2065
2079
|
namespace utils {
|
|
2066
2080
|
/**
|
|
@@ -2074,19 +2088,19 @@ declare namespace Helper {
|
|
|
2074
2088
|
* @param obj - The object to get entries from.
|
|
2075
2089
|
* @returns An array of key-value pairs from the object.
|
|
2076
2090
|
*/
|
|
2077
|
-
|
|
2091
|
+
const typedEntries: typeof object.entries;
|
|
2078
2092
|
/**
|
|
2079
2093
|
* Returns typed values of an object.
|
|
2080
2094
|
* @param obj - The object to get values from.
|
|
2081
2095
|
* @returns An array of values from the object.
|
|
2082
2096
|
*/
|
|
2083
|
-
|
|
2097
|
+
const typedValues: typeof object.values;
|
|
2084
2098
|
/**
|
|
2085
2099
|
* Returns typed keys of an object.
|
|
2086
2100
|
* @param obj - The object to get keys from.
|
|
2087
2101
|
* @returns An array of keys from the object.
|
|
2088
2102
|
*/
|
|
2089
|
-
|
|
2103
|
+
const typedKeys: typeof object.keys;
|
|
2090
2104
|
/**
|
|
2091
2105
|
* Selects an item based on weighted probabilities.
|
|
2092
2106
|
* @param items - An object where keys are items and values are their weights.
|
|
@@ -2222,6 +2236,24 @@ declare namespace Helper {
|
|
|
2222
2236
|
* ```
|
|
2223
2237
|
*/
|
|
2224
2238
|
function flatten(obj: Record<string, any>, stringify?: boolean, prefix?: string): Record<string, typeof stringify extends true ? string : string | number | boolean>;
|
|
2239
|
+
/**
|
|
2240
|
+
* Returns the entries of an object as an array of key-value pairs, with proper typing.
|
|
2241
|
+
* @param obj - The object to retrieve entries from.
|
|
2242
|
+
* @returns An array of key-value pairs from the object, typed as an array of tuples with key and value types.
|
|
2243
|
+
*/
|
|
2244
|
+
function entries<K extends string, V>(obj: Record<K, V>): [K, V][];
|
|
2245
|
+
/**
|
|
2246
|
+
* Returns the values of an object as an array, with proper typing.
|
|
2247
|
+
* @param obj - The object to retrieve values from.
|
|
2248
|
+
* @returns An array of values from the object, typed as an array of the value type.
|
|
2249
|
+
*/
|
|
2250
|
+
function values<K extends string, V>(obj: Record<K, V>): V[];
|
|
2251
|
+
/**
|
|
2252
|
+
* Returns the keys of an object as an array of strings, with proper typing.
|
|
2253
|
+
* @param obj - The object to retrieve keys from.
|
|
2254
|
+
* @returns An array of keys from the object, typed as an array of strings.
|
|
2255
|
+
*/
|
|
2256
|
+
function keys<K extends string, V>(obj: Record<K, V>): K[];
|
|
2225
2257
|
}
|
|
2226
2258
|
namespace message {
|
|
2227
2259
|
type BadgeOptions = Twitch.roles[] | Twitch.roles | `${Twitch.roles}, ${Twitch.roles}` | `${Twitch.roles}, ${Twitch.roles}, ${Twitch.roles}`;
|
|
@@ -2563,6 +2595,24 @@ declare namespace Helper {
|
|
|
2563
2595
|
*/
|
|
2564
2596
|
function uuid(): string;
|
|
2565
2597
|
}
|
|
2598
|
+
namespace fn {
|
|
2599
|
+
/**
|
|
2600
|
+
* Apply function with given thisArg and arguments
|
|
2601
|
+
* @param fn - Function to apply
|
|
2602
|
+
* @param thisArg - Value to use as this when calling fn
|
|
2603
|
+
* @param args - Arguments to pass to fn
|
|
2604
|
+
* @returns Result of calling fn with thisArg and args
|
|
2605
|
+
*/
|
|
2606
|
+
function apply<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, args: TArgs): TReturn;
|
|
2607
|
+
/**
|
|
2608
|
+
* Call function with given thisArg and arguments
|
|
2609
|
+
* @param fn - Function to call
|
|
2610
|
+
* @param thisArg - Value to use as this when calling fn
|
|
2611
|
+
* @param args - Arguments to pass to fn
|
|
2612
|
+
* @returns Result of calling fn with thisArg and args
|
|
2613
|
+
*/
|
|
2614
|
+
function call<TThis, TArgs extends unknown[], TReturn>(fn: (this: TThis, ...args: TArgs) => TReturn, thisArg: TThis, ...args: TArgs): TReturn;
|
|
2615
|
+
}
|
|
2566
2616
|
}
|
|
2567
2617
|
|
|
2568
2618
|
declare namespace Local {
|
|
@@ -2829,6 +2879,58 @@ declare namespace Data {
|
|
|
2829
2879
|
}[];
|
|
2830
2880
|
}
|
|
2831
2881
|
|
|
2882
|
+
type MessageMap = Record<string, any>;
|
|
2883
|
+
type MessageTuple<T extends MessageMap> = {
|
|
2884
|
+
[K in keyof T]: [key: K, data: T[K]];
|
|
2885
|
+
}[keyof T];
|
|
2886
|
+
type BaseEvents<T extends MessageMap> = {
|
|
2887
|
+
load: [];
|
|
2888
|
+
message: MessageTuple<T>;
|
|
2889
|
+
};
|
|
2890
|
+
type UseCommsOptions = {
|
|
2891
|
+
id?: string;
|
|
2892
|
+
};
|
|
2893
|
+
type UseCommItem<T extends MessageMap> = {
|
|
2894
|
+
nonce: string;
|
|
2895
|
+
key: keyof T;
|
|
2896
|
+
value: T[keyof T];
|
|
2897
|
+
timestamp: string;
|
|
2898
|
+
};
|
|
2899
|
+
/**
|
|
2900
|
+
* A module for handling communications between different widgets inside streamelements.
|
|
2901
|
+
* @example
|
|
2902
|
+
* ```ts
|
|
2903
|
+
* type CommsMessages = {
|
|
2904
|
+
* hello: { loaded: boolean };
|
|
2905
|
+
* update: { value: number };
|
|
2906
|
+
* reload: {};
|
|
2907
|
+
* tags: string[];
|
|
2908
|
+
* }
|
|
2909
|
+
*
|
|
2910
|
+
* const comms = new useComms<CommsMessages>();
|
|
2911
|
+
*
|
|
2912
|
+
* comms.on('message', (message, data) => {
|
|
2913
|
+
* switch (message) {
|
|
2914
|
+
* case 'hello': {}
|
|
2915
|
+
* case 'update': {}
|
|
2916
|
+
* case 'reload': {}
|
|
2917
|
+
* case 'tags': {}
|
|
2918
|
+
* }
|
|
2919
|
+
* })
|
|
2920
|
+
* ```
|
|
2921
|
+
*/
|
|
2922
|
+
declare class useComms<T extends MessageMap> extends EventProvider<BaseEvents<T>> {
|
|
2923
|
+
private SE_API;
|
|
2924
|
+
id: string;
|
|
2925
|
+
loaded: boolean;
|
|
2926
|
+
private history;
|
|
2927
|
+
private detected;
|
|
2928
|
+
constructor(options?: UseCommsOptions);
|
|
2929
|
+
send<K extends keyof T>(key: K, data: T[K]): Promise<void>;
|
|
2930
|
+
update(history: Array<UseCommItem<T>>): void;
|
|
2931
|
+
on<K extends keyof BaseEvents<T>>(eventName: K, callback: (this: useComms<T>, ...args: BaseEvents<T>[K]) => void): this;
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2832
2934
|
declare const main: {
|
|
2833
2935
|
SeAPI: Promise<StreamElements.SE_API>;
|
|
2834
2936
|
Client: typeof Client;
|
|
@@ -2841,6 +2943,7 @@ declare const main: {
|
|
|
2841
2943
|
useStorage: typeof useStorage;
|
|
2842
2944
|
useQueue: typeof useQueue;
|
|
2843
2945
|
useLogger: typeof useLogger;
|
|
2946
|
+
useComms: typeof useComms;
|
|
2844
2947
|
};
|
|
2845
2948
|
actions: {
|
|
2846
2949
|
Button: typeof Button;
|
|
@@ -2851,6 +2954,7 @@ declare const main: {
|
|
|
2851
2954
|
};
|
|
2852
2955
|
data: {
|
|
2853
2956
|
usedStorages: useStorage<any>[];
|
|
2957
|
+
usedComms: useComms<any>[];
|
|
2854
2958
|
};
|
|
2855
2959
|
pronouns: {
|
|
2856
2960
|
Alejo: typeof Alejo;
|