@nightstem/utils 0.0.1-alpha.1 → 0.0.1-alpha.2
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/README.md +51 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# @nightstem/utils
|
|
2
|
+
|
|
3
|
+
Framework-agnostic utilities for the Nightstem design system.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @nightstem/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### `cn(...inputs)`
|
|
14
|
+
|
|
15
|
+
Merges Tailwind CSS class names, resolving conflicts via `tailwind-merge` and handling conditional classes via `clsx`.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { cn } from '@nightstem/utils';
|
|
19
|
+
|
|
20
|
+
cn('px-4 py-2', condition && 'bg-blue-500', 'px-2');
|
|
21
|
+
// → 'py-2 bg-blue-500 px-2' (px-4 overridden by px-2)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### `hashIndex(seed, max)`
|
|
25
|
+
|
|
26
|
+
Deterministically maps a string to an integer in `[0, max)`. Same seed and max always return the same index — useful for stable color or avatar assignments.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { hashIndex } from '@nightstem/utils';
|
|
30
|
+
|
|
31
|
+
hashIndex('alice', 5); // → e.g. 3 (stable across calls)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Parameter | Type | Description |
|
|
35
|
+
| --------- | -------- | ----------------------------------------------------------- |
|
|
36
|
+
| `seed` | `string` | Input string to hash |
|
|
37
|
+
| `max` | `number` | Upper bound (exclusive). Must be > 1, otherwise returns `0` |
|
|
38
|
+
|
|
39
|
+
### `randomInt(max)`
|
|
40
|
+
|
|
41
|
+
Returns a cryptographically random integer in `[0, max)` using `crypto.getRandomValues`.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { randomInt } from '@nightstem/utils';
|
|
45
|
+
|
|
46
|
+
randomInt(10); // → e.g. 7
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Parameter | Type | Description |
|
|
50
|
+
| --------- | -------- | ----------------------------------------------------------- |
|
|
51
|
+
| `max` | `number` | Upper bound (exclusive). Must be > 1, otherwise returns `0` |
|