@dxtmisha/wiki 0.24.0 → 0.24.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dxtmisha/wiki",
3
3
  "private": false,
4
- "version": "0.24.0",
4
+ "version": "0.24.1",
5
5
  "type": "module",
6
6
  "description": "Wiki documentation and storybook utilities for DXT UI design system",
7
7
  "keywords": [
@@ -0,0 +1,55 @@
1
+ import {Meta} from '@storybook/addon-docs/blocks'
2
+
3
+ <Meta title='@dxtmisha/functional/en/About'/>
4
+
5
+ # @dxtmisha/functional
6
+
7
+ Functional utilities library for DXT UI ecosystem. Contains ready-made solutions for common web development tasks: HTTP requests, geolocation, date handling, data caching, and more.
8
+
9
+ ## Package Contents
10
+
11
+ ### Classes (20+)
12
+
13
+ - **Api** — HTTP requests with caching support, loading indicators, and response mocking
14
+ - **Geo** — detecting user's country and language, working with geodata and timezones
15
+ - **Datetime** — date handling: formatting, manipulation, comparison with localization support
16
+ - **Cache** — data caching system with automatic invalidation
17
+ - **GeoFlag** — access to country flags (200+) with localized names
18
+ - **GeoPhone** — phone codes and formatting masks for all countries
19
+ - **GeoIntl** — internationalization: formatting numbers, currencies, dates by regional standards
20
+ - **Cookie** — convenient cookie handling
21
+ - **Hash** — URL hash parameter management
22
+ - **DataStorage** — typed localStorage and sessionStorage operations
23
+ - **Loading** — global loading indicator management
24
+ - **Translate** — translation system with placeholder support
25
+ - **Icons** — icon and SVG sprite management
26
+
27
+ ### Vue 3 Composables (10+)
28
+
29
+ Reactive wrappers over classes for use in Vue components:
30
+
31
+ - **useApiRef** — reactive HTTP requests with automatic loading state management
32
+ - **useGeoIntlRef** — reactive formatting based on user locale
33
+ - **useStorageRef** — two-way ref synchronization with localStorage/sessionStorage
34
+ - **useHashRef** — two-way ref synchronization with URL hash
35
+ - **useCookieRef** — reactive cookie operations
36
+ - **useLoadingRef** — reactive loading state tracking
37
+ - **useTranslateRef** — reactive translation system
38
+
39
+ ### Helper Functions (100+)
40
+
41
+ **Arrays:** convert to array, filter, iterate, fill, unique values
42
+
43
+ **Objects:** deep copy, merge objects, get values by path, compare
44
+
45
+ **Strings:** case conversion (camelCase, kebabCase), string filling, template application
46
+
47
+ **Validation:** type checking, emptiness checking, value comparison
48
+
49
+ **DOM utilities:** element search, element creation, attribute handling, scrolling
50
+
51
+ **Math:** safe number conversion, percentages, random numbers, step values
52
+
53
+ **Async:** safe promise and function execution, animation frame handling
54
+
55
+ **Clipboard:** copy and read clipboard data
@@ -13,7 +13,7 @@ Class for working with browser localStorage and sessionStorage with automatic se
13
13
  - **Automatic serialization** — JSON serialization/deserialization handled automatically
14
14
  - **Cache time validation** — optional cache expiration with automatic cleanup
15
15
  - **Singleton pattern** — reuses instances for same storage keys
16
- - **Prefix management** — configurable prefix for all storage keys
16
+ - **Prefix management** — configurable prefix for all storage keys (default 'ui-storage')
17
17
  - **Function value support** — accepts functions as values for dynamic data generation
18
18
  - **Browser compatibility** — safe usage with server-side rendering
19
19
 
@@ -26,6 +26,8 @@ Sets the global prefix for all storage keys. Should be called at application sta
26
26
  **Parameters:**
27
27
  - `newPrefix: string` — new prefix for storage keys
28
28
 
29
+ **Returns:** `void`
30
+
29
31
  ```javascript
30
32
  import { DataStorage } from '@dxtmisha/functional'
31
33
 
@@ -33,7 +35,8 @@ import { DataStorage } from '@dxtmisha/functional'
33
35
  DataStorage.setPrefix('myapp-storage')
34
36
 
35
37
  // All storage keys will now use this prefix:
36
- // 'user-settings' → 'myapp-storage-user-settings'
38
+ // 'user-settings' → 'myapp-storage__user-settings'
39
+ // Default prefix: 'ui-storage'
37
40
  ```
38
41
 
39
42
  ## Constructor
@@ -46,6 +49,8 @@ Creates DataStorage instance for specified key. Uses singleton pattern.
46
49
  - `name: string` — storage key name
47
50
  - `isSession?: boolean` — use sessionStorage instead of localStorage (default: false)
48
51
 
52
+ **Returns:** `DataStorage<T>` — class instance (or existing from cache)
53
+
49
54
  ```javascript
50
55
  // localStorage instance
51
56
  const userPrefs = new DataStorage('user-preferences')
@@ -66,7 +71,7 @@ Retrieves data from storage with optional default value and cache validation.
66
71
 
67
72
  **Parameters:**
68
73
  - `defaultValue?: T | (() => T)` — default value or function if no data found (optional)
69
- - `cache?: number` — cache time in seconds for validation (optional)
74
+ - `cache?: number` — cache time in **seconds** for validation (optional)
70
75
 
71
76
  **Returns:** `T | undefined` — stored data, default value, or undefined
72
77
 
@@ -88,8 +93,10 @@ const config = settings.get(() => ({
88
93
  created: Date.now()
89
94
  }))
90
95
 
91
- // Get with cache validation (10 minutes)
92
- const cachedData = settings.get(null, 600) // Returns null if data older than 10 minutes
96
+ // Get with cache validation (600 seconds = 10 minutes)
97
+ const cachedData = settings.get(null, 600)
98
+ // Returns undefined if data older than 10 minutes
99
+ // Returns stored data if cache is valid
93
100
  ```
94
101
 
95
102
  ### `set`
@@ -99,7 +106,7 @@ Stores data in storage with automatic serialization.
99
106
  **Parameters:**
100
107
  - `value?: T | (() => T)` — value to store or function that returns value (optional)
101
108
 
102
- **Returns:** `T | undefined` — the stored value
109
+ **Returns:** `T | undefined` — stored value
103
110
 
104
111
  ```javascript
105
112
  const userStorage = new DataStorage('user-data')
@@ -127,112 +134,83 @@ Removes data from storage.
127
134
  ```javascript
128
135
  const userStorage = new DataStorage('user-data')
129
136
 
130
- // First set some data
137
+ // First set data
131
138
  userStorage.set({ name: 'John', preferences: { theme: 'dark' } })
132
139
  console.log(userStorage.get()) // { name: 'John', preferences: { theme: 'dark' } }
133
140
 
134
- // Simple removal
141
+ // Remove
135
142
  userStorage.remove()
136
143
  console.log(userStorage.get()) // undefined
137
144
 
138
- // Method chaining with other DataStorage instances
139
- const tempStorage = new DataStorage('temp-data')
140
- const anotherStorage = new DataStorage('another-data')
145
+ // Method chaining
146
+ userStorage
147
+ .set({ temp: 'data' })
148
+ .remove() // Removes just saved data
149
+ ```
141
150
 
142
- // Chain operations across different instances
143
- tempStorage.set({ temp: true })
144
- anotherStorage.set({ another: true })
151
+ ### `update`
145
152
 
146
- tempStorage.remove() // Remove temp data
147
- anotherStorage.remove() // Remove another data
153
+ Updates data from storage by re-reading it.
148
154
 
149
- console.log(tempStorage.get()) // undefined
150
- console.log(anotherStorage.get()) // undefined
151
- ```
155
+ **Returns:** `this` — DataStorage instance for method chaining
152
156
 
153
- ## Practical Examples
157
+ ```javascript
158
+ const storage = new DataStorage('shared-data')
154
159
 
155
- ### User Settings
160
+ // Set data
161
+ storage.set({ value: 'initial' })
162
+ console.log(storage.get()) // { value: 'initial' }
156
163
 
157
- ```javascript
158
- class UserSettings {
159
- constructor() {
160
- this.storage = new DataStorage('user-settings')
161
- }
162
-
163
- getTheme() {
164
- return this.storage.get('theme', 'light')
165
- }
166
-
167
- setTheme(theme) {
168
- this.storage.set('theme', theme)
169
- }
170
-
171
- getLanguage() {
172
- return this.storage.get('language', 'en')
173
- }
174
-
175
- setLanguage(language) {
176
- this.storage.set('language', language)
177
- }
178
-
179
- exportSettings() {
180
- return {
181
- theme: this.getTheme(),
182
- language: this.getLanguage(),
183
- notifications: this.storage.get('notifications', true)
184
- }
185
- }
186
- }
164
+ // Data changed in another tab/browser window
165
+ // or directly via localStorage.setItem()
187
166
 
188
- // Usage
189
- const settings = new UserSettings()
190
- settings.setTheme('dark')
191
- console.log('Settings:', settings.exportSettings())
167
+ // Update data from storage
168
+ storage.update()
169
+ console.log(storage.get()) // Gets actual data from storage
170
+
171
+ // Method chaining
172
+ storage.update().get() // Update and get fresh data
192
173
  ```
193
174
 
194
- ### Application Cache
175
+ ## Practical Examples
176
+
177
+ ### User Settings
195
178
 
196
179
  ```javascript
197
- const appCache = new DataStorage('app-cache', 'sessionStorage')
180
+ const settings = new DataStorage('user-settings')
198
181
 
199
- function cacheApiData(endpoint, data) {
200
- const key = `api_${endpoint.replace(/\//g, '_')}`
201
- appCache.set(key, { data, timestamp: Date.now() }, 5 * 60 * 1000) // 5 minutes
202
- }
182
+ // Get with default value
183
+ const theme = settings.get(() => 'light')
184
+ console.log(theme) // 'light' or saved value
203
185
 
204
- function getCachedData(endpoint) {
205
- const key = `api_${endpoint.replace(/\//g, '_')}`
206
- return appCache.get(key)
207
- }
186
+ // Save new value
187
+ settings.set('dark')
208
188
 
209
- // Usage
210
- cacheApiData('/users', [{ id: 1, name: 'John' }])
211
- const cached = getCachedData('/users')
212
- console.log('Cached data:', cached)
189
+ // Remove settings
190
+ settings.remove()
213
191
  ```
214
192
 
215
- ### Form State
193
+ ### Data Cache with TTL
216
194
 
217
195
  ```javascript
218
- const formStorage = new DataStorage('form-draft')
196
+ async function fetchWithCache(url, cacheDuration = 300) {
197
+ const storage = new DataStorage(`api_${url}`)
219
198
 
220
- function saveFormDraft(formData) {
221
- formStorage.set('draft', formData)
222
- }
199
+ // Try to get from cache (cacheDuration in seconds)
200
+ const cached = storage.get(undefined, cacheDuration)
201
+ if (cached) return cached
223
202
 
224
- function loadFormDraft() {
225
- return formStorage.get('draft', {})
226
- }
203
+ // Load fresh data
204
+ const response = await fetch(url)
205
+ const data = await response.json()
227
206
 
228
- function clearFormDraft() {
229
- formStorage.remove('draft')
207
+ // Save to cache
208
+ storage.set(data)
209
+ return data
230
210
  }
231
211
 
232
212
  // Usage
233
- saveFormDraft({ name: 'John', email: 'john@example.com' })
234
- const draft = loadFormDraft()
235
- console.log('Form draft:', draft)
213
+ const users = await fetchWithCache('/api/users', 600) // Cache for 10 minutes
236
214
  ```
237
215
 
238
- The DataStorage class provides a unified interface for working with browser storage, ensuring type safety, automatic serialization, and flexible TTL management.
216
+ DataStorage class provides a unified interface for working with browser storage, ensuring type safety, automatic serialization, and flexible data lifetime management with singleton pattern support for efficient memory usage.