@cripty2001/utils 0.0.27 → 0.0.29
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 +2 -0
- package/dist/index.js +8 -0
- package/dist/react-whispr.d.ts +6 -0
- package/dist/react-whispr.js +12 -0
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -29,3 +29,5 @@ export declare function parseQuery(query: string | Record<string, any> | URLSear
|
|
|
29
29
|
left: URLSearchParams;
|
|
30
30
|
};
|
|
31
31
|
export declare function randBetween(min: number, max: number): number;
|
|
32
|
+
import "dotenv/config";
|
|
33
|
+
export declare function getEnv(key: string, defaultValue: string | undefined): string;
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.download = download;
|
|
|
13
13
|
exports.stableLog = stableLog;
|
|
14
14
|
exports.parseQuery = parseQuery;
|
|
15
15
|
exports.randBetween = randBetween;
|
|
16
|
+
exports.getEnv = getEnv;
|
|
16
17
|
const lodash_1 = require("lodash");
|
|
17
18
|
function getRandom(_alphabeth, length) {
|
|
18
19
|
const alphabeth = _alphabeth.split("");
|
|
@@ -134,3 +135,10 @@ function parseQuery(query, fields) {
|
|
|
134
135
|
function randBetween(min, max) {
|
|
135
136
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
136
137
|
}
|
|
138
|
+
require("dotenv/config");
|
|
139
|
+
function getEnv(key, defaultValue) {
|
|
140
|
+
const value = process.env[key] ?? defaultValue;
|
|
141
|
+
if (value === undefined)
|
|
142
|
+
throw new Error(`Environment variable ${key} is not defined and no default value was provided.`);
|
|
143
|
+
return value;
|
|
144
|
+
}
|
package/dist/react-whispr.d.ts
CHANGED
|
@@ -25,6 +25,12 @@ 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
|
+
/**
|
|
29
|
+
* Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
|
|
30
|
+
* @param w The whispr to subscribe to
|
|
31
|
+
* @param cb The callback to call on value change
|
|
32
|
+
*/
|
|
33
|
+
export declare function useOnWhispr<T>(w: Whispr<T>, cb: (value: T) => void): void;
|
|
28
34
|
export declare function useCurrentTimestamp(refresh?: number): number;
|
|
29
35
|
export declare function useDebounced<T>(value: T): T;
|
|
30
36
|
/**
|
package/dist/react-whispr.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useWhisprValue = useWhisprValue;
|
|
4
4
|
exports.useWhispr = useWhispr;
|
|
5
|
+
exports.useOnWhispr = useOnWhispr;
|
|
5
6
|
exports.useCurrentTimestamp = useCurrentTimestamp;
|
|
6
7
|
exports.useDebounced = useDebounced;
|
|
7
8
|
exports.useAsync = useAsync;
|
|
@@ -54,6 +55,17 @@ function useWhispr(data) {
|
|
|
54
55
|
return data;
|
|
55
56
|
return w;
|
|
56
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Subscribe a callback to a Whispr inside a react component, properly handling unsubscription on unmount.
|
|
60
|
+
* @param w The whispr to subscribe to
|
|
61
|
+
* @param cb The callback to call on value change
|
|
62
|
+
*/
|
|
63
|
+
function useOnWhispr(w, cb) {
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
const unsub = w.subscribe(cb);
|
|
66
|
+
return () => unsub();
|
|
67
|
+
}, [w, cb]);
|
|
68
|
+
}
|
|
57
69
|
function useCurrentTimestamp(refresh = 1000) {
|
|
58
70
|
const [currTs, setCurrTs] = (0, react_1.useState)(Date.now());
|
|
59
71
|
(0, react_1.useEffect)(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cripty2001/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.29",
|
|
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": {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/node": "^24.9.1",
|
|
25
26
|
"@types/react": "^19",
|
|
26
27
|
"react": "^19",
|
|
27
28
|
"typescript": "^5.9.3"
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@cripty2001/whispr": "^0.1.0",
|
|
31
32
|
"@types/lodash": "^4.17.20",
|
|
33
|
+
"dotenv": "^17.2.3",
|
|
32
34
|
"lodash": "^4.17.21"
|
|
33
35
|
},
|
|
34
36
|
"peerDependencies": {
|