@cripty2001/utils 0.0.25 → 0.0.27

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 CHANGED
@@ -22,6 +22,7 @@ export declare function loop(cb: () => Promise<void>, interval: number, onError?
22
22
  export declare function isEqual(a: any, b: any): boolean;
23
23
  export declare function arrayStep(from: number, to: number, step: number): number[];
24
24
  export declare function copyToClipboard(text: string): void;
25
+ export declare function download(data: string | Blob, filename: string, mimeType?: string): void;
25
26
  export declare function stableLog(obj: any, message?: string): void;
26
27
  export declare function parseQuery(query: string | Record<string, any> | URLSearchParams, fields: string[]): {
27
28
  extracted: URLSearchParams;
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ exports.loop = loop;
9
9
  exports.isEqual = isEqual;
10
10
  exports.arrayStep = arrayStep;
11
11
  exports.copyToClipboard = copyToClipboard;
12
+ exports.download = download;
12
13
  exports.stableLog = stableLog;
13
14
  exports.parseQuery = parseQuery;
14
15
  exports.randBetween = randBetween;
@@ -86,6 +87,17 @@ function arrayStep(from, to, step) {
86
87
  function copyToClipboard(text) {
87
88
  navigator.clipboard.writeText(text);
88
89
  }
90
+ function download(data, filename, mimeType = 'application/octet-stream') {
91
+ const blob = data instanceof Blob ? data : new Blob([data], { type: mimeType });
92
+ const url = URL.createObjectURL(blob);
93
+ const a = document.createElement('a');
94
+ a.href = url;
95
+ a.download = filename;
96
+ document.body.appendChild(a);
97
+ a.click();
98
+ document.body.removeChild(a);
99
+ URL.revokeObjectURL(url);
100
+ }
89
101
  function stableLog(obj, message = '') {
90
102
  console.log(message, JSON.parse(JSON.stringify(obj)));
91
103
  }
@@ -25,7 +25,7 @@ export declare function useWhisprValue<I, O = I>(w: Whispr<I>, computer?: (data:
25
25
  * @remarks The returned whispr has already been ref-fed, so it can be directly used without worrying about react recreating it or similar bad things
26
26
  */
27
27
  export declare function useWhispr<T>(data: T | Whispr<T>): Whispr<T>;
28
- export declare function useCurrentTimestamp(): number;
28
+ export declare function useCurrentTimestamp(refresh?: number): number;
29
29
  export declare function useDebounced<T>(value: T): T;
30
30
  /**
31
31
  *
@@ -54,10 +54,10 @@ function useWhispr(data) {
54
54
  return data;
55
55
  return w;
56
56
  }
57
- function useCurrentTimestamp() {
57
+ function useCurrentTimestamp(refresh = 1000) {
58
58
  const [currTs, setCurrTs] = (0, react_1.useState)(Date.now());
59
59
  (0, react_1.useEffect)(() => {
60
- const id = setInterval(() => setCurrTs(Date.now()), 1000);
60
+ const id = setInterval(() => setCurrTs(Date.now()), refresh);
61
61
  return () => clearInterval(id);
62
62
  }, [setCurrTs]);
63
63
  return currTs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cripty2001/utils",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
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": {