gjendje 0.1.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Charlie Beckstrand
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,143 @@
1
+ <img src="https://raw.githubusercontent.com/charliebeckstrand/habitat/main/logo.png" alt="Screenshot" width="100" />
2
+
3
+ # stead
4
+
5
+ **stead** brings state management to multiple storage backends through one consistent API.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add stead
11
+ ```
12
+
13
+ ## Examples
14
+
15
+ #### localStorage
16
+ ```ts
17
+ import { state } from 'stead'
18
+
19
+ const theme = state('theme', {
20
+ default: 'light',
21
+ scope: 'local',
22
+ ssr: true // optional AsyncLocalStorage
23
+ })
24
+
25
+ theme.get()
26
+ theme.set('dark')
27
+ ```
28
+
29
+ #### Storage Buckets
30
+ ```ts
31
+ import { state } from 'stead'
32
+
33
+ const settings = state('settings', {
34
+ default: { notifications: true, theme: 'light' },
35
+ scope: 'bucket',
36
+ bucket: {
37
+ name: 'app-settings',
38
+ },
39
+ })
40
+
41
+ await settings.ready
42
+
43
+ settings.set(prev => ({ ...prev, notifications: false }))
44
+ ```
45
+
46
+ ## Configure
47
+
48
+ ```ts
49
+ configure(config: SteadConfig): void
50
+ ```
51
+
52
+ Sets global defaults for all state instances. Call once at app startup before creating any state.
53
+
54
+ #### Settings
55
+
56
+ - `defaultScope` — `'render'`
57
+ - `keyPattern`
58
+ - `logLevel` — `'warn'`
59
+ - `maxKeys`
60
+ - `prefix`
61
+ - `requireValidation`
62
+ - `ssr`
63
+ - `sync`
64
+ - `warnOnDuplicate`
65
+
66
+ #### Lifecycle hooks
67
+
68
+ - `onDestroy`
69
+ - `onError`
70
+ - `onHydrate`
71
+ - `onMigrate`
72
+ - `onQuotaExceeded`
73
+ - `onRegister`
74
+ - `onSync`
75
+
76
+ [Full configure reference](https://github.com/charliebeckstrand/habitat/blob/main/docs/configure.md) — all options, validation, error handling, and examples.
77
+
78
+ ## Scopes
79
+
80
+ |Scope |Description |
81
+ |-----------|--------------------------------------------------------|
82
+ |`render` | `memory` |
83
+ |`local` |`localStorage` |
84
+ |`server` |`AsyncLocalStorage` |
85
+ |`bucket` | `Storage Buckets` |
86
+ |`url` |`URLSearchParams` |
87
+ |`tab` |`sessionStorage` |
88
+
89
+ ## API
90
+
91
+ Every `state()` instance exposes the same interface regardless of scope.
92
+
93
+ #### `get()`
94
+ Returns the current value. Reactive — triggers tracking in `computed` and `effect`.
95
+
96
+ #### `set(value)` / `set(prev => next)`
97
+ Replaces the current value. Accepts a direct value or an updater function that receives the previous value.
98
+
99
+ #### `subscribe(fn)`
100
+ Calls `fn` on every change. Returns an `unsubscribe` function.
101
+
102
+ #### `watch(key, fn)`
103
+ Like `subscribe`, but scoped to a single key within an object value. Only fires when that key changes.
104
+
105
+ #### `intercept(fn)`
106
+ Receives `(next, prev)` before each update. Return the value to store, or return `prev` to reject the change. Returns an `unsubscribe` function.
107
+
108
+ [Full API reference](https://github.com/charliebeckstrand/habitat/blob/main/docs/api.md) — all methods, promise lifecycle, options, and types.
109
+
110
+ ## Middleware
111
+
112
+ Primitives that plug into the update pipeline of any state instance.
113
+
114
+ #### `intercept(fn)`
115
+ Runs **before** a value is stored. Receives `(next, prev)` and returns the value to actually persist. Return `prev` to reject the update. Multiple interceptors run in registration order.
116
+
117
+ #### `use(fn)`
118
+ Runs **after** a value is stored. Receives `(next, prev)`. Return value is ignored. Useful for logging, analytics, or syncing external systems.
119
+
120
+ ## Derived state
121
+
122
+ Primitives that build on top of `state` to handle computed values, collections, and side effects.
123
+
124
+ #### `computed(deps, fn)`
125
+ Derives a reactive, read-only value from one or more state dependencies. Recomputes only when a dependency changes and caches the result between changes. Returns a `ReadonlyInstance` — no `set()` or `reset()`.
126
+
127
+ #### `collection(key, options)`
128
+ Reactive array with first-class mutation methods — `add`, `remove`, `update`, `find`, `findAll`, `has`, `clear`. Supports all the same scopes, persistence, validation, and migration as `state`.
129
+
130
+ #### `effect(deps, fn)`
131
+ Runs a side effect immediately and re-runs whenever any dependency changes. The callback can return a cleanup function that runs before the next execution and on `stop()`. Returns an `EffectHandle` with a `stop()` method.
132
+
133
+ ## React
134
+
135
+ [Full React API reference](https://github.com/charliebeckstrand/habitat/blob/main/docs/react.md)
136
+
137
+ ## License
138
+
139
+ MIT
140
+
141
+ ## Icon
142
+
143
+ Created by [Gulraiz](https://www.flaticon.com/authors/gulraiz)