@cripty2001/utils 0.0.204 → 0.0.205
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 +1 -0
- package/dist/index.js +7 -1
- package/dist/react-whispr.d.ts +6 -0
- package/dist/react-whispr.js +9 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ export declare function randBetween(min: number, max: number): number;
|
|
|
84
84
|
*/
|
|
85
85
|
export declare function getEnv(key: string, defaultValue?: string): string;
|
|
86
86
|
export declare const CURRENT_TS_MS: () => Whispr<number>;
|
|
87
|
+
export declare function getClock(rate: number): Whispr<number>;
|
|
87
88
|
export declare function timediff2HumanReadable(diffMs: number): string;
|
|
88
89
|
export declare function fn2promise<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
89
90
|
export type SafeApplyed<T> = (updater: (draft: T) => T | void) => T;
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.stableLog = stableLog;
|
|
|
15
15
|
exports.parseQuery = parseQuery;
|
|
16
16
|
exports.randBetween = randBetween;
|
|
17
17
|
exports.getEnv = getEnv;
|
|
18
|
+
exports.getClock = getClock;
|
|
18
19
|
exports.timediff2HumanReadable = timediff2HumanReadable;
|
|
19
20
|
exports.fn2promise = fn2promise;
|
|
20
21
|
exports.safeApply = safeApply;
|
|
@@ -210,11 +211,16 @@ const CURRENT_TS_MS = () => {
|
|
|
210
211
|
if (currentTsMsInterval === null) {
|
|
211
212
|
currentTsMsInterval = setInterval(() => {
|
|
212
213
|
setCurrentTsMs(Date.now());
|
|
213
|
-
},
|
|
214
|
+
}, 16);
|
|
214
215
|
}
|
|
215
216
|
return currentTsMs;
|
|
216
217
|
};
|
|
217
218
|
exports.CURRENT_TS_MS = CURRENT_TS_MS;
|
|
219
|
+
function getClock(rate) {
|
|
220
|
+
return whispr_1.Whispr.from({ curr: currentTsMs }, ({ curr }) => {
|
|
221
|
+
return Math.floor(curr / rate);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
218
224
|
function timediff2HumanReadable(diffMs) {
|
|
219
225
|
const { unit, diff } = (() => {
|
|
220
226
|
let toReturn = diffMs;
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -37,6 +37,12 @@ export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void, uns
|
|
|
37
37
|
* @returns The current timestamp
|
|
38
38
|
*/
|
|
39
39
|
export declare function useCurrentTimestamp(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Return a reactive clock value, based on the current timestamp and a given rate.
|
|
42
|
+
* @param rate The rate to use for the clock
|
|
43
|
+
* @returns The clock value
|
|
44
|
+
*/
|
|
45
|
+
export declare function useClock(rate: number): Whispr<number>;
|
|
40
46
|
/**
|
|
41
47
|
* Debounce a reactive value, deep checking for equality, and stopping updates until the value changes.
|
|
42
48
|
* @param value The value to debounce
|
package/dist/react-whispr.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.useWhisprValue = useWhisprValue;
|
|
|
4
4
|
exports.useWhispr = useWhispr;
|
|
5
5
|
exports.useOnWhispr = useOnWhispr;
|
|
6
6
|
exports.useCurrentTimestamp = useCurrentTimestamp;
|
|
7
|
+
exports.useClock = useClock;
|
|
7
8
|
exports.useDebounced = useDebounced;
|
|
8
9
|
exports.useSynced = useSynced;
|
|
9
10
|
exports.useAsync = useAsync;
|
|
@@ -88,6 +89,14 @@ function useOnWhispr(w, cb, unsafe = false) {
|
|
|
88
89
|
function useCurrentTimestamp() {
|
|
89
90
|
return useWhisprValue((0, _1.CURRENT_TS_MS)());
|
|
90
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Return a reactive clock value, based on the current timestamp and a given rate.
|
|
94
|
+
* @param rate The rate to use for the clock
|
|
95
|
+
* @returns The clock value
|
|
96
|
+
*/
|
|
97
|
+
function useClock(rate) {
|
|
98
|
+
return useWhisprValue((0, _1.getClock)(rate));
|
|
99
|
+
}
|
|
91
100
|
/**
|
|
92
101
|
* Debounce a reactive value, deep checking for equality, and stopping updates until the value changes.
|
|
93
102
|
* @param value The value to debounce
|
package/package.json
CHANGED