@cripty2001/utils 0.0.203 → 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.
@@ -62,9 +62,7 @@ class Appserver {
62
62
  this.parseUser = parseUser;
63
63
  this.getMetrics = getMetrics;
64
64
  this.app = (0, express_1.default)();
65
- console.log("Origins: ", origins);
66
65
  if (origins.length > 0) {
67
- console.log("Using cors for origins: ", origins);
68
66
  this.app.use((0, cors_1.default)({
69
67
  origin: origins,
70
68
  credentials: true
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
- }, 200);
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;
@@ -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
@@ -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
@@ -126,7 +135,6 @@ function useSynced(def, value, setValue) {
126
135
  return;
127
136
  if ((0, lodash_1.isEqual)(v, value))
128
137
  return;
129
- console.log('SYNC DOWNSTREAM', value);
130
138
  setV(value);
131
139
  }, [value]);
132
140
  // Return a setter that updates both
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.203",
3
+ "version": "0.0.205",
4
4
  "description": "Internal Set of utils. If you need them use them, otherwise go to the next package ;)",
5
5
  "homepage": "https://github.com/cripty2001/utils#readme",
6
6
  "bugs": {