@dxtmisha/functional 1.0.9
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 +767 -0
- package/dist/Icons-C2lZhD4l.js +1284 -0
- package/dist/classes/Api.d.ts +305 -0
- package/dist/classes/Cache.d.ts +34 -0
- package/dist/classes/CacheItem.d.ts +55 -0
- package/dist/classes/CacheStatic.d.ts +17 -0
- package/dist/classes/Cookie.d.ts +52 -0
- package/dist/classes/CookieBlock.d.ts +22 -0
- package/dist/classes/DataStorage.d.ts +70 -0
- package/dist/classes/Datetime.d.ts +482 -0
- package/dist/classes/EventItem.d.ts +160 -0
- package/dist/classes/Geo.d.ts +168 -0
- package/dist/classes/GeoFlag.d.ts +79 -0
- package/dist/classes/GeoIntl.d.ts +262 -0
- package/dist/classes/GeoPhone.d.ts +107 -0
- package/dist/classes/Global.d.ts +21 -0
- package/dist/classes/Hash.d.ts +59 -0
- package/dist/classes/Icons.d.ts +90 -0
- package/dist/classes/Loading.d.ts +49 -0
- package/dist/classes/ScrollbarWidth.d.ts +33 -0
- package/dist/classes/Translate.d.ts +116 -0
- package/dist/classes/design/DesignAbstract.d.ts +61 -0
- package/dist/classes/design/DesignAsyncAbstract.d.ts +28 -0
- package/dist/classes/design/DesignChanged.d.ts +42 -0
- package/dist/classes/design/DesignComp.d.ts +4 -0
- package/dist/classes/design/DesignComponents.d.ts +81 -0
- package/dist/classes/design/DesignConstructorAbstract.d.ts +150 -0
- package/dist/classes/ref/DatetimeRef.d.ts +119 -0
- package/dist/classes/ref/EventRef.d.ts +23 -0
- package/dist/classes/ref/GeoFlagRef.d.ts +52 -0
- package/dist/classes/ref/GeoIntlRef.d.ts +173 -0
- package/dist/classes/ref/GeoRef.d.ts +52 -0
- package/dist/classes/ref/ListDataRef.d.ts +228 -0
- package/dist/classes/ref/RouterItemRef.d.ts +36 -0
- package/dist/classes/ref/ScrollbarWidthRef.d.ts +24 -0
- package/dist/composables/ref/useApiRef.d.ts +25 -0
- package/dist/composables/ref/useCookieRef.d.ts +11 -0
- package/dist/composables/ref/useGeoIntlRef.d.ts +7 -0
- package/dist/composables/ref/useHashRef.d.ts +9 -0
- package/dist/composables/ref/useLazyRef.d.ts +33 -0
- package/dist/composables/ref/useLoadingRef.d.ts +7 -0
- package/dist/composables/ref/useSessionRef.d.ts +9 -0
- package/dist/composables/ref/useStorageRef.d.ts +10 -0
- package/dist/composables/ref/useTranslateRef.d.ts +16 -0
- package/dist/flags.d.ts +1 -0
- package/dist/flags.js +8 -0
- package/dist/functions/anyToString.d.ts +7 -0
- package/dist/functions/applyTemplate.d.ts +10 -0
- package/dist/functions/arrFill.d.ts +8 -0
- package/dist/functions/copyObject.d.ts +8 -0
- package/dist/functions/createElement.d.ts +13 -0
- package/dist/functions/domQuerySelector.d.ts +7 -0
- package/dist/functions/domQuerySelectorAll.d.ts +7 -0
- package/dist/functions/eventStopPropagation.d.ts +7 -0
- package/dist/functions/executeFunction.d.ts +8 -0
- package/dist/functions/executePromise.d.ts +7 -0
- package/dist/functions/executeUse.d.ts +11 -0
- package/dist/functions/forEach.d.ts +11 -0
- package/dist/functions/frame.d.ts +16 -0
- package/dist/functions/getAttributes.d.ts +8 -0
- package/dist/functions/getClipboardData.d.ts +11 -0
- package/dist/functions/getColumn.d.ts +10 -0
- package/dist/functions/getElement.d.ts +8 -0
- package/dist/functions/getElementId.d.ts +9 -0
- package/dist/functions/getElementItem.d.ts +11 -0
- package/dist/functions/getElementOrWindow.d.ts +8 -0
- package/dist/functions/getExp.d.ts +13 -0
- package/dist/functions/getItemByPath.d.ts +8 -0
- package/dist/functions/getKey.d.ts +7 -0
- package/dist/functions/getLengthOfAllArray.d.ts +8 -0
- package/dist/functions/getMaxLengthAllArray.d.ts +8 -0
- package/dist/functions/getMinLengthAllArray.d.ts +8 -0
- package/dist/functions/getMouseClient.d.ts +8 -0
- package/dist/functions/getMouseClientX.d.ts +7 -0
- package/dist/functions/getMouseClientY.d.ts +7 -0
- package/dist/functions/getObjectByKeys.d.ts +8 -0
- package/dist/functions/getObjectNoUndefined.d.ts +8 -0
- package/dist/functions/getObjectOrNone.d.ts +7 -0
- package/dist/functions/getRandomText.d.ts +11 -0
- package/dist/functions/getRequestString.d.ts +9 -0
- package/dist/functions/getStepPercent.d.ts +8 -0
- package/dist/functions/getStepValue.d.ts +8 -0
- package/dist/functions/goScroll.d.ts +10 -0
- package/dist/functions/inArray.d.ts +8 -0
- package/dist/functions/initScrollbarOffset.d.ts +6 -0
- package/dist/functions/intersectKey.d.ts +8 -0
- package/dist/functions/isArray.d.ts +7 -0
- package/dist/functions/isDifferent.d.ts +9 -0
- package/dist/functions/isDomRuntime.d.ts +10 -0
- package/dist/functions/isFilled.d.ts +9 -0
- package/dist/functions/isFloat.d.ts +7 -0
- package/dist/functions/isFunction.d.ts +8 -0
- package/dist/functions/isInDom.d.ts +8 -0
- package/dist/functions/isIntegerBetween.d.ts +8 -0
- package/dist/functions/isNull.d.ts +8 -0
- package/dist/functions/isNumber.d.ts +7 -0
- package/dist/functions/isObject.d.ts +7 -0
- package/dist/functions/isObjectNotArray.d.ts +7 -0
- package/dist/functions/isSelected.d.ts +8 -0
- package/dist/functions/isSelectedByList.d.ts +8 -0
- package/dist/functions/isString.d.ts +7 -0
- package/dist/functions/isWindow.d.ts +7 -0
- package/dist/functions/random.d.ts +8 -0
- package/dist/functions/ref/getBindRef.d.ts +13 -0
- package/dist/functions/ref/getComputedAsync.d.ts +9 -0
- package/dist/functions/ref/getRef.d.ts +8 -0
- package/dist/functions/ref/render.d.ts +13 -0
- package/dist/functions/ref/setRef.d.ts +9 -0
- package/dist/functions/ref/toComputed.d.ts +8 -0
- package/dist/functions/ref/toRefItem.d.ts +9 -0
- package/dist/functions/render/getBind.d.ts +14 -0
- package/dist/functions/render/getClassName.d.ts +8 -0
- package/dist/functions/render/getIndexForRender.d.ts +10 -0
- package/dist/functions/replaceRecursive.d.ts +10 -0
- package/dist/functions/replaceTemplate.d.ts +9 -0
- package/dist/functions/secondToTime.d.ts +7 -0
- package/dist/functions/setElementItem.d.ts +10 -0
- package/dist/functions/setValues.d.ts +17 -0
- package/dist/functions/splice.d.ts +12 -0
- package/dist/functions/strFill.d.ts +8 -0
- package/dist/functions/toArray.d.ts +17 -0
- package/dist/functions/toBind.d.ts +10 -0
- package/dist/functions/toBinds.d.ts +9 -0
- package/dist/functions/toCamelCase.d.ts +7 -0
- package/dist/functions/toCamelCaseFirst.d.ts +7 -0
- package/dist/functions/toDate.d.ts +7 -0
- package/dist/functions/toKebabCase.d.ts +15 -0
- package/dist/functions/toNumber.d.ts +8 -0
- package/dist/functions/toNumberByMax.d.ts +9 -0
- package/dist/functions/toPercent.d.ts +8 -0
- package/dist/functions/toPercentBy100.d.ts +8 -0
- package/dist/functions/transformation.d.ts +21 -0
- package/dist/functions/uniqueArray.d.ts +7 -0
- package/dist/functions/writeClipboardData.d.ts +7 -0
- package/dist/library.d.ts +135 -0
- package/dist/library.js +4254 -0
- package/dist/types/basicTypes.d.ts +126 -0
- package/dist/types/constructorTypes.d.ts +114 -0
- package/dist/types/geoTypes.d.ts +86 -0
- package/dist/types/listTypes.d.ts +61 -0
- package/dist/types/refTypes.d.ts +36 -0
- package/package.json +77 -0
package/README.md
ADDED
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
# @dxtmisha/functional
|
|
2
|
+
|
|
3
|
+
> Comprehensive functional utility library for modern web development
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@dxtmisha/functional)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
A powerful utility library for DXT UI ecosystem, providing classes, composables, functions, and types for modern development with TypeScript and Vue 3. Full tree-shaking support, works with or without Vue.
|
|
10
|
+
|
|
11
|
+
## 📦 Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @dxtmisha/functional
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @dxtmisha/functional
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm add @dxtmisha/functional
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✨ Features
|
|
26
|
+
|
|
27
|
+
- 🏗️ **20+ Utility Classes** — Api, Cache, Geo, Datetime, Hash, Cookie, DataStorage, and more
|
|
28
|
+
- 🎯 **10+ Vue Composables** — useApiRef, useGeoIntlRef, useStorageRef, useHashRef, and more
|
|
29
|
+
- 🔧 **100+ Helper Functions** — for arrays, objects, strings, DOM, validation, and math
|
|
30
|
+
- 📝 **TypeScript Types** — full type coverage for all utilities
|
|
31
|
+
- ⚡ **Tree-shakeable** — import only what you use
|
|
32
|
+
- 🌍 **Geolocation & i18n** — auto-detect country, language, and formatting
|
|
33
|
+
- 🎨 **Country Flags** — 200+ flags with localized country names
|
|
34
|
+
- 📞 **Phone Masks** — international codes and number formatting
|
|
35
|
+
- 💾 **Caching** — intelligent cache system with invalidation
|
|
36
|
+
- 🌐 **HTTP Client** — extended API class with caching and loading indicators
|
|
37
|
+
- 📦 **Optional Vue Integration** — works with or without Vue
|
|
38
|
+
|
|
39
|
+
## 🚀 Quick Start
|
|
40
|
+
|
|
41
|
+
### Utility Functions
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import {
|
|
45
|
+
toArray,
|
|
46
|
+
forEach,
|
|
47
|
+
toCamelCase,
|
|
48
|
+
toKebabCase,
|
|
49
|
+
transformation,
|
|
50
|
+
copyObject,
|
|
51
|
+
isFilled
|
|
52
|
+
} from '@dxtmisha/functional'
|
|
53
|
+
|
|
54
|
+
// Array operations
|
|
55
|
+
const items = toArray('single') // ['single']
|
|
56
|
+
forEach([1, 2, 3], (item) => console.log(item))
|
|
57
|
+
|
|
58
|
+
// String case transformations
|
|
59
|
+
const camel = toCamelCase('my-variable-name') // 'myVariableName'
|
|
60
|
+
const kebab = toKebabCase('myVariableName') // 'my-variable-name'
|
|
61
|
+
|
|
62
|
+
// Object operations
|
|
63
|
+
const data = transformation('{"name":"test"}') // { name: 'test' }
|
|
64
|
+
const copy = copyObject({ deep: { object: true } })
|
|
65
|
+
|
|
66
|
+
// Validation
|
|
67
|
+
if (isFilled(value)) {
|
|
68
|
+
// value is not empty
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Utility Classes
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import {
|
|
76
|
+
Cache,
|
|
77
|
+
Datetime,
|
|
78
|
+
Geo,
|
|
79
|
+
Hash,
|
|
80
|
+
Api,
|
|
81
|
+
Cookie,
|
|
82
|
+
DataStorage
|
|
83
|
+
} from '@dxtmisha/functional'
|
|
84
|
+
|
|
85
|
+
// Caching
|
|
86
|
+
const cache = new Cache()
|
|
87
|
+
const userData = cache.get('user', () => fetchUser())
|
|
88
|
+
|
|
89
|
+
// Date operations
|
|
90
|
+
const datetime = new Datetime('2024-10-15')
|
|
91
|
+
const formatted = datetime.format('YYYY-MM-DD HH:mm')
|
|
92
|
+
|
|
93
|
+
// Geolocation
|
|
94
|
+
const country = Geo.getCountry() // 'US'
|
|
95
|
+
const language = Geo.getLanguage() // 'en'
|
|
96
|
+
|
|
97
|
+
// URL Hash management
|
|
98
|
+
Hash.set('userId', '12345')
|
|
99
|
+
const userId = Hash.get('userId')
|
|
100
|
+
|
|
101
|
+
// HTTP requests
|
|
102
|
+
const api = new Api('/api')
|
|
103
|
+
const users = await api.get('/users')
|
|
104
|
+
|
|
105
|
+
// Cookie management
|
|
106
|
+
const theme = new Cookie('theme')
|
|
107
|
+
theme.set('dark')
|
|
108
|
+
|
|
109
|
+
// LocalStorage wrapper
|
|
110
|
+
const settings = new DataStorage('app-settings')
|
|
111
|
+
settings.set({ theme: 'dark' })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Vue Composables (Optional)
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import {
|
|
118
|
+
useGeoIntlRef,
|
|
119
|
+
useStorageRef,
|
|
120
|
+
useApiRef,
|
|
121
|
+
useHashRef,
|
|
122
|
+
useTranslateRef
|
|
123
|
+
} from '@dxtmisha/functional'
|
|
124
|
+
|
|
125
|
+
export default {
|
|
126
|
+
setup() {
|
|
127
|
+
// Reactive geolocation
|
|
128
|
+
const { country, language } = useGeoIntlRef()
|
|
129
|
+
|
|
130
|
+
// Reactive storage
|
|
131
|
+
const { value: theme, set: setTheme } = useStorageRef('theme', 'light')
|
|
132
|
+
|
|
133
|
+
// Reactive API requests
|
|
134
|
+
const { data, loading, error } = useApiRef('/api/users')
|
|
135
|
+
|
|
136
|
+
// Reactive URL hash
|
|
137
|
+
const { hash, setHash } = useHashRef()
|
|
138
|
+
|
|
139
|
+
// Reactive translations
|
|
140
|
+
const { t } = useTranslateRef()
|
|
141
|
+
|
|
142
|
+
return { country, language, theme, setTheme, data, loading }
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## 📚 API Documentation
|
|
148
|
+
|
|
149
|
+
### 🏗️ Classes
|
|
150
|
+
|
|
151
|
+
#### API & Network
|
|
152
|
+
|
|
153
|
+
**Api** — HTTP client with caching, loading indicators, and locale support
|
|
154
|
+
```typescript
|
|
155
|
+
Api.setUrl('/api/v1')
|
|
156
|
+
Api.setHeaders({ 'Authorization': 'Bearer token' })
|
|
157
|
+
const api = new Api()
|
|
158
|
+
const data = await api.get('/users')
|
|
159
|
+
const result = await api.post('/users', { name: 'John' })
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Loading** — Global loading indicator management
|
|
163
|
+
```typescript
|
|
164
|
+
Loading.show() // show loading
|
|
165
|
+
Loading.hide() // hide loading
|
|
166
|
+
if (Loading.is()) { /* is loading */ }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Caching
|
|
170
|
+
|
|
171
|
+
**Cache** — Manage multiple caches with automatic invalidation
|
|
172
|
+
```typescript
|
|
173
|
+
const cache = new Cache()
|
|
174
|
+
const data = cache.get('key', () => expensiveOperation(), [dep1, dep2])
|
|
175
|
+
const asyncData = await cache.getAsync('key', async () => await fetch())
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**CacheItem** — Low-level single cache value management
|
|
179
|
+
```typescript
|
|
180
|
+
const item = new CacheItem(() => computeValue())
|
|
181
|
+
const value = item.getCache([dependencies])
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**CacheStatic** — Static cache for global data
|
|
185
|
+
```typescript
|
|
186
|
+
CacheStatic.set('config', configuration)
|
|
187
|
+
const config = CacheStatic.get('config')
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Data Storage
|
|
191
|
+
|
|
192
|
+
**Cookie** — Cookie management with automatic serialization
|
|
193
|
+
```typescript
|
|
194
|
+
const theme = new Cookie('theme')
|
|
195
|
+
theme.set('dark', { age: 365 * 24 * 60 * 60 }) // 1 year
|
|
196
|
+
const value = theme.get('light') // with default
|
|
197
|
+
theme.remove()
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**CookieBlock** — Cookie consent management
|
|
201
|
+
```typescript
|
|
202
|
+
CookieBlock.set(true) // allow cookies
|
|
203
|
+
if (CookieBlock.isBlock()) { /* cookies blocked */ }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**DataStorage** — LocalStorage/SessionStorage wrapper
|
|
207
|
+
```typescript
|
|
208
|
+
const storage = new DataStorage('settings')
|
|
209
|
+
storage.set({ theme: 'dark', lang: 'en' })
|
|
210
|
+
const settings = storage.get({ theme: 'light' }) // with default
|
|
211
|
+
storage.clear()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Hash** — URL hash parameter management
|
|
215
|
+
```typescript
|
|
216
|
+
Hash.set('page', 'home')
|
|
217
|
+
Hash.set('userId', '123')
|
|
218
|
+
const page = Hash.get('page', 'home')
|
|
219
|
+
Hash.addWatch('theme', (theme) => applyTheme(theme))
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Global** — Global configuration storage
|
|
223
|
+
```typescript
|
|
224
|
+
Global.add({ apiUrl: 'https://api.example.com', version: '1.0' })
|
|
225
|
+
const apiUrl = Global.get('apiUrl')
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Geolocation & Internationalization
|
|
229
|
+
|
|
230
|
+
**Geo** — Location detection and geographic data
|
|
231
|
+
```typescript
|
|
232
|
+
const country = Geo.getCountry() // 'US'
|
|
233
|
+
const language = Geo.getLanguage() // 'en'
|
|
234
|
+
const standard = Geo.getStandard() // 'en-US'
|
|
235
|
+
Geo.set('en-US') // set locale
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**GeoIntl** — Locale-aware formatting (Intl API)
|
|
239
|
+
```typescript
|
|
240
|
+
const intl = new GeoIntl('en-US')
|
|
241
|
+
const formatted = intl.number(1234.56) // '1,234.56'
|
|
242
|
+
const currency = intl.currency(99.99, 'USD') // '$99.99'
|
|
243
|
+
const date = intl.date(new Date(), 'short') // '10/15/2024'
|
|
244
|
+
const relative = intl.relative(-2, 'day') // '2 days ago'
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**GeoFlag** — Country flags management
|
|
248
|
+
```typescript
|
|
249
|
+
const flag = new GeoFlag('en-US')
|
|
250
|
+
const usa = flag.get('US')
|
|
251
|
+
// { country: 'United States', icon: '@flag-us', value: 'US', ... }
|
|
252
|
+
const list = flag.getList() // list of all countries
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
**GeoPhone** — Phone codes and masks
|
|
256
|
+
```typescript
|
|
257
|
+
const phone = GeoPhone.get('US')
|
|
258
|
+
// { phone: 1, within: 1, mask: ['+1 (***) ***-****'], value: 'US' }
|
|
259
|
+
const info = GeoPhone.getByPhone('+14155551234')
|
|
260
|
+
// detect country by phone number
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### Date & Time
|
|
264
|
+
|
|
265
|
+
**Datetime** — Date operations and formatting
|
|
266
|
+
```typescript
|
|
267
|
+
const dt = new Datetime('2024-10-15', 'full', 'en-US')
|
|
268
|
+
const formatted = dt.format('YYYY-MM-DD HH:mm:ss')
|
|
269
|
+
const iso = dt.toIso() // ISO 8601 format
|
|
270
|
+
dt.moveByDay(5) // +5 days
|
|
271
|
+
dt.moveByMonth(-1) // -1 month
|
|
272
|
+
const year = dt.getYear()
|
|
273
|
+
const month = dt.getMonth()
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
#### Translations
|
|
277
|
+
|
|
278
|
+
**Translate** — Translation system with caching
|
|
279
|
+
```typescript
|
|
280
|
+
const text = await Translate.get('welcome.message')
|
|
281
|
+
const withVars = await Translate.get('hello.user', { name: 'John' })
|
|
282
|
+
const texts = await Translate.getList(['save', 'cancel', 'submit'])
|
|
283
|
+
const cached = Translate.getSync('button.save') // sync from cache
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
#### Icons
|
|
287
|
+
|
|
288
|
+
**Icons** — SVG icon management
|
|
289
|
+
```typescript
|
|
290
|
+
Icons.add('user', '/icons/user.svg')
|
|
291
|
+
const icon = await Icons.get('user')
|
|
292
|
+
const autoPath = await Icons.get('@arrow-left') // auto path
|
|
293
|
+
if (Icons.is('settings')) { /* icon exists */ }
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
#### Events
|
|
297
|
+
|
|
298
|
+
**EventItem** — DOM event management
|
|
299
|
+
```typescript
|
|
300
|
+
const event = new EventItem(element, 'click', handler)
|
|
301
|
+
event.start() // start listening
|
|
302
|
+
event.stop() // stop listening
|
|
303
|
+
event.toggle(true) // enable/disable
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
#### Utilities
|
|
307
|
+
|
|
308
|
+
**ScrollbarWidth** — Detect scrollbar width
|
|
309
|
+
```typescript
|
|
310
|
+
const width = await ScrollbarWidth.get() // width in px
|
|
311
|
+
const shouldHide = await ScrollbarWidth.is() // thin scrollbar?
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### 🎯 Vue Composables
|
|
315
|
+
|
|
316
|
+
**useApiRef** — Reactive HTTP requests
|
|
317
|
+
```typescript
|
|
318
|
+
const { data, loading, error, reload } = useApiRef('/api/users')
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**useCookieRef** — Reactive cookies
|
|
322
|
+
```typescript
|
|
323
|
+
const { value, set } = useCookieRef('theme', 'light')
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
**useGeoIntlRef** — Reactive geolocation
|
|
327
|
+
```typescript
|
|
328
|
+
const { country, language, intl } = useGeoIntlRef()
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**useHashRef** — Reactive URL hash
|
|
332
|
+
```typescript
|
|
333
|
+
const { hash, setHash } = useHashRef()
|
|
334
|
+
const userId = useHashRef('userId', '0')
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
**useLazyRef** — Lazy data loading
|
|
338
|
+
```typescript
|
|
339
|
+
const { value, load, loading } = useLazyRef(async () => await fetchData())
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
**useLoadingRef** — Reactive loading state
|
|
343
|
+
```typescript
|
|
344
|
+
const { loading, is, show, hide } = useLoadingRef()
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
**useSessionRef** — Reactive sessionStorage
|
|
348
|
+
```typescript
|
|
349
|
+
const { value, set } = useSessionRef('tempData', {})
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
**useStorageRef** — Reactive localStorage
|
|
353
|
+
```typescript
|
|
354
|
+
const { value, set, clear } = useStorageRef('settings', { theme: 'dark' })
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
**useTranslateRef** — Reactive translations
|
|
358
|
+
```typescript
|
|
359
|
+
const { t, locale, setLocale } = useTranslateRef()
|
|
360
|
+
const text = t('welcome.message')
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
### 🔧 Functions
|
|
364
|
+
|
|
365
|
+
#### Array Operations
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
toArray(value) // convert to array
|
|
369
|
+
arrFill(value, count) // create array with repetitions
|
|
370
|
+
forEach(data, callback) // universal iteration
|
|
371
|
+
uniqueArray(array) // remove duplicates
|
|
372
|
+
inArray(array, value) // check presence
|
|
373
|
+
getColumn(array, column) // extract column
|
|
374
|
+
splice(array, start, count) // immutable splice
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### Object Operations
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
copyObject(obj) // deep copy
|
|
381
|
+
isObjectNotArray(value) // check object (not array)
|
|
382
|
+
getObjectByKeys(obj, keys) // extract by keys
|
|
383
|
+
getObjectNoUndefined(obj) // remove undefined
|
|
384
|
+
replaceRecursive(data, search, replace) // recursive replace
|
|
385
|
+
setValues(obj, keys, value) // set values
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
#### String Operations
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
toCamelCase(str) // to camelCase
|
|
392
|
+
toKebabCase(str) // to kebab-case
|
|
393
|
+
toCamelCaseFirst(str) // capitalize first
|
|
394
|
+
anyToString(value) // universal string conversion
|
|
395
|
+
strFill(value, length, fill) // fill string
|
|
396
|
+
replaceTemplate(str, replacements) // replace templates
|
|
397
|
+
applyTemplate(text, data) // apply template
|
|
398
|
+
getRandomText(min, max) // generate random text
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
#### DOM Operations
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
getElement(selector) // get element
|
|
405
|
+
createElement(parent, tag, options) // create element
|
|
406
|
+
getElementId(element) // get/generate ID
|
|
407
|
+
getAttributes(element) // get attributes
|
|
408
|
+
setElementItem(element, name, value) // set attribute
|
|
409
|
+
domQuerySelector(selector) // safe querySelector
|
|
410
|
+
domQuerySelectorAll(selector) // safe querySelectorAll
|
|
411
|
+
goScroll(element, options) // smooth scroll
|
|
412
|
+
initScrollbarOffset() // scrollbar compensation
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
#### Events
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
eventStopPropagation(event) // stop propagation
|
|
419
|
+
getKey(event) // get pressed key
|
|
420
|
+
getMouseClient(event) // mouse/touch coordinates
|
|
421
|
+
getMouseClientX(event) // X coordinate
|
|
422
|
+
getMouseClientY(event) // Y coordinate
|
|
423
|
+
getClipboardData(event) // clipboard data
|
|
424
|
+
writeClipboardData(text) // write to clipboard
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
#### Validation
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
isFilled(value) // check if filled
|
|
431
|
+
isArray(value) // check array
|
|
432
|
+
isObject(value) // check object
|
|
433
|
+
isString(value) // check string
|
|
434
|
+
isNumber(value) // check number
|
|
435
|
+
isFunction(value) // check function
|
|
436
|
+
isFloat(value) // check float
|
|
437
|
+
isIntegerBetween(value, min, max) // check range
|
|
438
|
+
isDifferent(value1, value2) // check difference
|
|
439
|
+
isNull(value) // check null/undefined
|
|
440
|
+
isDomRuntime() // check browser environment
|
|
441
|
+
isWindow(element) // check window
|
|
442
|
+
isInDom(element) // check if in DOM
|
|
443
|
+
isSelected(value, check) // check selection
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
#### Math Operations
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
random(min, max) // random number
|
|
450
|
+
getStepPercent(value, min, max) // percent from range
|
|
451
|
+
getStepValue(percent, min, max) // value by percent
|
|
452
|
+
toNumber(value) // convert to number
|
|
453
|
+
toNumberByMax(value, max) // with limit
|
|
454
|
+
toPercent(value) // to percent
|
|
455
|
+
toPercentBy100(value) // to percent (divide by 100)
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
#### Conversions
|
|
459
|
+
|
|
460
|
+
```typescript
|
|
461
|
+
transformation(value) // universal conversion
|
|
462
|
+
toDate(value) // to Date object
|
|
463
|
+
toBind(extra, value) // merge props
|
|
464
|
+
toBinds(list) // merge props list
|
|
465
|
+
secondToTime(seconds) // seconds to time format
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
#### Execution Utilities
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
executeFunction(callback) // execute function or return value
|
|
472
|
+
executePromise(callback) // async execution
|
|
473
|
+
executeUse(callback, options) // caching for Vue composables
|
|
474
|
+
frame(callback, next, end) // requestAnimationFrame loop
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
#### Data Operations
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
getItemByPath(obj, path) // get by path
|
|
481
|
+
getExp(value, flags) // create RegExp with escaping
|
|
482
|
+
getRequestString(data) // object to query string
|
|
483
|
+
getLengthOfAllArray(arrays) // total length of arrays
|
|
484
|
+
getMaxLengthAllArray(arrays) // max length
|
|
485
|
+
getMinLengthAllArray(arrays) // min length
|
|
486
|
+
intersectKey(data1, data2) // key intersection
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
#### Vue Utilities
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
getRef(value) // get ref value
|
|
493
|
+
setRef(target, value) // set ref value
|
|
494
|
+
toRefItem(callback) // convert to ref
|
|
495
|
+
toComputed(callback) // create computed
|
|
496
|
+
getComputedAsync(callback) // async computed
|
|
497
|
+
getBindRef(extra, value) // reactive props merge
|
|
498
|
+
render(callback) // render with tracking
|
|
499
|
+
getBind(props, options) // get bind attributes
|
|
500
|
+
getClassName(classes) // merge classes
|
|
501
|
+
getIndexForRender(array) // indexes for render
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 📝 TypeScript Types
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
// Basic types
|
|
508
|
+
Undefined // undefined | null
|
|
509
|
+
EmptyValue // all "empty" values
|
|
510
|
+
NumberOrString // number | string
|
|
511
|
+
NumberOrStringOrBoolean // number | string | boolean
|
|
512
|
+
NumberOrStringOrDate // number | string | Date
|
|
513
|
+
NormalOrArray<T> // T | T[]
|
|
514
|
+
NormalOrPromise<T> // T | Promise<T>
|
|
515
|
+
FunctionArgs<Args, Return> // typed function
|
|
516
|
+
FunctionReturn<R> // () => R
|
|
517
|
+
ObjectOrArray<T> // Record | T[]
|
|
518
|
+
ItemList // Record<string, any>
|
|
519
|
+
ElementOrString<E> // E | string | Window
|
|
520
|
+
|
|
521
|
+
// Geo types
|
|
522
|
+
GeoItemFull // full country information
|
|
523
|
+
GeoFlagItem // flag information
|
|
524
|
+
GeoPhoneValue // phone data
|
|
525
|
+
GeoDate // date format types
|
|
526
|
+
|
|
527
|
+
// List types
|
|
528
|
+
ConversionType // conversion types
|
|
529
|
+
DataOrCallbackType<T> // data or callback
|
|
530
|
+
|
|
531
|
+
// Ref types (Vue)
|
|
532
|
+
RefOrNormal<T> // Ref<T> | T
|
|
533
|
+
RefOrNormalOrCallback<T> // Ref<T> | T | (() => T)
|
|
534
|
+
ConversionRefType<T> // ref conversion type
|
|
535
|
+
|
|
536
|
+
// Constructor types
|
|
537
|
+
ClassesItemType // class element types
|
|
538
|
+
PropsValueType // props value types
|
|
539
|
+
```
|
|
540
|
+
|
|
541
|
+
## 🎯 Usage Examples
|
|
542
|
+
|
|
543
|
+
### Caching Expensive Operations
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { Cache } from '@dxtmisha/functional'
|
|
547
|
+
|
|
548
|
+
const cache = new Cache()
|
|
549
|
+
let userId = 1
|
|
550
|
+
|
|
551
|
+
// Data is cached on first call
|
|
552
|
+
const userData = cache.get(
|
|
553
|
+
'user-data',
|
|
554
|
+
() => {
|
|
555
|
+
console.log('Loading user data...')
|
|
556
|
+
return fetchUserData(userId)
|
|
557
|
+
},
|
|
558
|
+
[userId] // dependencies for invalidation
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
// When userId changes, cache invalidates
|
|
562
|
+
userId = 2
|
|
563
|
+
const newUserData = cache.get('user-data', () => fetchUserData(userId), [userId])
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### Locale-Aware Formatting
|
|
567
|
+
|
|
568
|
+
```typescript
|
|
569
|
+
import { GeoIntl } from '@dxtmisha/functional'
|
|
570
|
+
|
|
571
|
+
const intl = new GeoIntl('en-US')
|
|
572
|
+
|
|
573
|
+
// Numbers
|
|
574
|
+
console.log(intl.number(1234567.89)) // '1,234,567.89'
|
|
575
|
+
|
|
576
|
+
// Currency
|
|
577
|
+
console.log(intl.currency(99.99, 'USD')) // '$99.99'
|
|
578
|
+
|
|
579
|
+
// Dates
|
|
580
|
+
console.log(intl.date(new Date(), 'long')) // 'October 15, 2024'
|
|
581
|
+
|
|
582
|
+
// Relative time
|
|
583
|
+
console.log(intl.relative(-2, 'day')) // '2 days ago'
|
|
584
|
+
|
|
585
|
+
// Plural forms
|
|
586
|
+
console.log(intl.plural(5, ['item', 'items'])) // '5 items'
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
### REST API with Caching
|
|
590
|
+
|
|
591
|
+
```typescript
|
|
592
|
+
import { Api } from '@dxtmisha/functional'
|
|
593
|
+
|
|
594
|
+
// Setup
|
|
595
|
+
Api.setUrl('/api/v1')
|
|
596
|
+
Api.setHeaders({
|
|
597
|
+
'Authorization': 'Bearer token',
|
|
598
|
+
'Content-Type': 'application/json'
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
// Usage
|
|
602
|
+
const api = new Api()
|
|
603
|
+
|
|
604
|
+
// GET with caching
|
|
605
|
+
const users = await api.request('/users', { cache: 3600 }) // cache for 1 hour
|
|
606
|
+
|
|
607
|
+
// POST
|
|
608
|
+
const newUser = await api.post('/users', {
|
|
609
|
+
name: 'John Doe',
|
|
610
|
+
email: 'john@example.com'
|
|
611
|
+
})
|
|
612
|
+
|
|
613
|
+
// PUT
|
|
614
|
+
await api.put('/users/123', { name: 'Jane Doe' })
|
|
615
|
+
|
|
616
|
+
// DELETE
|
|
617
|
+
await api.delete('/users/123')
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
### URL Parameters via Hash
|
|
621
|
+
|
|
622
|
+
```typescript
|
|
623
|
+
import { Hash } from '@dxtmisha/functional'
|
|
624
|
+
|
|
625
|
+
// Set parameters
|
|
626
|
+
Hash.set('page', 'products')
|
|
627
|
+
Hash.set('category', 'electronics')
|
|
628
|
+
Hash.set('sort', 'price')
|
|
629
|
+
|
|
630
|
+
// URL becomes: #page:products/category:electronics/sort:price
|
|
631
|
+
|
|
632
|
+
// Get parameters
|
|
633
|
+
const page = Hash.get('page', 'home')
|
|
634
|
+
const category = Hash.get('category')
|
|
635
|
+
|
|
636
|
+
// Watch for changes
|
|
637
|
+
Hash.addWatch('page', (newPage) => {
|
|
638
|
+
console.log(`Page changed to: ${newPage}`)
|
|
639
|
+
loadPageContent(newPage)
|
|
640
|
+
})
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
### Reactive State in Vue
|
|
644
|
+
|
|
645
|
+
```typescript
|
|
646
|
+
import { useStorageRef, useGeoIntlRef } from '@dxtmisha/functional'
|
|
647
|
+
|
|
648
|
+
export default {
|
|
649
|
+
setup() {
|
|
650
|
+
// Reactive localStorage with auto-save
|
|
651
|
+
const { value: settings, set: setSettings } = useStorageRef('app-settings', {
|
|
652
|
+
theme: 'dark',
|
|
653
|
+
notifications: true,
|
|
654
|
+
language: 'en'
|
|
655
|
+
})
|
|
656
|
+
|
|
657
|
+
// Reactive geolocation
|
|
658
|
+
const { country, language, intl } = useGeoIntlRef()
|
|
659
|
+
|
|
660
|
+
// Format with locale awareness
|
|
661
|
+
const formatPrice = (price: number) => {
|
|
662
|
+
return intl.value.currency(price, 'USD')
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const toggleTheme = () => {
|
|
666
|
+
setSettings({
|
|
667
|
+
...settings.value,
|
|
668
|
+
theme: settings.value.theme === 'dark' ? 'light' : 'dark'
|
|
669
|
+
})
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
return {
|
|
673
|
+
settings,
|
|
674
|
+
country,
|
|
675
|
+
language,
|
|
676
|
+
formatPrice,
|
|
677
|
+
toggleTheme
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
## 📁 Export Structure
|
|
684
|
+
|
|
685
|
+
```
|
|
686
|
+
@dxtmisha/functional
|
|
687
|
+
├── / # All utilities (recommended)
|
|
688
|
+
├── /flags # Flag utilities
|
|
689
|
+
└── /types/* # TypeScript types
|
|
690
|
+
```
|
|
691
|
+
|
|
692
|
+
## 🔧 Requirements
|
|
693
|
+
|
|
694
|
+
- **Node.js**: ≥18.0.0
|
|
695
|
+
- **TypeScript**: 4.0+ (optional)
|
|
696
|
+
- **Vue**: ≥3.0.0 (optional, only for composables)
|
|
697
|
+
|
|
698
|
+
## 🤝 Compatibility
|
|
699
|
+
|
|
700
|
+
| Environment | Support |
|
|
701
|
+
|-------------|---------|
|
|
702
|
+
| **Browsers** | ✅ ES2020+ (Chrome 80+, Firefox 72+, Safari 13.1+, Edge 80+) |
|
|
703
|
+
| **Node.js** | ✅ 18+ |
|
|
704
|
+
| **Vue.js** | ✅ 3+ (optional) |
|
|
705
|
+
| **TypeScript** | ✅ 4+ |
|
|
706
|
+
| **Vanilla JS** | ✅ Full support |
|
|
707
|
+
| **SSR** | ✅ With environment checks |
|
|
708
|
+
|
|
709
|
+
## 📊 Bundle Size
|
|
710
|
+
|
|
711
|
+
- **Full library**: ~120KB (minified)
|
|
712
|
+
- **With tree-shaking**: only used functions are imported
|
|
713
|
+
- **Minimal import**: ~2KB (single function)
|
|
714
|
+
- **Vue composables**: optional, only when using Vue
|
|
715
|
+
- **Dependencies**: no runtime dependencies
|
|
716
|
+
|
|
717
|
+
## 🎯 Tree-shaking
|
|
718
|
+
|
|
719
|
+
The library fully supports tree-shaking:
|
|
720
|
+
|
|
721
|
+
```typescript
|
|
722
|
+
// ❌ Bad - imports entire library
|
|
723
|
+
import * as functional from '@dxtmisha/functional'
|
|
724
|
+
|
|
725
|
+
// ✅ Good - imports only what's needed
|
|
726
|
+
import { toArray, forEach, Cache } from '@dxtmisha/functional'
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
## 🏆 Advantages
|
|
730
|
+
|
|
731
|
+
- ✅ **Full TypeScript support** — TypeScript out of the box
|
|
732
|
+
- ✅ **Zero dependencies** — no external runtime dependencies
|
|
733
|
+
- ✅ **Tree-shakeable** — optimal bundle size
|
|
734
|
+
- ✅ **SSR friendly** — safe for server-side rendering
|
|
735
|
+
- ✅ **Vue optional** — works with or without Vue
|
|
736
|
+
- ✅ **Comprehensive** — everything you need in one library
|
|
737
|
+
- ✅ **Well documented** — complete documentation
|
|
738
|
+
- ✅ **Production ready** — used in production projects
|
|
739
|
+
- ✅ **Regular updates** — active development and support
|
|
740
|
+
|
|
741
|
+
## 📖 Additional Documentation
|
|
742
|
+
|
|
743
|
+
- [GitHub Repository](https://github.com/dxtmisha/dxt-ui)
|
|
744
|
+
- [Full API Documentation](https://github.com/dxtmisha/dxt-ui/tree/main/packages/wiki/src/media/functional)
|
|
745
|
+
- [DXT UI Documentation](https://dxtmisha.github.io/dxt-ui/)
|
|
746
|
+
|
|
747
|
+
## 🐛 Report Issues
|
|
748
|
+
|
|
749
|
+
If you found a bug or want to suggest an improvement:
|
|
750
|
+
|
|
751
|
+
- [GitHub Issues](https://github.com/dxtmisha/dxt-ui/issues)
|
|
752
|
+
|
|
753
|
+
## 📄 License
|
|
754
|
+
|
|
755
|
+
MIT © [dxtmisha](https://github.com/dxtmisha)
|
|
756
|
+
|
|
757
|
+
## 🤝 Contributing
|
|
758
|
+
|
|
759
|
+
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
|
|
760
|
+
|
|
761
|
+
## ⭐ Support the Project
|
|
762
|
+
|
|
763
|
+
If this library was helpful, please star it on [GitHub](https://github.com/dxtmisha/dxt-ui)!
|
|
764
|
+
|
|
765
|
+
---
|
|
766
|
+
|
|
767
|
+
Made with ❤️ by [dxtmisha](https://github.com/dxtmisha)
|