vlite3 1.5.12 → 1.5.14
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 +20 -8
- package/components/Accordion/AccordionContent.vue.js +2 -2
- package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
- package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
- package/components/Form/AccordionView2.vue.js +1 -1
- package/components/Form/Form.vue.js +2 -2
- package/components/NavbarCommandPalette.vue.js +1 -1
- package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
- package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
- package/components/Tabes/Tabes.vue.js +2 -2
- package/docs/README.md +16 -0
- package/docs/component-index.md +313 -0
- package/docs/components/accordion.md +52 -0
- package/docs/components/alert.md +34 -0
- package/docs/components/app-shell.md +371 -0
- package/docs/components/async-select.md +264 -0
- package/docs/components/attachments-list.md +231 -0
- package/docs/components/avatar-group.md +74 -0
- package/docs/components/avatar-uploader.md +61 -0
- package/docs/components/avatar.md +28 -0
- package/docs/components/badge.md +81 -0
- package/docs/components/barcode.md +42 -0
- package/docs/components/beacon.md +29 -0
- package/docs/components/breadcrumb.md +317 -0
- package/docs/components/button-group.md +35 -0
- package/docs/components/button.md +86 -0
- package/docs/components/calendar.md +95 -0
- package/docs/components/carousel.md +122 -0
- package/docs/components/cart.md +533 -0
- package/docs/components/category-manager.md +269 -0
- package/docs/components/category-menu.md +251 -0
- package/docs/components/charts.md +1456 -0
- package/docs/components/chat.md +330 -0
- package/docs/components/checkbox.md +31 -0
- package/docs/components/chip.md +137 -0
- package/docs/components/choice-box.md +40 -0
- package/docs/components/clipboard.md +105 -0
- package/docs/components/clock.md +70 -0
- package/docs/components/color-picker.md +82 -0
- package/docs/components/command-palette.md +214 -0
- package/docs/components/comment-thread.md +171 -0
- package/docs/components/confirmation-modal.md +50 -0
- package/docs/components/custom-fields-display.md +94 -0
- package/docs/components/custom-fields.md +97 -0
- package/docs/components/data-list.md +93 -0
- package/docs/components/data-table.md +922 -0
- package/docs/components/date-picker.md +58 -0
- package/docs/components/date-range-picker.md +24 -0
- package/docs/components/date-time.md +104 -0
- package/docs/components/dropdown.md +740 -0
- package/docs/components/empty.md +100 -0
- package/docs/components/export-data.md +320 -0
- package/docs/components/file-picker.md +83 -0
- package/docs/components/file-preview.md +42 -0
- package/docs/components/file-tree.md +144 -0
- package/docs/components/footer.md +251 -0
- package/docs/components/forms.md +776 -0
- package/docs/components/gantt-chart.md +767 -0
- package/docs/components/google-login.md +67 -0
- package/docs/components/google-map.md +128 -0
- package/docs/components/heatmap.md +80 -0
- package/docs/components/icon-picker.md +58 -0
- package/docs/components/icon.md +176 -0
- package/docs/components/image-comparison.md +51 -0
- package/docs/components/image-magnifier.md +26 -0
- package/docs/components/import-data.md +521 -0
- package/docs/components/input.md +58 -0
- package/docs/components/invoice.md +339 -0
- package/docs/components/kanban.md +302 -0
- package/docs/components/label.md +25 -0
- package/docs/components/list.md +419 -0
- package/docs/components/masonry.md +55 -0
- package/docs/components/modal.md +133 -0
- package/docs/components/multi-select.md +54 -0
- package/docs/components/navbar.md +403 -0
- package/docs/components/number-input.md +41 -0
- package/docs/components/otp-input.md +68 -0
- package/docs/components/pagination.md +83 -0
- package/docs/components/pan-zoom-viewport.md +245 -0
- package/docs/components/permission-editor.md +322 -0
- package/docs/components/persona.md +56 -0
- package/docs/components/price.md +106 -0
- package/docs/components/pricing-plan.md +68 -0
- package/docs/components/progress-bar.md +53 -0
- package/docs/components/qr-code.md +59 -0
- package/docs/components/rating.md +59 -0
- package/docs/components/rich-text-editor.md +210 -0
- package/docs/components/scale-generator.md +101 -0
- package/docs/components/screen.md +208 -0
- package/docs/components/seo-provider.md +189 -0
- package/docs/components/side-panel.md +94 -0
- package/docs/components/sidebar-menu.md +422 -0
- package/docs/components/skeleton.md +115 -0
- package/docs/components/slider.md +48 -0
- package/docs/components/spinner.md +27 -0
- package/docs/components/splitter.md +97 -0
- package/docs/components/stats.md +234 -0
- package/docs/components/status-chip.md +232 -0
- package/docs/components/switch.md +23 -0
- package/docs/components/tabs.md +335 -0
- package/docs/components/tag-input.md +55 -0
- package/docs/components/textarea.md +31 -0
- package/docs/components/theme-provider.md +130 -0
- package/docs/components/theme-toggle.md +36 -0
- package/docs/components/thumbnail-selector.md +186 -0
- package/docs/components/timeline.md +225 -0
- package/docs/components/toast-notification.md +89 -0
- package/docs/components/tooltip.md +31 -0
- package/docs/components/workbook.md +102 -0
- package/docs/composables/use-theme.md +59 -0
- package/docs/getting-started/setup.md +176 -0
- package/docs/guides/draggable.md +211 -0
- package/docs/guides/internationalization.md +281 -0
- package/docs/guides/performance.md +118 -0
- package/docs/guides/testing-forms.md +154 -0
- package/docs/guides/testing-overlays.md +131 -0
- package/docs/guides/theming.md +124 -0
- package/docs/utilities/search.md +580 -0
- package/docs/utilities/utilities.md +371 -0
- package/docs-manifest.json +336 -0
- package/package.json +5 -13
- package/scripts/generate-docs-manifest.js +207 -0
- package/scripts/sync-docs.js +754 -0
- package/style.css +1 -1
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
# Composables
|
|
2
|
+
|
|
3
|
+
## useCart
|
|
4
|
+
|
|
5
|
+
**Import:** `import { useCart } from 'vlite3'`
|
|
6
|
+
|
|
7
|
+
Creates reactive cart state you can pass into `<Cart />` and update from product cards,
|
|
8
|
+
headers, checkout buttons, or any other part of your page.
|
|
9
|
+
|
|
10
|
+
```vue
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { Cart, useCart } from 'vlite3'
|
|
13
|
+
|
|
14
|
+
const cart = useCart({
|
|
15
|
+
currency: 'USD',
|
|
16
|
+
items: [],
|
|
17
|
+
shipping: { mode: 'flat', cost: 5 },
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
cart.addToCart({
|
|
21
|
+
id: 1,
|
|
22
|
+
name: 'Desk Lamp',
|
|
23
|
+
price: 49,
|
|
24
|
+
quantity: 1,
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const qty = cart.getQuantity(1)
|
|
28
|
+
const snapshot = cart.getCartItems()
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<Cart
|
|
33
|
+
:data="cart.data"
|
|
34
|
+
@update:quantity="cart.updateQuantity"
|
|
35
|
+
@remove="cart.removeFromCart"
|
|
36
|
+
@clear="cart.clearCart"
|
|
37
|
+
@update:coupon="cart.setCoupon"
|
|
38
|
+
/>
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Return API
|
|
43
|
+
|
|
44
|
+
| Name | Type | Description |
|
|
45
|
+
| --- | --- | --- |
|
|
46
|
+
| `items` | `Ref<CartItem[]>` | Reactive cart line items. |
|
|
47
|
+
| `coupon` | `Ref<CartCoupon \| null>` | Reactive applied coupon. |
|
|
48
|
+
| `totals` | `ComputedRef<CartTotals>` | Computed totals from the cart calculator. |
|
|
49
|
+
| `data` | `ComputedRef<CartData>` | Ready-to-pass data object for `<Cart :data="cart.data" />`. |
|
|
50
|
+
| `itemCount` | `ComputedRef<number>` | Total quantity across all line items. |
|
|
51
|
+
| `isEmpty` | `ComputedRef<boolean>` | Whether the cart currently has no line items. |
|
|
52
|
+
| `addToCart(item, quantity?)` | `(item: CartItem, quantity?: number) => void` | Adds an item or merges quantity with an existing item that has the same `id`. |
|
|
53
|
+
| `removeFromCart(itemId, quantity?)` | `(itemId: string \| number, quantity?: number) => void` | Removes an item entirely, or subtracts a quantity when provided. |
|
|
54
|
+
| `updateQuantity(itemId, quantity)` | `(itemId: string \| number, quantity: number) => void` | Sets an exact quantity; zero or less removes the item. |
|
|
55
|
+
| `incrementQuantity(itemId, amount?)` | `(itemId: string \| number, amount?: number) => void` | Increases quantity by `amount`, defaulting to `1`. |
|
|
56
|
+
| `decrementQuantity(itemId, amount?)` | `(itemId: string \| number, amount?: number) => void` | Decreases quantity by `amount`, defaulting to `1`. |
|
|
57
|
+
| `setItems(nextItems)` | `(nextItems: CartItem[]) => void` | Replaces the cart item list. |
|
|
58
|
+
| `clearCart()` | `() => void` | Removes all items. |
|
|
59
|
+
| `setCoupon(nextCoupon)` | `(nextCoupon: CartCoupon \| null) => void` | Sets or clears the applied coupon. |
|
|
60
|
+
| `getQuantity(itemId)` | `(itemId: string \| number) => number` | Returns the current quantity for an item, or `0` when absent. |
|
|
61
|
+
| `getCartItems()` | `() => CartItem[]` | Returns a shallow-copied snapshot of the current items. |
|
|
62
|
+
|
|
63
|
+
## useKeyStroke
|
|
64
|
+
|
|
65
|
+
**Import:** `import { useKeyStroke, useAdvancedKeyStroke } from 'vlite3'`
|
|
66
|
+
|
|
67
|
+
### Single key listener
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const { onKeyStroke, offKeyStroke, destroy } = useKeyStroke()
|
|
71
|
+
|
|
72
|
+
onKeyStroke('Escape', (e) => closeModal())
|
|
73
|
+
onKeyStroke(['ArrowUp', 'ArrowDown'], (e) => navigate(e), { preventDefault: true })
|
|
74
|
+
offKeyStroke('Escape')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Combo key listener (Ctrl+S, Cmd+K)
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const { onKeyStroke, offKeyStroke, destroy } = useAdvancedKeyStroke()
|
|
81
|
+
|
|
82
|
+
onKeyStroke('ctrl+s', (e) => {
|
|
83
|
+
e.preventDefault()
|
|
84
|
+
save()
|
|
85
|
+
})
|
|
86
|
+
onKeyStroke('cmd+k', (e) => openSearch()) // Auto-maps cmd↔ctrl cross-platform
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
# Utility Functions
|
|
92
|
+
|
|
93
|
+
**Import:** `import { debounce, throttle, deepMerge, getUniqueId, downloadFile, isAppleDevice, isEmpty, removeExtraProperties, flattenArray, capitalize, camelCase, slugify, randomNumber, truncate, formatCurrency, delay, copyToClipboard } from 'vlite3'`
|
|
94
|
+
|
|
95
|
+
### `debounce(fn, delay)`
|
|
96
|
+
|
|
97
|
+
Creates a debounced function that delays invocation until `delay` ms after the last call.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const debouncedSearch = debounce((query) => fetchResults(query), 300)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `throttle(fn, delay)`
|
|
104
|
+
|
|
105
|
+
Creates a throttled function that only invokes the provided function at most once per every `delay` ms.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
const throttledSearch = throttle((query) => fetchResults(query), 300)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### `deepMerge(target, source)`
|
|
112
|
+
|
|
113
|
+
Deep merges two objects. Source overwrites target. Arrays are replaced, not concatenated.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const merged = deepMerge(defaults, userConfig)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### `getUniqueId()`
|
|
120
|
+
|
|
121
|
+
Generates a unique 24-character hex string (similar to MongoDB ObjectId).
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const id = getUniqueId() // e.g. '65a1b2c3d4e5f6a7b8c9d0e1'
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### `isAppleDevice()`
|
|
128
|
+
|
|
129
|
+
Returns `true` if the current device is an Apple device (Mac, iPhone, or Safari browser).
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
if (isAppleDevice()) {
|
|
133
|
+
/* Apple-specific logic */
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### `downloadFile(fileUrl, fileName)`
|
|
138
|
+
|
|
139
|
+
Downloads a file from a URL by fetching it as a blob and triggering a browser download.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
downloadFile('https://example.com/file.pdf', 'My File')
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### `isEmpty(value)`
|
|
146
|
+
|
|
147
|
+
Returns `true` if the value is null, undefined, empty string, 0, empty array, or object with all empty values.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
isEmpty(null) // true
|
|
151
|
+
isEmpty([]) // true
|
|
152
|
+
isEmpty({ a: '' }) // true
|
|
153
|
+
isEmpty('hello') // false
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### `removeExtraProperties(data, propertiesToRemove)`
|
|
157
|
+
|
|
158
|
+
Recursively removes specified keys from an object or array of objects.
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
removeExtraProperties({ x: 1, y: 2, z: 3 }, ['x', 'y']) // { z: 3 }
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### `flattenArray(arr)`
|
|
165
|
+
|
|
166
|
+
Recursively flattens a nested array, including values from nested objects.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
flattenArray([1, [2, [3]], 4]) // [1, 2, 3, 4]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### `capitalize(str)`
|
|
173
|
+
|
|
174
|
+
Capitalizes the first letter and any letter following `.`, `!`, or `?`.
|
|
175
|
+
|
|
176
|
+
```ts
|
|
177
|
+
capitalize('hello world') // 'Hello world'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### `camelCase(str)`
|
|
181
|
+
|
|
182
|
+
Lowercases the first character of a string.
|
|
183
|
+
|
|
184
|
+
```ts
|
|
185
|
+
camelCase('HelloWorld') // 'helloWorld'
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### `slugify(input)`
|
|
189
|
+
|
|
190
|
+
Converts a string into a URL-friendly slug. Handles Unicode via NFD normalization, strips diacritics, collapses whitespace/special characters into hyphens.
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
slugify('Hello World!') // 'hello-world'
|
|
194
|
+
slugify('Crème Brûlée') // 'creme-brulee'
|
|
195
|
+
slugify(' --foo bar-- ') // 'foo-bar'
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### `randomNumber(min, max)`
|
|
199
|
+
|
|
200
|
+
Generates a random integer between `min` and `max` (inclusive). Throws `TypeError` for non-finite values, `RangeError` if `min > max`.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
randomNumber(1, 10) // e.g. 7
|
|
204
|
+
randomNumber(-5, 5) // e.g. -2
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### `truncate(text, length, ellipsis?)`
|
|
208
|
+
|
|
209
|
+
Truncates text to a given length, breaking at the last word boundary. Default ellipsis is `'…'`.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
truncate('Hello, beautiful world!', 13) // 'Hello,…'
|
|
213
|
+
truncate('Hello, beautiful world!', 13, '...') // 'Hello,...'
|
|
214
|
+
truncate('Short', 100) // 'Short'
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### `formatCurrency(amount, locale?, currency?)`
|
|
218
|
+
|
|
219
|
+
Formats a number as a locale-aware currency string using `Intl.NumberFormat`. Defaults to `'en-US'` locale and `'USD'` currency.
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
formatCurrency(1234.5) // '$1,234.50'
|
|
223
|
+
formatCurrency(1234.5, 'de-DE', 'EUR') // '1.234,50 €'
|
|
224
|
+
formatCurrency(0) // '$0.00'
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### `delay(ms)`
|
|
228
|
+
|
|
229
|
+
Returns a Promise that resolves after the specified milliseconds. Rejects with `RangeError` if `ms` is negative or non-finite.
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
await delay(1000) // waits 1 second
|
|
233
|
+
|
|
234
|
+
// Polling example
|
|
235
|
+
while (polling) {
|
|
236
|
+
const data = await fetchData()
|
|
237
|
+
await delay(5000)
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### `copyToClipboard(text)`
|
|
242
|
+
|
|
243
|
+
Copies text to the system clipboard. Uses the modern `navigator.clipboard` API with a `document.execCommand('copy')` fallback. Returns a Promise resolving to `true` on success.
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
const ok = await copyToClipboard('Hello!')
|
|
247
|
+
if (ok) showToast('Copied!')
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## `getDefaultDateRange`
|
|
251
|
+
|
|
252
|
+
This utility provides standardized date ranges for dashboards, reports, and date pickers. It uses Day.js for immutability and timezone safety.
|
|
253
|
+
|
|
254
|
+
### 2. Function Signature
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
/**
|
|
258
|
+
* @param mode - The range type: 'week' | 'month' | '3-months' | '6-months' | 'year' | 'last-week' | 'last-month'
|
|
259
|
+
* @param maxDate - (Optional) Caps the end date (e.g., set to dayjs() to prevent future dates)
|
|
260
|
+
* @param anchorDate - (Optional) The reference date for calculation (defaults to today)
|
|
261
|
+
*/
|
|
262
|
+
const range = getDefaultDateRange(mode, maxDate, anchorDate)
|
|
263
|
+
// Result
|
|
264
|
+
export interface DateRangeResult {
|
|
265
|
+
startDate: string
|
|
266
|
+
endDate: string
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### 3. Logic & Behaviors
|
|
271
|
+
|
|
272
|
+
#### **A. The 7-Day "Smart Lookback"**
|
|
273
|
+
|
|
274
|
+
For **Calendar Modes** (`week`, `month`, `3-months`, `6-months`, `year`), if the current date is between the **1st and 7th** of the month, the utility automatically shifts the entire range back by one month.
|
|
275
|
+
|
|
276
|
+
- **Why?** This prevents dashboards from appearing "empty" at the start of a new month before data has been collected.
|
|
277
|
+
|
|
278
|
+
#### **B. Rolling vs. Calendar Windows**
|
|
279
|
+
|
|
280
|
+
The utility distinguishes between "Current Period" and "Last X Period":
|
|
281
|
+
|
|
282
|
+
| Mode | Type | Logic | Example (if today is March 24) |
|
|
283
|
+
| :--------------- | :------- | :--------------------------- | :----------------------------- |
|
|
284
|
+
| **`month`** | Calendar | Full current month | March 1 — March 31 |
|
|
285
|
+
| **`week`** | Calendar | Full current week | March 22 — March 28 |
|
|
286
|
+
| **`last-month`** | Rolling | Last 30 days including today | Feb 23 — March 24 |
|
|
287
|
+
| **`last-week`** | Rolling | Last 7 days including today | March 18 — March 24 |
|
|
288
|
+
| **`year`** | Rolling | Last 12 full months | April 1 (Prev Year) — March 31 |
|
|
289
|
+
|
|
290
|
+
## Date Formatting & ISO Utilities
|
|
291
|
+
|
|
292
|
+
**Import:** `import { formatDate, formatAmPm, formatSchedule, toISO, toLocalISO, getToday, getYesterday, getTomorrow, getUpcoming, getNextMonth, getPrevMonth, getYear, getNextYear, getPrevYear, isValidTimeRange, parseDateTime } from 'vlite3'`
|
|
293
|
+
|
|
294
|
+
### `formatAmPm(time)`
|
|
295
|
+
|
|
296
|
+
Converts a 24-hour time string into a 12-hour format with AM/PM.
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
formatAmPm('13:00') // '01:00 PM'
|
|
300
|
+
formatAmPm('09:30') // '09:30 AM'
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### `formatSchedule(date, startTime, endTime)`
|
|
304
|
+
|
|
305
|
+
Formats a date with an associated start and end time into a compact string. Uses the globally configured date format from `configState` (defaults to 'MMM DD, YYYY').
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
formatSchedule('2026-03-29', '12:00', '13:00')
|
|
309
|
+
// 'Mar 29, 2026 • 12:00 - 01:00 PM'
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### `formatDate(value, format?, type?)`
|
|
313
|
+
|
|
314
|
+
Formats a given date or time. It automatically detects time-only strings (e.g. `'13:00'`) and parses them with AM/PM. For dates, it falls back to the global date format from `configState` unless an explicit format or `type='dateTime'` is provided.
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
formatDate('13:00') // '01:00 PM'
|
|
318
|
+
formatDate('2026-03-30') // '03/30/2026' (uses global config format)
|
|
319
|
+
formatDate('2026-03-30', undefined, 'dateTime') // '03/30/2026 12:00 AM'
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### ISO String Helpers
|
|
323
|
+
|
|
324
|
+
Functions designed for returning dates in standard string formats (perfect for API requests or persistent state).
|
|
325
|
+
|
|
326
|
+
- **`toISO(date?)`**: Converts an optional date to a standard ISO string.
|
|
327
|
+
- **`toLocalISO(date?)`**: Converts an optional date to an ISO string formatted in the local timezone (e.g., `YYYY-MM-DDTHH:mm:ss.SSSZ`).
|
|
328
|
+
|
|
329
|
+
```ts
|
|
330
|
+
toISO() // '2026-03-30T00:50:00.000Z'
|
|
331
|
+
toLocalISO('2026-03-30') // '2026-03-30T00:00:00.000+05:00'
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Relative ISO Date Generators
|
|
335
|
+
|
|
336
|
+
A suite of utility functions that automatically calculate relative dates from the current time and return them as ISO strings.
|
|
337
|
+
|
|
338
|
+
- **`getToday()`**: Returns current time as ISO string.
|
|
339
|
+
- **`getYesterday()`**: Returns exactly 1 day ago.
|
|
340
|
+
- **`getTomorrow()`**: Returns exactly 1 day from now.
|
|
341
|
+
- **`getUpcoming(days = 7)`**: Returns exactly `days` into the future.
|
|
342
|
+
- **`getNextMonth()`**: Returns exactly 1 month from now.
|
|
343
|
+
- **`getPrevMonth()`**: Returns exactly 1 month ago.
|
|
344
|
+
- **`getYear()`**: Returns current date as ISO string.
|
|
345
|
+
- **`getNextYear()`**: Returns exactly 1 year from now.
|
|
346
|
+
- **`getPrevYear()`**: Returns exactly 1 year ago.
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
getToday() // e.g. '2026-03-30T00:50:00.000Z'
|
|
350
|
+
getYesterday() // e.g. '2026-03-29T00:50:00.000Z'
|
|
351
|
+
getUpcoming(14) // e.g. '2026-04-13T00:50:00.000Z'
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Time Range Validations
|
|
355
|
+
|
|
356
|
+
These utilities safely validate timelines. Crucially, they automatically parse standard date strings AND pure time strings (e.g., `'13:00'`) safely under the hood.
|
|
357
|
+
|
|
358
|
+
- **`isValidTimeRange(start, end, allowSame?)`**: Validates an end boundary constraint. By default, pure date strings can perfectly overlap (`end >= start`), but pure time strings structurally require strictly greater times (`end > start`). This auto-behavior can be overridden with `allowSame`.
|
|
359
|
+
- **`parseDateTime(val)`**: A powerful helper exported to safely parse Date objects, ISO strings, or simple `"HH:mm"` time strings reliably into Dayjs objects.
|
|
360
|
+
|
|
361
|
+
```ts
|
|
362
|
+
// Auto-detects Time (strictly after)
|
|
363
|
+
isValidTimeRange('12:00', '13:00') // true
|
|
364
|
+
isValidTimeRange('13:00', '13:00') // false (times cannot be same)
|
|
365
|
+
|
|
366
|
+
// Auto-detects Date (can be same)
|
|
367
|
+
isValidTimeRange('2026-03-30', '2026-03-30') // true
|
|
368
|
+
isValidTimeRange('2026-03-31', '2026-03-30') // false
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
|