@cripty2001/utils 0.0.188 → 0.0.190

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.
@@ -19,6 +19,7 @@ class Appstorage {
19
19
  constructor(PREFIX) {
20
20
  this.PREFIX = PREFIX;
21
21
  [this.index, this._setIndex] = whispr_1.Whispr.create({});
22
+ this.refresh();
22
23
  }
23
24
  add(key, data) {
24
25
  const k = `${this.PREFIX}${key}`;
package/dist/index.d.ts CHANGED
@@ -86,3 +86,4 @@ export declare function getEnv(key: string, defaultValue?: string): string;
86
86
  export declare const CURRENT_TS_MS: () => Whispr<number>;
87
87
  export declare function timediff2HumanReadable(diffMs: number): string;
88
88
  export declare function fn2promise<T>(fn: () => T | Promise<T>): Promise<T>;
89
+ export declare function safeApply<T>(updater: (draft: T) => T | void, incoming: T): T;
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ exports.randBetween = randBetween;
17
17
  exports.getEnv = getEnv;
18
18
  exports.timediff2HumanReadable = timediff2HumanReadable;
19
19
  exports.fn2promise = fn2promise;
20
+ exports.safeApply = safeApply;
20
21
  const whispr_1 = require("@cripty2001/whispr");
21
22
  const lodash_1 = require("lodash");
22
23
  /**
@@ -246,3 +247,9 @@ function fn2promise(fn) {
246
247
  result :
247
248
  Promise.resolve(result);
248
249
  }
250
+ function safeApply(updater, incoming) {
251
+ const cloned = structuredClone(incoming);
252
+ const new_data = updater(cloned);
253
+ const chosen = new_data ?? cloned;
254
+ return chosen;
255
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.188",
3
+ "version": "0.0.190",
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": {