solid-tiny-utils 0.0.1
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/LICENSE +21 -0
- package/README.md +77 -0
- package/dist/chunk-2BUPSB7O.js +0 -0
- package/dist/chunk-4L6FK7MF.js +9 -0
- package/dist/chunk-7K22IJFO.js +12 -0
- package/dist/chunk-EZML2DEC.js +0 -0
- package/dist/chunk-PEWQLY2D.js +12 -0
- package/dist/chunk-QKJKTJQE.js +0 -0
- package/dist/chunk-WAZBT4BV.js +23 -0
- package/dist/chunk-ZHWDHAF3.js +56 -0
- package/dist/chunk-ZZNAXGNU.js +0 -0
- package/dist/fn/create-debounce.d.ts +6 -0
- package/dist/fn/create-debounce.js +10 -0
- package/dist/fn/create-loop-exec.d.ts +21 -0
- package/dist/fn/create-loop-exec.js +10 -0
- package/dist/fn/index.d.ts +4 -0
- package/dist/fn/index.js +15 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +28 -0
- package/dist/is/index.d.ts +4 -0
- package/dist/is/index.js +8 -0
- package/dist/reactive/access.d.ts +6 -0
- package/dist/reactive/access.js +7 -0
- package/dist/reactive/create-watch.d.ts +5 -0
- package/dist/reactive/create-watch.js +6 -0
- package/dist/reactive/index.d.ts +4 -0
- package/dist/reactive/index.js +12 -0
- package/dist/types/fn.d.ts +3 -0
- package/dist/types/fn.js +0 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +2 -0
- package/dist/types/maybe.d.ts +7 -0
- package/dist/types/maybe.js +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 g-mero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# solid-tiny-utils
|
|
2
|
+
|
|
3
|
+
Tiny utilities for SolidJS applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add solid-tiny-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { access, createWatch, CreateLoopExec, isFn, isArray } from 'solid-tiny-utils';
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## API
|
|
18
|
+
|
|
19
|
+
### Reactive
|
|
20
|
+
|
|
21
|
+
#### `access(value)`
|
|
22
|
+
Safely access a value that might be an accessor function.
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
const value = access(maybeAccessor); // Returns the value directly or calls the accessor
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
#### `createWatch(targets, fn, options?)`
|
|
29
|
+
Create a watcher that runs when dependencies change.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
createWatch(() => signal(), (value) => {
|
|
33
|
+
console.log('Value changed:', value);
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Functions
|
|
38
|
+
|
|
39
|
+
#### `CreateLoopExec(fn, delay)`
|
|
40
|
+
Execute a function in a loop with cleanup support.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
CreateLoopExec(
|
|
44
|
+
async () => {
|
|
45
|
+
// Your async work here
|
|
46
|
+
},
|
|
47
|
+
1000 // Delay in milliseconds
|
|
48
|
+
);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Type Guards
|
|
52
|
+
|
|
53
|
+
#### `isFn(value)`
|
|
54
|
+
Check if a value is a function.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
if (isFn(value)) {
|
|
58
|
+
value(); // TypeScript knows it's a function
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### `isArray(value)`
|
|
63
|
+
Check if a value is an array.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
if (isArray(value)) {
|
|
67
|
+
value.forEach(...); // TypeScript knows it's an array
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Types
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
type MaybeArray<T> = T | T[];
|
|
75
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
76
|
+
type MaybeAccessor<T> = T | Accessor<T>;
|
|
77
|
+
```
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
access
|
|
3
|
+
} from "./chunk-7K22IJFO.js";
|
|
4
|
+
|
|
5
|
+
// src/fn/create-debounce.ts
|
|
6
|
+
import { onCleanup } from "solid-js";
|
|
7
|
+
function createDebounce(callback, delay) {
|
|
8
|
+
let timeoutId;
|
|
9
|
+
onCleanup(() => {
|
|
10
|
+
clearTimeout(timeoutId);
|
|
11
|
+
});
|
|
12
|
+
const run = (...args) => {
|
|
13
|
+
clearTimeout(timeoutId);
|
|
14
|
+
timeoutId = setTimeout(() => {
|
|
15
|
+
callback(...args);
|
|
16
|
+
}, access(delay));
|
|
17
|
+
};
|
|
18
|
+
return run;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
createDebounce
|
|
23
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
access
|
|
3
|
+
} from "./chunk-7K22IJFO.js";
|
|
4
|
+
import {
|
|
5
|
+
createWatch
|
|
6
|
+
} from "./chunk-4L6FK7MF.js";
|
|
7
|
+
|
|
8
|
+
// src/fn/create-loop-exec.ts
|
|
9
|
+
import { onCleanup } from "solid-js";
|
|
10
|
+
function createLoopExec(fn, delay) {
|
|
11
|
+
let shouldStop = false;
|
|
12
|
+
let isCleanedUp = false;
|
|
13
|
+
let timer;
|
|
14
|
+
const execFn = async () => {
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
if (shouldStop) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
await fn();
|
|
21
|
+
} finally {
|
|
22
|
+
timer = setTimeout(() => {
|
|
23
|
+
execFn();
|
|
24
|
+
}, access(delay));
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
createWatch(
|
|
28
|
+
() => access(delay),
|
|
29
|
+
() => {
|
|
30
|
+
execFn();
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
const stop = () => {
|
|
34
|
+
shouldStop = true;
|
|
35
|
+
clearTimeout(timer);
|
|
36
|
+
};
|
|
37
|
+
const start = () => {
|
|
38
|
+
if (isCleanedUp) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
shouldStop = false;
|
|
42
|
+
execFn();
|
|
43
|
+
};
|
|
44
|
+
onCleanup(() => {
|
|
45
|
+
isCleanedUp = true;
|
|
46
|
+
stop();
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
stop,
|
|
50
|
+
start
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
createLoopExec
|
|
56
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { MaybePromise, MaybeAccessor } from '../types/maybe.js';
|
|
2
|
+
import 'solid-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Repeatedly executes an asynchronous function with a specified delay between each execution.
|
|
6
|
+
* The loop continues until the surrounding SolidJS effect is cleaned up.
|
|
7
|
+
*
|
|
8
|
+
* @param fn - The asynchronous function to execute in a loop. Can return a promise or void.
|
|
9
|
+
* @param delay - The delay (in milliseconds) between each execution. Can be a number or a reactive accessor.
|
|
10
|
+
*
|
|
11
|
+
* @remarks
|
|
12
|
+
* - The loop is automatically stopped when cleanup.
|
|
13
|
+
* - `fn`'s error will not stop scheduling.
|
|
14
|
+
* - Uses `setTimeout` for scheduling and `onCleanup` for resource management.
|
|
15
|
+
*/
|
|
16
|
+
declare function createLoopExec(fn: () => MaybePromise<void>, delay: MaybeAccessor<number>): {
|
|
17
|
+
stop: () => void;
|
|
18
|
+
start: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { createLoopExec };
|
package/dist/fn/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "../chunk-QKJKTJQE.js";
|
|
2
|
+
import {
|
|
3
|
+
createDebounce
|
|
4
|
+
} from "../chunk-WAZBT4BV.js";
|
|
5
|
+
import {
|
|
6
|
+
createLoopExec
|
|
7
|
+
} from "../chunk-ZHWDHAF3.js";
|
|
8
|
+
import "../chunk-ZZNAXGNU.js";
|
|
9
|
+
import "../chunk-7K22IJFO.js";
|
|
10
|
+
import "../chunk-PEWQLY2D.js";
|
|
11
|
+
import "../chunk-4L6FK7MF.js";
|
|
12
|
+
export {
|
|
13
|
+
createDebounce,
|
|
14
|
+
createLoopExec
|
|
15
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createDebounce } from './fn/create-debounce.js';
|
|
2
|
+
export { createLoopExec } from './fn/create-loop-exec.js';
|
|
3
|
+
export { isArray, isFn } from './is/index.js';
|
|
4
|
+
export { access } from './reactive/access.js';
|
|
5
|
+
export { createWatch } from './reactive/create-watch.js';
|
|
6
|
+
export { MaybeAccessor, MaybeArray, MaybePromise } from './types/maybe.js';
|
|
7
|
+
import 'solid-js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "./chunk-2BUPSB7O.js";
|
|
2
|
+
import "./chunk-EZML2DEC.js";
|
|
3
|
+
import "./chunk-QKJKTJQE.js";
|
|
4
|
+
import {
|
|
5
|
+
createDebounce
|
|
6
|
+
} from "./chunk-WAZBT4BV.js";
|
|
7
|
+
import {
|
|
8
|
+
createLoopExec
|
|
9
|
+
} from "./chunk-ZHWDHAF3.js";
|
|
10
|
+
import "./chunk-ZZNAXGNU.js";
|
|
11
|
+
import {
|
|
12
|
+
access
|
|
13
|
+
} from "./chunk-7K22IJFO.js";
|
|
14
|
+
import {
|
|
15
|
+
isArray,
|
|
16
|
+
isFn
|
|
17
|
+
} from "./chunk-PEWQLY2D.js";
|
|
18
|
+
import {
|
|
19
|
+
createWatch
|
|
20
|
+
} from "./chunk-4L6FK7MF.js";
|
|
21
|
+
export {
|
|
22
|
+
access,
|
|
23
|
+
createDebounce,
|
|
24
|
+
createLoopExec,
|
|
25
|
+
createWatch,
|
|
26
|
+
isArray,
|
|
27
|
+
isFn
|
|
28
|
+
};
|
package/dist/is/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AccessorArray, Accessor, OnEffectFunction, OnOptions } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
declare function createWatch<S, Next extends Prev, Prev = Next>(targets: AccessorArray<S> | Accessor<S>, fn: OnEffectFunction<S, undefined | NoInfer<Prev>, Next>, opt?: OnOptions): void;
|
|
4
|
+
|
|
5
|
+
export { createWatch };
|
package/dist/types/fn.js
ADDED
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../chunk-EZML2DEC.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "solid-tiny-utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A collection of tiny utilities for SolidJS applications",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"solid-js": "^1.9.7"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@biomejs/biome": "2.1.2",
|
|
16
|
+
"@vitest/ui": "^3.2.4",
|
|
17
|
+
"commit-and-tag-version": "^12.5.1",
|
|
18
|
+
"husky": "^9.1.7",
|
|
19
|
+
"jsdom": "^26.1.0",
|
|
20
|
+
"tsup": "^8.5.0",
|
|
21
|
+
"typescript": "^5.8.3",
|
|
22
|
+
"ultracite": "5.1.2",
|
|
23
|
+
"unocss": "^66.3.3",
|
|
24
|
+
"vite": "^6.2.1",
|
|
25
|
+
"vite-plugin-solid": "^2.11.0",
|
|
26
|
+
"vitest": "^3.2.4"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"solidjs",
|
|
30
|
+
"solid",
|
|
31
|
+
"utilities",
|
|
32
|
+
"reactive",
|
|
33
|
+
"typescript",
|
|
34
|
+
"utils"
|
|
35
|
+
],
|
|
36
|
+
"author": "",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"solid-tiny-context": "0.1.2"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "vite",
|
|
44
|
+
"test": "vitest",
|
|
45
|
+
"test:run": "vitest --run",
|
|
46
|
+
"test:ui": "vitest --ui",
|
|
47
|
+
"test:coverage": "vitest --coverage",
|
|
48
|
+
"lint": "npx ultracite lint",
|
|
49
|
+
"lint:fix": "npx ultracite format",
|
|
50
|
+
"type-check": "tsc --noEmit --skipLibCheck",
|
|
51
|
+
"release": "pnpm lint:fix && pnpm test:run &&commit-and-tag-version -i CHANGELOG.md --same-file",
|
|
52
|
+
"pub": "pnpm build && pnpm publish"
|
|
53
|
+
}
|
|
54
|
+
}
|