@conorroberts/utils 0.0.111 → 0.0.116
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/db/migrate.mjs +1 -2
- package/dist/db/migrate.mjs.map +1 -1
- package/dist/db/validate-schema.mjs +1 -2
- package/dist/db/validate-schema.mjs.map +1 -1
- package/dist/env.d.mts +0 -1
- package/dist/env.mjs +2 -3
- package/dist/env.mjs.map +1 -1
- package/dist/images.mjs +1 -2
- package/dist/images.mjs.map +1 -1
- package/dist/oxlint/index.d.mts +2 -2
- package/dist/oxlint/index.mjs +86 -128
- package/dist/oxlint/index.mjs.map +1 -1
- package/dist/react.mjs +1 -6
- package/dist/react.mjs.map +1 -1
- package/dist/vscode/settings.json +47 -0
- package/package.json +14 -8
package/dist/react.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/react/useStableCallback.ts
|
|
4
3
|
/**
|
|
5
4
|
* Creates a stable callback that always calls the latest version of the function.
|
|
@@ -13,7 +12,6 @@ const useStableCallback = (callback) => {
|
|
|
13
12
|
return callbackRef.current(...args);
|
|
14
13
|
}, []);
|
|
15
14
|
};
|
|
16
|
-
|
|
17
15
|
//#endregion
|
|
18
16
|
//#region src/react/useOnce.ts
|
|
19
17
|
/**
|
|
@@ -41,7 +39,6 @@ const useOnce = (condition, callback) => {
|
|
|
41
39
|
}
|
|
42
40
|
}, [condition, stableCallback]);
|
|
43
41
|
};
|
|
44
|
-
|
|
45
42
|
//#endregion
|
|
46
43
|
//#region src/react/useLocalOnce.ts
|
|
47
44
|
/**
|
|
@@ -70,7 +67,6 @@ const useLocalOnce = (condition, callback) => {
|
|
|
70
67
|
stableCallback();
|
|
71
68
|
}
|
|
72
69
|
};
|
|
73
|
-
|
|
74
70
|
//#endregion
|
|
75
71
|
//#region src/react/useOnMount.ts
|
|
76
72
|
/**
|
|
@@ -121,7 +117,6 @@ const useAsyncOnMount = (callback) => {
|
|
|
121
117
|
}
|
|
122
118
|
}, [stableCallback]);
|
|
123
119
|
};
|
|
124
|
-
|
|
125
120
|
//#endregion
|
|
126
121
|
//#region src/react/useOnUnmount.ts
|
|
127
122
|
/**
|
|
@@ -136,7 +131,7 @@ const useOnUnmount = (callback) => {
|
|
|
136
131
|
};
|
|
137
132
|
}, [stableCallback]);
|
|
138
133
|
};
|
|
139
|
-
|
|
140
134
|
//#endregion
|
|
141
135
|
export { useAsyncOnMount, useLocalOnce, useOnMount, useOnUnmount, useOnce, useStableCallback };
|
|
136
|
+
|
|
142
137
|
//# sourceMappingURL=react.mjs.map
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react/useStableCallback.ts","../src/react/useOnce.ts","../src/react/useLocalOnce.ts","../src/react/useOnMount.ts","../src/react/useOnUnmount.ts"],"sourcesContent":["// oxlint-disable no-explicit-any\n\nimport { useCallback, useRef } from \"react\";\n\ntype AnyFunction = (...args: any[]) => any;\ntype AnyArgs = any[];\n\n/**\n * Creates a stable callback that always calls the latest version of the function.\n * Useful for callbacks that need to be used in dependency arrays but should always\n * execute the most recent version of the callback.\n */\nexport const useStableCallback = <T extends AnyFunction>(callback: T): T => {\n const callbackRef = useRef(callback);\n\n // Update the ref on every render\n callbackRef.current = callback;\n\n return useCallback((...args: AnyArgs) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n","import { useEffect, useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Runs a callback only once when a condition becomes truthy.\n * The callback is stabilized internally to always reference the latest version.\n *\n * @param condition - When truthy (evaluated via Boolean()), the callback will be executed (only once).\n * @param callback - The function to run once when the condition is met.\n *\n * @example\n * ```tsx\n * const isReady = true;\n * useOnce(isReady, () => {\n * console.log(\"Ready!\");\n * });\n * ```\n */\nexport const useOnce = (condition: unknown, callback: () => void): void => {\n const hasRunRef = useRef(false);\n const stableCallback = useStableCallback(callback);\n\n useEffect(() => {\n if (Boolean(condition) && !hasRunRef.current) {\n hasRunRef.current = true;\n stableCallback();\n }\n }, [condition, stableCallback]);\n};\n","import { useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Runs a callback only once when a condition becomes truthy, executing synchronously\n * during render. The callback is stabilized internally to always reference the latest version.\n *\n * Unlike `useOnce`, this runs at the top level of the hook (not in useEffect),\n * making it suitable for state updates that need to happen synchronously during render.\n *\n * @param condition - When truthy (evaluated via Boolean()), the callback will be executed (only once).\n * @param callback - The function to run once when the condition is met.\n *\n * @example\n * ```tsx\n * const user: User | null = getUser();\n * useLocalOnce(user, () => {\n * setState(user.name);\n * });\n * ```\n */\nexport const useLocalOnce = (condition: unknown, callback: () => void): void => {\n const hasRunRef = useRef(false);\n const stableCallback = useStableCallback(callback);\n\n if (Boolean(condition) && !hasRunRef.current) {\n hasRunRef.current = true;\n stableCallback();\n }\n};\n","import { useEffect, useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Calls the given callback when the component mounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n *\n * @param callback - The function to run when the component mounts.\n *\n * @example\n * ```tsx\n * useOnMount(() => {\n * console.log(\"Component mounted!\");\n * });\n * ```\n */\nexport const useOnMount = (callback: React.EffectCallback): void => {\n const stableCallback = useStableCallback(callback);\n const isRun = useRef(false);\n\n useEffect(() => {\n if (!isRun.current) {\n isRun.current = true;\n return stableCallback();\n }\n }, [stableCallback]);\n};\n\n/**\n * Calls the given async callback when the component mounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n * Unlike useOnMount, this does not support cleanup functions.\n *\n * @param callback - The async function to run when the component mounts.\n *\n * @example\n * ```tsx\n * useAsyncOnMount(async () => {\n * const data = await fetchData();\n * console.log(\"Data loaded:\", data);\n * });\n * ```\n */\nexport const useAsyncOnMount = (callback: () => Promise<void>): void => {\n const stableCallback = useStableCallback(callback);\n const isRun = useRef(false);\n\n useEffect(() => {\n if (!isRun.current) {\n isRun.current = true;\n stableCallback();\n }\n }, [stableCallback]);\n};\n","import { useEffect } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Calls the given callback when the component unmounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n */\nexport const useOnUnmount = (callback: () => void): void => {\n const stableCallback = useStableCallback(callback);\n\n useEffect(() => {\n return () => {\n stableCallback();\n };\n }, [stableCallback]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"react.mjs","names":[],"sources":["../src/react/useStableCallback.ts","../src/react/useOnce.ts","../src/react/useLocalOnce.ts","../src/react/useOnMount.ts","../src/react/useOnUnmount.ts"],"sourcesContent":["// oxlint-disable no-explicit-any\n\nimport { useCallback, useRef } from \"react\";\n\ntype AnyFunction = (...args: any[]) => any;\ntype AnyArgs = any[];\n\n/**\n * Creates a stable callback that always calls the latest version of the function.\n * Useful for callbacks that need to be used in dependency arrays but should always\n * execute the most recent version of the callback.\n */\nexport const useStableCallback = <T extends AnyFunction>(callback: T): T => {\n const callbackRef = useRef(callback);\n\n // Update the ref on every render\n callbackRef.current = callback;\n\n return useCallback((...args: AnyArgs) => {\n return callbackRef.current(...args);\n }, []) as T;\n};\n","import { useEffect, useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Runs a callback only once when a condition becomes truthy.\n * The callback is stabilized internally to always reference the latest version.\n *\n * @param condition - When truthy (evaluated via Boolean()), the callback will be executed (only once).\n * @param callback - The function to run once when the condition is met.\n *\n * @example\n * ```tsx\n * const isReady = true;\n * useOnce(isReady, () => {\n * console.log(\"Ready!\");\n * });\n * ```\n */\nexport const useOnce = (condition: unknown, callback: () => void): void => {\n const hasRunRef = useRef(false);\n const stableCallback = useStableCallback(callback);\n\n useEffect(() => {\n if (Boolean(condition) && !hasRunRef.current) {\n hasRunRef.current = true;\n stableCallback();\n }\n }, [condition, stableCallback]);\n};\n","import { useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Runs a callback only once when a condition becomes truthy, executing synchronously\n * during render. The callback is stabilized internally to always reference the latest version.\n *\n * Unlike `useOnce`, this runs at the top level of the hook (not in useEffect),\n * making it suitable for state updates that need to happen synchronously during render.\n *\n * @param condition - When truthy (evaluated via Boolean()), the callback will be executed (only once).\n * @param callback - The function to run once when the condition is met.\n *\n * @example\n * ```tsx\n * const user: User | null = getUser();\n * useLocalOnce(user, () => {\n * setState(user.name);\n * });\n * ```\n */\nexport const useLocalOnce = (condition: unknown, callback: () => void): void => {\n const hasRunRef = useRef(false);\n const stableCallback = useStableCallback(callback);\n\n if (Boolean(condition) && !hasRunRef.current) {\n hasRunRef.current = true;\n stableCallback();\n }\n};\n","import { useEffect, useRef } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Calls the given callback when the component mounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n *\n * @param callback - The function to run when the component mounts.\n *\n * @example\n * ```tsx\n * useOnMount(() => {\n * console.log(\"Component mounted!\");\n * });\n * ```\n */\nexport const useOnMount = (callback: React.EffectCallback): void => {\n const stableCallback = useStableCallback(callback);\n const isRun = useRef(false);\n\n useEffect(() => {\n if (!isRun.current) {\n isRun.current = true;\n return stableCallback();\n }\n }, [stableCallback]);\n};\n\n/**\n * Calls the given async callback when the component mounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n * Unlike useOnMount, this does not support cleanup functions.\n *\n * @param callback - The async function to run when the component mounts.\n *\n * @example\n * ```tsx\n * useAsyncOnMount(async () => {\n * const data = await fetchData();\n * console.log(\"Data loaded:\", data);\n * });\n * ```\n */\nexport const useAsyncOnMount = (callback: () => Promise<void>): void => {\n const stableCallback = useStableCallback(callback);\n const isRun = useRef(false);\n\n useEffect(() => {\n if (!isRun.current) {\n isRun.current = true;\n stableCallback();\n }\n }, [stableCallback]);\n};\n","import { useEffect } from \"react\";\nimport { useStableCallback } from \"./useStableCallback\";\n\n/**\n * Calls the given callback when the component unmounts.\n * Uses useStableCallback internally to ensure the latest version is called.\n */\nexport const useOnUnmount = (callback: () => void): void => {\n const stableCallback = useStableCallback(callback);\n\n useEffect(() => {\n return () => {\n stableCallback();\n };\n }, [stableCallback]);\n};\n"],"mappings":";;;;;;;AAYA,MAAa,qBAA4C,aAAmB;CAC1E,MAAM,cAAc,OAAO,SAAS;AAGpC,aAAY,UAAU;AAEtB,QAAO,aAAa,GAAG,SAAkB;AACvC,SAAO,YAAY,QAAQ,GAAG,KAAK;IAClC,EAAE,CAAC;;;;;;;;;;;;;;;;;;;ACFR,MAAa,WAAW,WAAoB,aAA+B;CACzE,MAAM,YAAY,OAAO,MAAM;CAC/B,MAAM,iBAAiB,kBAAkB,SAAS;AAElD,iBAAgB;AACd,MAAI,QAAQ,UAAU,IAAI,CAAC,UAAU,SAAS;AAC5C,aAAU,UAAU;AACpB,mBAAgB;;IAEjB,CAAC,WAAW,eAAe,CAAC;;;;;;;;;;;;;;;;;;;;;;ACNjC,MAAa,gBAAgB,WAAoB,aAA+B;CAC9E,MAAM,YAAY,OAAO,MAAM;CAC/B,MAAM,iBAAiB,kBAAkB,SAAS;AAElD,KAAI,QAAQ,UAAU,IAAI,CAAC,UAAU,SAAS;AAC5C,YAAU,UAAU;AACpB,kBAAgB;;;;;;;;;;;;;;;;;;ACXpB,MAAa,cAAc,aAAyC;CAClE,MAAM,iBAAiB,kBAAkB,SAAS;CAClD,MAAM,QAAQ,OAAO,MAAM;AAE3B,iBAAgB;AACd,MAAI,CAAC,MAAM,SAAS;AAClB,SAAM,UAAU;AAChB,UAAO,gBAAgB;;IAExB,CAAC,eAAe,CAAC;;;;;;;;;;;;;;;;;AAkBtB,MAAa,mBAAmB,aAAwC;CACtE,MAAM,iBAAiB,kBAAkB,SAAS;CAClD,MAAM,QAAQ,OAAO,MAAM;AAE3B,iBAAgB;AACd,MAAI,CAAC,MAAM,SAAS;AAClB,SAAM,UAAU;AAChB,mBAAgB;;IAEjB,CAAC,eAAe,CAAC;;;;;;;;AC7CtB,MAAa,gBAAgB,aAA+B;CAC1D,MAAM,iBAAiB,kBAAkB,SAAS;AAElD,iBAAgB;AACd,eAAa;AACX,mBAAgB;;IAEjB,CAAC,eAAe,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files.watcherExclude": {
|
|
3
|
+
"**/routeTree.gen.ts": true,
|
|
4
|
+
"packages/*/dist": true,
|
|
5
|
+
"packages/*/.react-router": true,
|
|
6
|
+
"packages/*/.turbo": true
|
|
7
|
+
},
|
|
8
|
+
"search.exclude": {
|
|
9
|
+
"**/routeTree.gen.ts": true,
|
|
10
|
+
"packages/*/dist": true,
|
|
11
|
+
"packages/*/.react-router": true,
|
|
12
|
+
"packages/*/.turbo": true
|
|
13
|
+
},
|
|
14
|
+
"files.readonlyInclude": {
|
|
15
|
+
"**/routeTree.gen.ts": true,
|
|
16
|
+
"packages/*/dist": true,
|
|
17
|
+
"packages/*/.react-router": true,
|
|
18
|
+
"packages/*/.turbo": true
|
|
19
|
+
},
|
|
20
|
+
"oxc.lint.run": "onType",
|
|
21
|
+
"oxc.typeAware": true,
|
|
22
|
+
"oxc.fixKind": "safe_fix_or_suggestion",
|
|
23
|
+
"editor.codeActionsOnSave": {
|
|
24
|
+
"source.organizeImports": "always",
|
|
25
|
+
"source.fixAll.oxc": "always"
|
|
26
|
+
},
|
|
27
|
+
"editor.defaultFormatter": "oxc.oxc-vscode",
|
|
28
|
+
"editor.formatOnSave": true,
|
|
29
|
+
"[typescript]": {
|
|
30
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
31
|
+
},
|
|
32
|
+
"[typescriptreact]": {
|
|
33
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
34
|
+
},
|
|
35
|
+
"[javascript]": {
|
|
36
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
37
|
+
},
|
|
38
|
+
"[javascriptreact]": {
|
|
39
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
40
|
+
},
|
|
41
|
+
"[json]": {
|
|
42
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
43
|
+
},
|
|
44
|
+
"[jsonc]": {
|
|
45
|
+
"editor.defaultFormatter": "oxc.oxc-vscode"
|
|
46
|
+
}
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conorroberts/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.116",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "ISC",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"./oxfmt/config": {
|
|
28
28
|
"default": "./dist/oxfmt/config.json"
|
|
29
29
|
},
|
|
30
|
+
"./vscode/settings": {
|
|
31
|
+
"default": "./dist/vscode/settings.json"
|
|
32
|
+
},
|
|
30
33
|
"./oxlint": {
|
|
31
34
|
"types": "./dist/oxlint/index.d.mts",
|
|
32
35
|
"default": "./dist/oxlint/index.mjs"
|
|
@@ -41,29 +44,32 @@
|
|
|
41
44
|
}
|
|
42
45
|
},
|
|
43
46
|
"dependencies": {
|
|
47
|
+
"@oxlint/plugins": "1.58.0",
|
|
44
48
|
"dayjs": "1.11.19",
|
|
45
49
|
"nanoid": "5.1.6",
|
|
46
50
|
"ofetch": "1.5.1",
|
|
47
|
-
"
|
|
48
|
-
"remeda": "2.32.0",
|
|
49
|
-
"valibot": "1.1.0"
|
|
51
|
+
"remeda": "2.32.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
54
|
"@testing-library/react": "16.3.0",
|
|
53
55
|
"@types/node": "25.0.1",
|
|
54
56
|
"@types/react": "19.2.7",
|
|
55
57
|
"jsdom": "27.4.0",
|
|
56
|
-
"oxfmt": "0.
|
|
58
|
+
"oxfmt": "0.43.0",
|
|
59
|
+
"oxlint": "1.58.0",
|
|
57
60
|
"react": "19.2.3",
|
|
58
|
-
"tsdown": "0.
|
|
59
|
-
"typescript": "
|
|
61
|
+
"tsdown": "0.21.7",
|
|
62
|
+
"typescript": "6.0.2",
|
|
63
|
+
"valibot": "1.1.0",
|
|
60
64
|
"vitest": "4.0.15"
|
|
61
65
|
},
|
|
62
66
|
"peerDependencies": {
|
|
63
67
|
"consola": ">=3.0.0",
|
|
64
68
|
"drizzle-orm": ">=0.44.0",
|
|
69
|
+
"oxlint": ">=1.58.0",
|
|
65
70
|
"react": ">=18.0.0",
|
|
66
|
-
"react-dom": ">=18.0.0"
|
|
71
|
+
"react-dom": ">=18.0.0",
|
|
72
|
+
"valibot": ">=1.3.1"
|
|
67
73
|
},
|
|
68
74
|
"scripts": {
|
|
69
75
|
"dev": "tsdown --watch",
|