typetify 2.4.0 → 4.0.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/CHANGELOG.md +41 -0
- package/README.md +121 -1
- package/dist/chunk-C5X2N4X4.js +2 -0
- package/dist/chunk-CX7GJR55.js +1 -0
- package/dist/chunk-H7MLD632.mjs +2 -0
- package/dist/chunk-MCQFAXUX.mjs +1 -0
- package/dist/chunk-RCSO5S56.js +2 -0
- package/dist/chunk-U6XM3X5N.mjs +2 -0
- package/dist/chunk-X6JSYVIW.mjs +1 -0
- package/dist/chunk-XKTDG6LH.js +1 -0
- package/dist/datetime/index.d.mts +320 -0
- package/dist/datetime/index.d.ts +320 -0
- package/dist/datetime/index.js +1 -0
- package/dist/datetime/index.mjs +1 -0
- package/dist/encrypt/index.d.mts +208 -0
- package/dist/encrypt/index.d.ts +208 -0
- package/dist/encrypt/index.js +1 -0
- package/dist/encrypt/index.mjs +1 -0
- package/dist/http/index.d.mts +301 -0
- package/dist/http/index.d.ts +301 -0
- package/dist/http/index.js +1 -0
- package/dist/http/index.mjs +1 -0
- package/dist/index.d.mts +113 -7
- package/dist/index.d.ts +113 -7
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/path/index.d.mts +178 -0
- package/dist/path/index.d.ts +178 -0
- package/dist/path/index.js +1 -0
- package/dist/path/index.mjs +1 -0
- package/package.json +21 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,47 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [3.0.0] - 2026-02-07
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **HTTP Module** (Backend Focus): 18 functions for type-safe HTTP requests
|
|
12
|
+
- `request`, `get`, `post`, `put`, `patch`, `del` - HTTP methods with typed responses
|
|
13
|
+
- `buildUrl` - URL construction with query parameters
|
|
14
|
+
- `createHttpClient` - Configurable HTTP client with interceptors
|
|
15
|
+
- `requestWithRetry`, `withRetry` - Automatic retry with exponential backoff
|
|
16
|
+
- `HttpHeaders`, `ContentTypes` - Common HTTP constants
|
|
17
|
+
- `parseAuthHeader`, `bearerAuth`, `basicAuth` - Authentication helpers
|
|
18
|
+
- `parseCookieHeader`, `buildCookieHeader`, `mergeHeaders` - Header utilities
|
|
19
|
+
|
|
20
|
+
- **DateTime Module** (Backend Focus): 26 functions for date manipulation
|
|
21
|
+
- `toDate`, `formatDate`, `toISODateString`, `toISOString` - Date formatting
|
|
22
|
+
- `toUnixTimestamp`, `fromUnixTimestamp` - Unix timestamp conversion
|
|
23
|
+
- `addTime`, `subtractTime`, `startOf`, `endOf`, `diff` - Date manipulation
|
|
24
|
+
- `isBefore`, `isAfter`, `isSameDate`, `isSameDay`, `isBetween` - Date comparison
|
|
25
|
+
- `isToday`, `isYesterday`, `isTomorrow`, `isPast`, `isFuture` - Relative checks
|
|
26
|
+
- `isLeapYear`, `isWeekend`, `isWeekday` - Date utilities
|
|
27
|
+
- `timeAgo`, `formatDuration`, `parseDuration` - Human-readable durations
|
|
28
|
+
|
|
29
|
+
- **Path Module** (Backend Focus): 14 functions for path manipulation
|
|
30
|
+
- `parsePath`, `dirname`, `basename`, `extname` - Path parsing
|
|
31
|
+
- `joinPath`, `resolvePath`, `relativePath` - Path joining
|
|
32
|
+
- `normalizePath`, `isAbsolute`, `toPosix`, `toWindows` - Path normalization
|
|
33
|
+
- `removeTrailingSlash`, `ensureTrailingSlash`, `commonPath` - Path utilities
|
|
34
|
+
|
|
35
|
+
- **Crypto Module** (Backend Focus): 20 functions for cryptography
|
|
36
|
+
- `hash`, `sha256`, `sha512`, `hmac` - Hashing functions
|
|
37
|
+
- `timingSafeEqual` - Timing-safe string comparison
|
|
38
|
+
- `uuid`, `randomBytes`, `randomString`, `randomInt` - Random generation
|
|
39
|
+
- `generateToken`, `urlSafeToken` - Token generation
|
|
40
|
+
- `base64Encode`, `base64Decode`, `base64UrlEncode`, `base64UrlDecode` - Base64 encoding
|
|
41
|
+
- `stringToHex`, `hexToString`, `bytesToHex`, `hexToBytes` - Hex encoding
|
|
42
|
+
- `utf8Encode`, `utf8Decode` - UTF-8 encoding
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
- Added HTTP, DateTime, Path, and Crypto modules to namespace `_`
|
|
46
|
+
- Updated documentation with all new backend-focused utilities
|
|
47
|
+
- **BREAKING**: Major version bump to 3.0.0
|
|
48
|
+
|
|
8
49
|
## [2.4.0] - 2026-02-07
|
|
9
50
|
|
|
10
51
|
### Added
|
package/README.md
CHANGED
|
@@ -61,8 +61,9 @@ Boring, predictable API. No config, no setup, just functions that work.
|
|
|
61
61
|
| Type narrowing | ❌ | ❌ | ✅ |
|
|
62
62
|
| Zero dependencies | ❌ | ✅ | ✅ |
|
|
63
63
|
| Tree-shakable | ⚠️ | ✅ | ✅ |
|
|
64
|
-
| Bundle size | 72KB | 51KB | **~15KB** |
|
|
65
64
|
| Modern syntax | ❌ | ⚠️ | ✅ |
|
|
65
|
+
| Frontend utilities | ❌ | ❌ | ✅ |
|
|
66
|
+
| Backend utilities | ❌ | ❌ | ✅ |
|
|
66
67
|
|
|
67
68
|
## Installation
|
|
68
69
|
|
|
@@ -404,6 +405,125 @@ type MergedConfig = Merge<DefaultConfig, UserConfig>
|
|
|
404
405
|
|
|
405
406
|
## Real-World Examples
|
|
406
407
|
|
|
408
|
+
### 🎨 Frontend Focus
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
import {
|
|
412
|
+
// DOM
|
|
413
|
+
querySelector, classNames, addEventListener, isInViewport,
|
|
414
|
+
// Storage
|
|
415
|
+
localStorageTyped, withExpiry, getCookie,
|
|
416
|
+
// Color
|
|
417
|
+
lighten, darken, getContrastColor, opacity
|
|
418
|
+
} from 'typetify'
|
|
419
|
+
|
|
420
|
+
// Type-safe DOM manipulation
|
|
421
|
+
const button = querySelector<HTMLButtonElement>('#submit')
|
|
422
|
+
if (button) {
|
|
423
|
+
button.className = classNames('btn', { 'btn-primary': isPrimary, 'btn-disabled': disabled })
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// Event handling with automatic cleanup
|
|
427
|
+
const cleanup = addEventListener(button, 'click', () => {
|
|
428
|
+
console.log('Clicked!')
|
|
429
|
+
})
|
|
430
|
+
// Later: cleanup()
|
|
431
|
+
|
|
432
|
+
// Lazy loading with viewport detection
|
|
433
|
+
const images = querySelectorAll<HTMLImageElement>('img[data-src]')
|
|
434
|
+
images.forEach(img => {
|
|
435
|
+
if (isInViewport(img)) {
|
|
436
|
+
img.src = img.dataset.src!
|
|
437
|
+
}
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
// Type-safe localStorage
|
|
441
|
+
interface UserPrefs {
|
|
442
|
+
theme: 'light' | 'dark'
|
|
443
|
+
language: string
|
|
444
|
+
}
|
|
445
|
+
const prefs = localStorageTyped<UserPrefs>('user-prefs')
|
|
446
|
+
prefs.set({ theme: 'dark', language: 'en' })
|
|
447
|
+
const theme = prefs.get()?.theme // 'dark' | 'light' | undefined
|
|
448
|
+
|
|
449
|
+
// Storage with expiration
|
|
450
|
+
const cache = withExpiry<ApiResponse>('api-cache', {
|
|
451
|
+
storage: sessionStorage,
|
|
452
|
+
ttl: 5 * 60 * 1000 // 5 minutes
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
// Dynamic theming with color utilities
|
|
456
|
+
const primaryColor = '#3b82f6'
|
|
457
|
+
const hoverColor = lighten(primaryColor, 10)
|
|
458
|
+
const activeColor = darken(primaryColor, 10)
|
|
459
|
+
const textColor = getContrastColor(primaryColor) // '#ffffff' or '#000000'
|
|
460
|
+
const overlay = opacity('#000000', 0.5) // 'rgba(0, 0, 0, 0.5)'
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### 🔧 Backend Focus
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
import {
|
|
467
|
+
// HTTP
|
|
468
|
+
createHttpClient, requestWithRetry, bearerAuth, buildUrl,
|
|
469
|
+
// DateTime
|
|
470
|
+
formatDate, addTime, timeAgo, isBetween, parseDuration,
|
|
471
|
+
// Path
|
|
472
|
+
joinPath, parsePath, normalizePath, relativePath,
|
|
473
|
+
// Crypto
|
|
474
|
+
sha256, hmac, uuid, generateToken, base64Encode
|
|
475
|
+
} from 'typetify'
|
|
476
|
+
|
|
477
|
+
// Type-safe HTTP client with interceptors
|
|
478
|
+
const api = createHttpClient({
|
|
479
|
+
baseUrl: 'https://api.example.com',
|
|
480
|
+
timeout: 5000,
|
|
481
|
+
headers: { Authorization: bearerAuth(token) },
|
|
482
|
+
interceptors: {
|
|
483
|
+
request: (opts) => {
|
|
484
|
+
opts.headers = { ...opts.headers, 'X-Request-Id': uuid() }
|
|
485
|
+
return opts
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
})
|
|
489
|
+
|
|
490
|
+
const users = await api.get<User[]>('/users')
|
|
491
|
+
const user = await api.post<User>('/users', { body: { name: 'John' } })
|
|
492
|
+
|
|
493
|
+
// Retry with exponential backoff
|
|
494
|
+
const data = await requestWithRetry<Data>('/api/data', {
|
|
495
|
+
maxRetries: 3,
|
|
496
|
+
delay: 1000,
|
|
497
|
+
backoff: 'exponential'
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
// Date manipulation
|
|
501
|
+
const now = new Date()
|
|
502
|
+
const nextWeek = addTime(now, 7, 'days')
|
|
503
|
+
const formatted = formatDate(now, 'YYYY-MM-DD HH:mm')
|
|
504
|
+
console.log(timeAgo(lastLogin)) // '2 hours ago'
|
|
505
|
+
|
|
506
|
+
// Check booking availability
|
|
507
|
+
if (isBetween(requestedDate, bookingStart, bookingEnd)) {
|
|
508
|
+
allowBooking()
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// Parse duration strings
|
|
512
|
+
const ttl = parseDuration('2h 30m') // 9000000 (ms)
|
|
513
|
+
|
|
514
|
+
// Cross-platform path handling
|
|
515
|
+
const configPath = joinPath('/etc', 'app', 'config.json')
|
|
516
|
+
const { name, ext } = parsePath('/var/log/app.log') // { name: 'app', ext: '.log' }
|
|
517
|
+
const normalized = normalizePath('/home/user/../admin/./file.txt') // '/home/admin/file.txt'
|
|
518
|
+
|
|
519
|
+
// Cryptographic utilities
|
|
520
|
+
const hashedPassword = await sha256(password + salt)
|
|
521
|
+
const signature = await hmac(payload, webhookSecret)
|
|
522
|
+
const sessionId = uuid()
|
|
523
|
+
const apiKey = generateToken(32)
|
|
524
|
+
const encoded = base64Encode(JSON.stringify(data))
|
|
525
|
+
```
|
|
526
|
+
|
|
407
527
|
### API Response Validation
|
|
408
528
|
|
|
409
529
|
```typescript
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunkWOT6VMZA_js=require('./chunk-WOT6VMZA.js');var j={};chunkWOT6VMZA_js.a(j,{basename:()=>p,commonPath:()=>w,dirname:()=>f,ensureTrailingSlash:()=>v,extname:()=>d,isAbsolute:()=>W,joinPath:()=>h,normalizePath:()=>x,parsePath:()=>g,relativePath:()=>P,removeTrailingSlash:()=>b,resolvePath:()=>m,toPosix:()=>z,toWindows:()=>A});function g(t){let a=t.includes("\\")||/^[A-Za-z]:/.test(t),e=a?"\\":"/",s=t.replace(/\\/g,e).replace(/\//g,e),o="";a&&/^[A-Za-z]:/.test(s)?o=s.slice(0,3):s.startsWith(e)&&(o=e);let r=s.lastIndexOf(e),n=r===-1?s:s.slice(r+1),i=r===-1?"":s.slice(0,r)||o,l=n.lastIndexOf("."),u=l>0?n.slice(l):"",c=l>0?n.slice(0,l):n;return {root:o,dir:i,base:n,ext:u,name:c}}function f(t){return g(t).dir||"."}function p(t,a){let e=g(t);return a&&e.base.endsWith(a)?e.base.slice(0,-a.length):e.base}function d(t){return g(t).ext}function h(...t){if(t.length===0)return ".";let e=t.some(l=>l.includes("\\")||/^[A-Za-z]:/.test(l))?"\\":"/",s=[];for(let l of t){if(!l)continue;let c=l.replace(/[\\/]+/g,e).split(e).filter(Boolean);s.push(...c);}let o=t[0]??"",r=o.startsWith("/")||o.startsWith("\\"),n=/^[A-Za-z]:/.test(o),i=s.join(e);return n?i=o.slice(0,2)+e+i.slice(i.indexOf(e)+1||i.length):r&&(i=e+i),i||"."}function m(...t){let e=t.some(n=>n.includes("\\")||/^[A-Za-z]:/.test(n))?"\\":"/",s=[],o=false;for(let n of t){if(!n)continue;let i=n.replace(/[\\/]+/g,e),l=i.split(e);(i.startsWith(e)||/^[A-Za-z]:/.test(i))&&(s.length=0,o=true);for(let c of l)c===""||c==="."||(c===".."?s.pop():s.push(c));}let r=s.join(e);return o?e+r:r||"."}function P(t,a){let e=t.includes("\\")||a.includes("\\")?"\\":"/",s=t.replace(/[\\/]+/g,e).split(e).filter(Boolean),o=a.replace(/[\\/]+/g,e).split(e).filter(Boolean),r=0,n=Math.min(s.length,o.length);for(let c=0;c<n&&s[c]===o[c];c++)r++;let i=s.length-r,l=o.slice(r);return [...Array(i).fill(".."),...l].join(e)||"."}function x(t){if(!t)return ".";let a=t.includes("\\")||/^[A-Za-z]:/.test(t),e=a?"\\":"/",s=t.replace(/[\\/]+/g,e),o=s.startsWith(e)||/^[A-Za-z]:/.test(s),r=s.split(e),n=[];for(let l of r)l===""||l==="."||(l===".."?n.length>0&&n[n.length-1]!==".."?n.pop():o||n.push(".."):n.push(l));let i=n.join(e);return o&&(a&&/^[A-Za-z]:/.test(t)?i=t.slice(0,2)+e+i:i=e+i),i||"."}function W(t){return t.startsWith("/")||t.startsWith("\\")||/^[A-Za-z]:/.test(t)}function z(t){return t.replace(/\\/g,"/")}function A(t){return t.replace(/\//g,"\\")}function b(t){return t==="/"||t==="\\"?t:t.replace(/[\\/]+$/,"")}function v(t){let a=t.includes("\\")?"\\":"/";return t.endsWith("/")||t.endsWith("\\")?t:t+a}function w(t){if(t.length===0)return "";if(t.length===1)return t[0];let a=t[0].includes("\\")?"\\":"/",e=t.map(r=>r.replace(/[\\/]+/g,a).split(a)),s=Math.min(...e.map(r=>r.length)),o=[];for(let r=0;r<s;r++){let n=e[0][r];if(e.every(i=>i[r]===n))o.push(n);else break}return o.join(a)||""}
|
|
2
|
+
exports.a=g;exports.b=f;exports.c=p;exports.d=d;exports.e=h;exports.f=m;exports.g=P;exports.h=x;exports.i=W;exports.j=z;exports.k=A;exports.l=b;exports.m=v;exports.n=w;exports.o=j;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkWOT6VMZA_js=require('./chunk-WOT6VMZA.js');var z={};chunkWOT6VMZA_js.a(z,{addTime:()=>h,diff:()=>Y,endOf:()=>k,formatDate:()=>d,formatDuration:()=>j,fromUnixTimestamp:()=>I,isAfter:()=>O,isBefore:()=>F,isBetween:()=>U,isFuture:()=>P,isLeapYear:()=>W,isPast:()=>B,isSameDate:()=>H,isSameDay:()=>D,isToday:()=>R,isTomorrow:()=>v,isWeekday:()=>$,isWeekend:()=>b,isYesterday:()=>A,parseDuration:()=>C,startOf:()=>S,subtractTime:()=>T,timeAgo:()=>L,toDate:()=>o,toISODateString:()=>M,toISOString:()=>x,toUnixTimestamp:()=>y});function o(t){return t instanceof Date?t:typeof t=="number"?new Date(t):new Date(t)}function d(t,n){let r=o(t),e=(m,p=2)=>String(m).padStart(p,"0"),a=r.getHours(),s=a%12||12,i=a>=12,f={YYYY:String(r.getFullYear()),YY:String(r.getFullYear()).slice(-2),MM:e(r.getMonth()+1),M:String(r.getMonth()+1),DD:e(r.getDate()),D:String(r.getDate()),HH:e(a),H:String(a),hh:e(s),h:String(s),mm:e(r.getMinutes()),m:String(r.getMinutes()),ss:e(r.getSeconds()),s:String(r.getSeconds()),SSS:e(r.getMilliseconds(),3),A:i?"PM":"AM",a:i?"pm":"am"},c=n;for(let[m,p]of Object.entries(f).sort((g,l)=>l[0].length-g[0].length))c=c.replace(new RegExp(m,"g"),p);return c}function M(t){return d(t,"YYYY-MM-DD")}function x(t){return o(t).toISOString()}function y(t){return Math.floor(o(t).getTime()/1e3)}function I(t){return new Date(t*1e3)}function w(t,n){return t*{milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6,years:31536e6}[n]}function h(t,n,r){let e=o(t);if(r==="months"){let a=new Date(e);return a.setMonth(a.getMonth()+n),a}if(r==="years"){let a=new Date(e);return a.setFullYear(a.getFullYear()+n),a}return new Date(e.getTime()+w(n,r))}function T(t,n,r){return h(t,-n,r)}function S(t,n){let r=o(t),e=new Date(r);switch(n){case "second":e.setMilliseconds(0);break;case "minute":e.setSeconds(0,0);break;case "hour":e.setMinutes(0,0,0);break;case "day":e.setHours(0,0,0,0);break;case "week":e.setHours(0,0,0,0),e.setDate(e.getDate()-e.getDay());break;case "month":e.setHours(0,0,0,0),e.setDate(1);break;case "year":e.setHours(0,0,0,0),e.setMonth(0,1);break}return e}function k(t,n){let r=o(t),e=new Date(r);switch(n){case "second":e.setMilliseconds(999);break;case "minute":e.setSeconds(59,999);break;case "hour":e.setMinutes(59,59,999);break;case "day":e.setHours(23,59,59,999);break;case "week":e.setHours(23,59,59,999),e.setDate(e.getDate()+(6-e.getDay()));break;case "month":e.setMonth(e.getMonth()+1,0),e.setHours(23,59,59,999);break;case "year":e.setMonth(11,31),e.setHours(23,59,59,999);break}return e}function Y(t,n,r){let e=o(t),a=o(n);if(r==="months")return (e.getFullYear()-a.getFullYear())*12+(e.getMonth()-a.getMonth());if(r==="years")return e.getFullYear()-a.getFullYear();let s=e.getTime()-a.getTime();return Math.floor(s/w(1,r))}function F(t,n){return o(t).getTime()<o(n).getTime()}function O(t,n){return o(t).getTime()>o(n).getTime()}function H(t,n){return o(t).getTime()===o(n).getTime()}function D(t,n){let r=o(t),e=o(n);return r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate()}function U(t,n,r){let e=o(t).getTime();return e>=o(n).getTime()&&e<=o(r).getTime()}function R(t){return D(t,new Date)}function A(t){let n=new Date;return n.setDate(n.getDate()-1),D(t,n)}function v(t){let n=new Date;return n.setDate(n.getDate()+1),D(t,n)}function B(t){return o(t).getTime()<Date.now()}function P(t){return o(t).getTime()>Date.now()}function W(t){return t%4===0&&t%100!==0||t%400===0}function b(t){let n=o(t).getDay();return n===0||n===6}function $(t){return !b(t)}function L(t,n={}){let{locale:r="en",style:e="long"}=n,a=o(t),s=Date.now(),i=a.getTime()-s,f=Math.round(i/1e3),c=Math.round(i/6e4),m=Math.round(i/36e5),p=Math.round(i/864e5),g=Math.round(i/6048e5),l=Math.round(i/2592e6),E=Math.round(i/31536e6),u=new Intl.RelativeTimeFormat(r,{style:e});return Math.abs(f)<60?u.format(f,"second"):Math.abs(c)<60?u.format(c,"minute"):Math.abs(m)<24?u.format(m,"hour"):Math.abs(p)<7?u.format(p,"day"):Math.abs(g)<4?u.format(g,"week"):Math.abs(l)<12?u.format(l,"month"):u.format(E,"year")}function j(t){let n=Math.floor(t/1e3),r=Math.floor(n/60),e=Math.floor(r/60),a=Math.floor(e/24),s=[];return a>0&&s.push(`${a}d`),e%24>0&&s.push(`${e%24}h`),r%60>0&&s.push(`${r%60}m`),(n%60>0||s.length===0)&&s.push(`${n%60}s`),s.join(" ")}function C(t){let n={ms:1,s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5},r=0,e=/(\d+)\s*(ms|s|m|h|d|w)/gi,a;for(;(a=e.exec(t))!==null;){let s=parseInt(a[1],10),i=a[2].toLowerCase();r+=s*(n[i]??0);}return r}exports.A=C;exports.B=z;exports.a=o;exports.b=d;exports.c=M;exports.d=x;exports.e=y;exports.f=I;exports.g=h;exports.h=T;exports.i=S;exports.j=k;exports.k=Y;exports.l=F;exports.m=O;exports.n=H;exports.o=D;exports.p=U;exports.q=R;exports.r=A;exports.s=v;exports.t=B;exports.u=P;exports.v=W;exports.w=b;exports.x=$;exports.y=L;exports.z=j;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a}from'./chunk-JZXLCA2E.mjs';var j={};a(j,{basename:()=>p,commonPath:()=>w,dirname:()=>f,ensureTrailingSlash:()=>v,extname:()=>d,isAbsolute:()=>W,joinPath:()=>h,normalizePath:()=>x,parsePath:()=>g,relativePath:()=>P,removeTrailingSlash:()=>b,resolvePath:()=>m,toPosix:()=>z,toWindows:()=>A});function g(t){let a=t.includes("\\")||/^[A-Za-z]:/.test(t),e=a?"\\":"/",s=t.replace(/\\/g,e).replace(/\//g,e),o="";a&&/^[A-Za-z]:/.test(s)?o=s.slice(0,3):s.startsWith(e)&&(o=e);let r=s.lastIndexOf(e),n=r===-1?s:s.slice(r+1),i=r===-1?"":s.slice(0,r)||o,l=n.lastIndexOf("."),u=l>0?n.slice(l):"",c=l>0?n.slice(0,l):n;return {root:o,dir:i,base:n,ext:u,name:c}}function f(t){return g(t).dir||"."}function p(t,a){let e=g(t);return a&&e.base.endsWith(a)?e.base.slice(0,-a.length):e.base}function d(t){return g(t).ext}function h(...t){if(t.length===0)return ".";let e=t.some(l=>l.includes("\\")||/^[A-Za-z]:/.test(l))?"\\":"/",s=[];for(let l of t){if(!l)continue;let c=l.replace(/[\\/]+/g,e).split(e).filter(Boolean);s.push(...c);}let o=t[0]??"",r=o.startsWith("/")||o.startsWith("\\"),n=/^[A-Za-z]:/.test(o),i=s.join(e);return n?i=o.slice(0,2)+e+i.slice(i.indexOf(e)+1||i.length):r&&(i=e+i),i||"."}function m(...t){let e=t.some(n=>n.includes("\\")||/^[A-Za-z]:/.test(n))?"\\":"/",s=[],o=false;for(let n of t){if(!n)continue;let i=n.replace(/[\\/]+/g,e),l=i.split(e);(i.startsWith(e)||/^[A-Za-z]:/.test(i))&&(s.length=0,o=true);for(let c of l)c===""||c==="."||(c===".."?s.pop():s.push(c));}let r=s.join(e);return o?e+r:r||"."}function P(t,a){let e=t.includes("\\")||a.includes("\\")?"\\":"/",s=t.replace(/[\\/]+/g,e).split(e).filter(Boolean),o=a.replace(/[\\/]+/g,e).split(e).filter(Boolean),r=0,n=Math.min(s.length,o.length);for(let c=0;c<n&&s[c]===o[c];c++)r++;let i=s.length-r,l=o.slice(r);return [...Array(i).fill(".."),...l].join(e)||"."}function x(t){if(!t)return ".";let a=t.includes("\\")||/^[A-Za-z]:/.test(t),e=a?"\\":"/",s=t.replace(/[\\/]+/g,e),o=s.startsWith(e)||/^[A-Za-z]:/.test(s),r=s.split(e),n=[];for(let l of r)l===""||l==="."||(l===".."?n.length>0&&n[n.length-1]!==".."?n.pop():o||n.push(".."):n.push(l));let i=n.join(e);return o&&(a&&/^[A-Za-z]:/.test(t)?i=t.slice(0,2)+e+i:i=e+i),i||"."}function W(t){return t.startsWith("/")||t.startsWith("\\")||/^[A-Za-z]:/.test(t)}function z(t){return t.replace(/\\/g,"/")}function A(t){return t.replace(/\//g,"\\")}function b(t){return t==="/"||t==="\\"?t:t.replace(/[\\/]+$/,"")}function v(t){let a=t.includes("\\")?"\\":"/";return t.endsWith("/")||t.endsWith("\\")?t:t+a}function w(t){if(t.length===0)return "";if(t.length===1)return t[0];let a=t[0].includes("\\")?"\\":"/",e=t.map(r=>r.replace(/[\\/]+/g,a).split(a)),s=Math.min(...e.map(r=>r.length)),o=[];for(let r=0;r<s;r++){let n=e[0][r];if(e.every(i=>i[r]===n))o.push(n);else break}return o.join(a)||""}
|
|
2
|
+
export{g as a,f as b,p as c,d,h as e,m as f,P as g,x as h,W as i,z as j,A as k,b as l,v as m,w as n,j as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-JZXLCA2E.mjs';var L={};a(L,{ContentTypes:()=>E,HttpError:()=>l,HttpHeaders:()=>w,basicAuth:()=>A,bearerAuth:()=>C,buildCookieHeader:()=>U,buildUrl:()=>d,createHttpClient:()=>O,del:()=>y,get:()=>f,mergeHeaders:()=>$,parseAuthHeader:()=>P,parseCookieHeader:()=>k,patch:()=>h,post:()=>g,put:()=>R,request:()=>T,requestWithRetry:()=>H,withRetry:()=>q});var l=class extends Error{constructor(r,u,a,p){super(r);this.status=u;this.statusText=a;this.response=p;this.name="HttpError";}};function d(t,e){if(!e)return t;let r=new URLSearchParams;for(let[a,p]of Object.entries(e))p!==void 0&&r.append(a,String(p));let u=r.toString();return u?t.includes("?")?`${t}&${u}`:`${t}?${u}`:t}async function T(t,e={}){let{baseUrl:r,timeout:u=3e4,params:a,body:p,...o}=e,n=d(r?`${r}${t}`:t,a),i=new AbortController,m=setTimeout(()=>i.abort(),u);try{let s=await fetch(n,{...o,signal:i.signal,headers:{"Content-Type":"application/json",...o.headers},body:p?JSON.stringify(p):null});clearTimeout(m);let c=await s.json().catch(()=>null);if(!s.ok)throw new l(`HTTP ${s.status}: ${s.statusText}`,s.status,s.statusText,c);return {data:c,status:s.status,statusText:s.statusText,headers:s.headers,ok:s.ok}}catch(s){throw clearTimeout(m),s instanceof l?s:s instanceof Error&&s.name==="AbortError"?new l("Request timeout",408,"Request Timeout"):s}}async function f(t,e){return T(t,{...e,method:"GET"})}async function g(t,e){return T(t,{...e,method:"POST"})}async function R(t,e){return T(t,{...e,method:"PUT"})}async function h(t,e){return T(t,{...e,method:"PATCH"})}async function y(t,e){return T(t,{...e,method:"DELETE"})}function O(t){let{baseUrl:e,timeout:r,headers:u,interceptors:a}=t;async function p(o,n,i={}){let m=i.timeout??r,s={...i,baseUrl:e,...m!==void 0&&{timeout:m},method:o,headers:{...u,...i.headers}};a?.request&&(s=await a.request(s));try{let c=await T(n,s);return a?.response&&(c=await a.response(c)),c}catch(c){throw a?.error&&c instanceof Error?await a.error(c):c}}return {get:(o,n)=>p("GET",o,n),post:(o,n)=>p("POST",o,n),put:(o,n)=>p("PUT",o,n),patch:(o,n)=>p("PATCH",o,n),delete:(o,n)=>p("DELETE",o,n),request:(o,n)=>p(n?.method??"GET",o,n)}}function x(t){return t instanceof l?t.status>=500&&t.status<600:t.name==="TypeError"||t.name==="AbortError"}function b(t,e,r){return r==="exponential"?e*Math.pow(2,t-1):e*t}async function H(t,e={}){let{maxRetries:r=3,delay:u=1e3,backoff:a="exponential",retryOn:p=x,...o}=e,n;for(let i=1;i<=r+1;i++)try{return await T(t,o)}catch(m){if(n=m instanceof Error?m:new Error(String(m)),i<=r&&p(n,i)){let s=b(i,u,a);await new Promise(c=>setTimeout(c,s));continue}throw n}throw n}function q(t,e={}){let{maxRetries:r=3,delay:u=1e3,backoff:a="exponential",retryOn:p=x}=e;return(async(...o)=>{let n;for(let i=1;i<=r+1;i++)try{return await t(...o)}catch(m){if(n=m instanceof Error?m:new Error(String(m)),i<=r&&p(n,i)){let s=b(i,u,a);await new Promise(c=>setTimeout(c,s));continue}throw n}throw n})}var w={ContentType:"Content-Type",Accept:"Accept",Authorization:"Authorization",CacheControl:"Cache-Control",UserAgent:"User-Agent",AcceptLanguage:"Accept-Language",ContentLength:"Content-Length",XRequestId:"X-Request-Id",XForwardedFor:"X-Forwarded-For",XRealIp:"X-Real-IP"},E={JSON:"application/json",FormData:"multipart/form-data",FormUrlEncoded:"application/x-www-form-urlencoded",Text:"text/plain",HTML:"text/html",XML:"application/xml",Binary:"application/octet-stream"};function P(t){if(!t)return null;let[e,r]=t.split(" ");return !e||!r?null:{type:e,credentials:r}}function C(t){return `Bearer ${t}`}function A(t,e){return `Basic ${btoa(`${t}:${e}`)}`}function k(t){let e={};return t&&t.split(";").forEach(r=>{let[u,...a]=r.trim().split("=");u&&(e[u]=a.join("="));}),e}function U(t){return Object.entries(t).map(([e,r])=>`${e}=${r}`).join("; ")}function $(...t){let e={};for(let r of t)r&&Object.assign(e,r);return e}export{l as a,d as b,T as c,f as d,g as e,R as f,h as g,y as h,O as i,H as j,q as k,w as l,E as m,P as n,C as o,A as p,k as q,U as r,$ as s,L as t};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var chunkWOT6VMZA_js=require('./chunk-WOT6VMZA.js');var k={};chunkWOT6VMZA_js.a(k,{base64Decode:()=>x,base64Encode:()=>A,base64UrlDecode:()=>S,base64UrlEncode:()=>b,bytesToHex:()=>U,generateToken:()=>m,hash:()=>a,hexToBytes:()=>w,hexToString:()=>T,hmac:()=>f,randomBytes:()=>i,randomInt:()=>y,randomString:()=>c,sha256:()=>g,sha512:()=>p,stringToHex:()=>H,timingSafeEqual:()=>d,urlSafeToken:()=>h,utf8Decode:()=>D,utf8Encode:()=>E,uuid:()=>l});async function a(r,t="SHA-256"){let n=new TextEncoder().encode(r),o=await crypto.subtle.digest(t,n);return Array.from(new Uint8Array(o)).map(s=>s.toString(16).padStart(2,"0")).join("")}async function g(r){return a(r,"SHA-256")}async function p(r){return a(r,"SHA-512")}async function f(r,t,e="SHA-256"){let n=new TextEncoder,o=n.encode(t),u=n.encode(r),s=await crypto.subtle.importKey("raw",o,{name:"HMAC",hash:e},false,["sign"]),B=await crypto.subtle.sign("HMAC",s,u);return Array.from(new Uint8Array(B)).map(C=>C.toString(16).padStart(2,"0")).join("")}function d(r,t){if(r.length!==t.length)return false;let e=0;for(let n=0;n<r.length;n++)e|=r.charCodeAt(n)^t.charCodeAt(n);return e===0}function l(){return crypto.randomUUID()}function i(r){let t=new Uint8Array(r);return crypto.getRandomValues(t),Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function c(r,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"){let e=new Uint8Array(r);crypto.getRandomValues(e);let n="";for(let o=0;o<r;o++)n+=t[e[o]%t.length];return n}function y(r,t){let e=t-r+1,n=new Uint32Array(1);return crypto.getRandomValues(n),r+n[0]%e}function m(r=32){return i(Math.ceil(r/2)).slice(0,r)}function h(r){return c(r,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_")}function A(r){return btoa(r)}function x(r){return atob(r)}function b(r){return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function S(r){let t=r.replace(/-/g,"+").replace(/_/g,"/"),e=t.length%4;return e&&(t+="=".repeat(4-e)),atob(t)}function H(r){return Array.from(r).map(t=>t.charCodeAt(0).toString(16).padStart(2,"0")).join("")}function T(r){let t="";for(let e=0;e<r.length;e+=2)t+=String.fromCharCode(parseInt(r.slice(e,e+2),16));return t}function U(r){return Array.from(r).map(t=>t.toString(16).padStart(2,"0")).join("")}function w(r){let t=new Uint8Array(r.length/2);for(let e=0;e<r.length;e+=2)t[e/2]=parseInt(r.slice(e,e+2),16);return t}function E(r){return new TextEncoder().encode(r)}function D(r){return new TextDecoder().decode(r)}
|
|
2
|
+
exports.a=a;exports.b=g;exports.c=p;exports.d=f;exports.e=d;exports.f=l;exports.g=i;exports.h=c;exports.i=y;exports.j=m;exports.k=h;exports.l=A;exports.m=x;exports.n=b;exports.o=S;exports.p=H;exports.q=T;exports.r=U;exports.s=w;exports.t=E;exports.u=D;exports.v=k;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a as a$1}from'./chunk-JZXLCA2E.mjs';var k={};a$1(k,{base64Decode:()=>x,base64Encode:()=>A,base64UrlDecode:()=>S,base64UrlEncode:()=>b,bytesToHex:()=>U,generateToken:()=>m,hash:()=>a,hexToBytes:()=>w,hexToString:()=>T,hmac:()=>f,randomBytes:()=>i,randomInt:()=>y,randomString:()=>c,sha256:()=>g,sha512:()=>p,stringToHex:()=>H,timingSafeEqual:()=>d,urlSafeToken:()=>h,utf8Decode:()=>D,utf8Encode:()=>E,uuid:()=>l});async function a(r,t="SHA-256"){let n=new TextEncoder().encode(r),o=await crypto.subtle.digest(t,n);return Array.from(new Uint8Array(o)).map(s=>s.toString(16).padStart(2,"0")).join("")}async function g(r){return a(r,"SHA-256")}async function p(r){return a(r,"SHA-512")}async function f(r,t,e="SHA-256"){let n=new TextEncoder,o=n.encode(t),u=n.encode(r),s=await crypto.subtle.importKey("raw",o,{name:"HMAC",hash:e},false,["sign"]),B=await crypto.subtle.sign("HMAC",s,u);return Array.from(new Uint8Array(B)).map(C=>C.toString(16).padStart(2,"0")).join("")}function d(r,t){if(r.length!==t.length)return false;let e=0;for(let n=0;n<r.length;n++)e|=r.charCodeAt(n)^t.charCodeAt(n);return e===0}function l(){return crypto.randomUUID()}function i(r){let t=new Uint8Array(r);return crypto.getRandomValues(t),Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join("")}function c(r,t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"){let e=new Uint8Array(r);crypto.getRandomValues(e);let n="";for(let o=0;o<r;o++)n+=t[e[o]%t.length];return n}function y(r,t){let e=t-r+1,n=new Uint32Array(1);return crypto.getRandomValues(n),r+n[0]%e}function m(r=32){return i(Math.ceil(r/2)).slice(0,r)}function h(r){return c(r,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_")}function A(r){return btoa(r)}function x(r){return atob(r)}function b(r){return btoa(r).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function S(r){let t=r.replace(/-/g,"+").replace(/_/g,"/"),e=t.length%4;return e&&(t+="=".repeat(4-e)),atob(t)}function H(r){return Array.from(r).map(t=>t.charCodeAt(0).toString(16).padStart(2,"0")).join("")}function T(r){let t="";for(let e=0;e<r.length;e+=2)t+=String.fromCharCode(parseInt(r.slice(e,e+2),16));return t}function U(r){return Array.from(r).map(t=>t.toString(16).padStart(2,"0")).join("")}function w(r){let t=new Uint8Array(r.length/2);for(let e=0;e<r.length;e+=2)t[e/2]=parseInt(r.slice(e,e+2),16);return t}function E(r){return new TextEncoder().encode(r)}function D(r){return new TextDecoder().decode(r)}
|
|
2
|
+
export{a,g as b,p as c,f as d,d as e,l as f,i as g,c as h,y as i,m as j,h as k,A as l,x as m,b as n,S as o,H as p,T as q,U as r,w as s,E as t,D as u,k as v};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {a}from'./chunk-JZXLCA2E.mjs';var z={};a(z,{addTime:()=>h,diff:()=>Y,endOf:()=>k,formatDate:()=>d,formatDuration:()=>j,fromUnixTimestamp:()=>I,isAfter:()=>O,isBefore:()=>F,isBetween:()=>U,isFuture:()=>P,isLeapYear:()=>W,isPast:()=>B,isSameDate:()=>H,isSameDay:()=>D,isToday:()=>R,isTomorrow:()=>v,isWeekday:()=>$,isWeekend:()=>b,isYesterday:()=>A,parseDuration:()=>C,startOf:()=>S,subtractTime:()=>T,timeAgo:()=>L,toDate:()=>o,toISODateString:()=>M,toISOString:()=>x,toUnixTimestamp:()=>y});function o(t){return t instanceof Date?t:typeof t=="number"?new Date(t):new Date(t)}function d(t,n){let r=o(t),e=(m,p=2)=>String(m).padStart(p,"0"),a=r.getHours(),s=a%12||12,i=a>=12,f={YYYY:String(r.getFullYear()),YY:String(r.getFullYear()).slice(-2),MM:e(r.getMonth()+1),M:String(r.getMonth()+1),DD:e(r.getDate()),D:String(r.getDate()),HH:e(a),H:String(a),hh:e(s),h:String(s),mm:e(r.getMinutes()),m:String(r.getMinutes()),ss:e(r.getSeconds()),s:String(r.getSeconds()),SSS:e(r.getMilliseconds(),3),A:i?"PM":"AM",a:i?"pm":"am"},c=n;for(let[m,p]of Object.entries(f).sort((g,l)=>l[0].length-g[0].length))c=c.replace(new RegExp(m,"g"),p);return c}function M(t){return d(t,"YYYY-MM-DD")}function x(t){return o(t).toISOString()}function y(t){return Math.floor(o(t).getTime()/1e3)}function I(t){return new Date(t*1e3)}function w(t,n){return t*{milliseconds:1,seconds:1e3,minutes:6e4,hours:36e5,days:864e5,weeks:6048e5,months:2592e6,years:31536e6}[n]}function h(t,n,r){let e=o(t);if(r==="months"){let a=new Date(e);return a.setMonth(a.getMonth()+n),a}if(r==="years"){let a=new Date(e);return a.setFullYear(a.getFullYear()+n),a}return new Date(e.getTime()+w(n,r))}function T(t,n,r){return h(t,-n,r)}function S(t,n){let r=o(t),e=new Date(r);switch(n){case "second":e.setMilliseconds(0);break;case "minute":e.setSeconds(0,0);break;case "hour":e.setMinutes(0,0,0);break;case "day":e.setHours(0,0,0,0);break;case "week":e.setHours(0,0,0,0),e.setDate(e.getDate()-e.getDay());break;case "month":e.setHours(0,0,0,0),e.setDate(1);break;case "year":e.setHours(0,0,0,0),e.setMonth(0,1);break}return e}function k(t,n){let r=o(t),e=new Date(r);switch(n){case "second":e.setMilliseconds(999);break;case "minute":e.setSeconds(59,999);break;case "hour":e.setMinutes(59,59,999);break;case "day":e.setHours(23,59,59,999);break;case "week":e.setHours(23,59,59,999),e.setDate(e.getDate()+(6-e.getDay()));break;case "month":e.setMonth(e.getMonth()+1,0),e.setHours(23,59,59,999);break;case "year":e.setMonth(11,31),e.setHours(23,59,59,999);break}return e}function Y(t,n,r){let e=o(t),a=o(n);if(r==="months")return (e.getFullYear()-a.getFullYear())*12+(e.getMonth()-a.getMonth());if(r==="years")return e.getFullYear()-a.getFullYear();let s=e.getTime()-a.getTime();return Math.floor(s/w(1,r))}function F(t,n){return o(t).getTime()<o(n).getTime()}function O(t,n){return o(t).getTime()>o(n).getTime()}function H(t,n){return o(t).getTime()===o(n).getTime()}function D(t,n){let r=o(t),e=o(n);return r.getFullYear()===e.getFullYear()&&r.getMonth()===e.getMonth()&&r.getDate()===e.getDate()}function U(t,n,r){let e=o(t).getTime();return e>=o(n).getTime()&&e<=o(r).getTime()}function R(t){return D(t,new Date)}function A(t){let n=new Date;return n.setDate(n.getDate()-1),D(t,n)}function v(t){let n=new Date;return n.setDate(n.getDate()+1),D(t,n)}function B(t){return o(t).getTime()<Date.now()}function P(t){return o(t).getTime()>Date.now()}function W(t){return t%4===0&&t%100!==0||t%400===0}function b(t){let n=o(t).getDay();return n===0||n===6}function $(t){return !b(t)}function L(t,n={}){let{locale:r="en",style:e="long"}=n,a=o(t),s=Date.now(),i=a.getTime()-s,f=Math.round(i/1e3),c=Math.round(i/6e4),m=Math.round(i/36e5),p=Math.round(i/864e5),g=Math.round(i/6048e5),l=Math.round(i/2592e6),E=Math.round(i/31536e6),u=new Intl.RelativeTimeFormat(r,{style:e});return Math.abs(f)<60?u.format(f,"second"):Math.abs(c)<60?u.format(c,"minute"):Math.abs(m)<24?u.format(m,"hour"):Math.abs(p)<7?u.format(p,"day"):Math.abs(g)<4?u.format(g,"week"):Math.abs(l)<12?u.format(l,"month"):u.format(E,"year")}function j(t){let n=Math.floor(t/1e3),r=Math.floor(n/60),e=Math.floor(r/60),a=Math.floor(e/24),s=[];return a>0&&s.push(`${a}d`),e%24>0&&s.push(`${e%24}h`),r%60>0&&s.push(`${r%60}m`),(n%60>0||s.length===0)&&s.push(`${n%60}s`),s.join(" ")}function C(t){let n={ms:1,s:1e3,m:6e4,h:36e5,d:864e5,w:6048e5},r=0,e=/(\d+)\s*(ms|s|m|h|d|w)/gi,a;for(;(a=e.exec(t))!==null;){let s=parseInt(a[1],10),i=a[2].toLowerCase();r+=s*(n[i]??0);}return r}export{C as A,z as B,o as a,d as b,M as c,x as d,y as e,I as f,h as g,T as h,S as i,k as j,Y as k,F as l,O as m,H as n,D as o,U as p,R as q,A as r,v as s,B as t,P as u,W as v,b as w,$ as x,L as y,j as z};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkWOT6VMZA_js=require('./chunk-WOT6VMZA.js');var L={};chunkWOT6VMZA_js.a(L,{ContentTypes:()=>E,HttpError:()=>l,HttpHeaders:()=>w,basicAuth:()=>A,bearerAuth:()=>C,buildCookieHeader:()=>U,buildUrl:()=>d,createHttpClient:()=>O,del:()=>y,get:()=>f,mergeHeaders:()=>$,parseAuthHeader:()=>P,parseCookieHeader:()=>k,patch:()=>h,post:()=>g,put:()=>R,request:()=>T,requestWithRetry:()=>H,withRetry:()=>q});var l=class extends Error{constructor(r,u,a,p){super(r);this.status=u;this.statusText=a;this.response=p;this.name="HttpError";}};function d(t,e){if(!e)return t;let r=new URLSearchParams;for(let[a,p]of Object.entries(e))p!==void 0&&r.append(a,String(p));let u=r.toString();return u?t.includes("?")?`${t}&${u}`:`${t}?${u}`:t}async function T(t,e={}){let{baseUrl:r,timeout:u=3e4,params:a,body:p,...o}=e,n=d(r?`${r}${t}`:t,a),i=new AbortController,m=setTimeout(()=>i.abort(),u);try{let s=await fetch(n,{...o,signal:i.signal,headers:{"Content-Type":"application/json",...o.headers},body:p?JSON.stringify(p):null});clearTimeout(m);let c=await s.json().catch(()=>null);if(!s.ok)throw new l(`HTTP ${s.status}: ${s.statusText}`,s.status,s.statusText,c);return {data:c,status:s.status,statusText:s.statusText,headers:s.headers,ok:s.ok}}catch(s){throw clearTimeout(m),s instanceof l?s:s instanceof Error&&s.name==="AbortError"?new l("Request timeout",408,"Request Timeout"):s}}async function f(t,e){return T(t,{...e,method:"GET"})}async function g(t,e){return T(t,{...e,method:"POST"})}async function R(t,e){return T(t,{...e,method:"PUT"})}async function h(t,e){return T(t,{...e,method:"PATCH"})}async function y(t,e){return T(t,{...e,method:"DELETE"})}function O(t){let{baseUrl:e,timeout:r,headers:u,interceptors:a}=t;async function p(o,n,i={}){let m=i.timeout??r,s={...i,baseUrl:e,...m!==void 0&&{timeout:m},method:o,headers:{...u,...i.headers}};a?.request&&(s=await a.request(s));try{let c=await T(n,s);return a?.response&&(c=await a.response(c)),c}catch(c){throw a?.error&&c instanceof Error?await a.error(c):c}}return {get:(o,n)=>p("GET",o,n),post:(o,n)=>p("POST",o,n),put:(o,n)=>p("PUT",o,n),patch:(o,n)=>p("PATCH",o,n),delete:(o,n)=>p("DELETE",o,n),request:(o,n)=>p(n?.method??"GET",o,n)}}function x(t){return t instanceof l?t.status>=500&&t.status<600:t.name==="TypeError"||t.name==="AbortError"}function b(t,e,r){return r==="exponential"?e*Math.pow(2,t-1):e*t}async function H(t,e={}){let{maxRetries:r=3,delay:u=1e3,backoff:a="exponential",retryOn:p=x,...o}=e,n;for(let i=1;i<=r+1;i++)try{return await T(t,o)}catch(m){if(n=m instanceof Error?m:new Error(String(m)),i<=r&&p(n,i)){let s=b(i,u,a);await new Promise(c=>setTimeout(c,s));continue}throw n}throw n}function q(t,e={}){let{maxRetries:r=3,delay:u=1e3,backoff:a="exponential",retryOn:p=x}=e;return(async(...o)=>{let n;for(let i=1;i<=r+1;i++)try{return await t(...o)}catch(m){if(n=m instanceof Error?m:new Error(String(m)),i<=r&&p(n,i)){let s=b(i,u,a);await new Promise(c=>setTimeout(c,s));continue}throw n}throw n})}var w={ContentType:"Content-Type",Accept:"Accept",Authorization:"Authorization",CacheControl:"Cache-Control",UserAgent:"User-Agent",AcceptLanguage:"Accept-Language",ContentLength:"Content-Length",XRequestId:"X-Request-Id",XForwardedFor:"X-Forwarded-For",XRealIp:"X-Real-IP"},E={JSON:"application/json",FormData:"multipart/form-data",FormUrlEncoded:"application/x-www-form-urlencoded",Text:"text/plain",HTML:"text/html",XML:"application/xml",Binary:"application/octet-stream"};function P(t){if(!t)return null;let[e,r]=t.split(" ");return !e||!r?null:{type:e,credentials:r}}function C(t){return `Bearer ${t}`}function A(t,e){return `Basic ${btoa(`${t}:${e}`)}`}function k(t){let e={};return t&&t.split(";").forEach(r=>{let[u,...a]=r.trim().split("=");u&&(e[u]=a.join("="));}),e}function U(t){return Object.entries(t).map(([e,r])=>`${e}=${r}`).join("; ")}function $(...t){let e={};for(let r of t)r&&Object.assign(e,r);return e}exports.a=l;exports.b=d;exports.c=T;exports.d=f;exports.e=g;exports.f=R;exports.g=h;exports.h=y;exports.i=O;exports.j=H;exports.k=q;exports.l=w;exports.m=E;exports.n=P;exports.o=C;exports.p=A;exports.q=k;exports.r=U;exports.s=$;exports.t=L;
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date input type - accepts Date, timestamp, or ISO string.
|
|
3
|
+
*/
|
|
4
|
+
type DateInput = Date | number | string;
|
|
5
|
+
/**
|
|
6
|
+
* Converts any date input to a Date object.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* toDate('2024-01-15');
|
|
10
|
+
* // => Date object
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* toDate(1705276800000);
|
|
14
|
+
* // => Date object
|
|
15
|
+
*/
|
|
16
|
+
declare function toDate(input: DateInput): Date;
|
|
17
|
+
/**
|
|
18
|
+
* Formats a date using a format string.
|
|
19
|
+
*
|
|
20
|
+
* Tokens:
|
|
21
|
+
* - YYYY: 4-digit year
|
|
22
|
+
* - YY: 2-digit year
|
|
23
|
+
* - MM: 2-digit month
|
|
24
|
+
* - M: month
|
|
25
|
+
* - DD: 2-digit day
|
|
26
|
+
* - D: day
|
|
27
|
+
* - HH: 2-digit hour (24h)
|
|
28
|
+
* - H: hour (24h)
|
|
29
|
+
* - hh: 2-digit hour (12h)
|
|
30
|
+
* - h: hour (12h)
|
|
31
|
+
* - mm: 2-digit minutes
|
|
32
|
+
* - m: minutes
|
|
33
|
+
* - ss: 2-digit seconds
|
|
34
|
+
* - s: seconds
|
|
35
|
+
* - SSS: milliseconds
|
|
36
|
+
* - A: AM/PM
|
|
37
|
+
* - a: am/pm
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* formatDate(new Date('2024-01-15T14:30:00'), 'YYYY-MM-DD');
|
|
41
|
+
* // => '2024-01-15'
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* formatDate(new Date('2024-01-15T14:30:00'), 'DD/MM/YYYY HH:mm');
|
|
45
|
+
* // => '15/01/2024 14:30'
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* formatDate(new Date('2024-01-15T14:30:00'), 'hh:mm A');
|
|
49
|
+
* // => '02:30 PM'
|
|
50
|
+
*/
|
|
51
|
+
declare function formatDate(input: DateInput, format: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Formats a date as ISO string (YYYY-MM-DD).
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* toISODateString(new Date('2024-01-15T14:30:00'));
|
|
57
|
+
* // => '2024-01-15'
|
|
58
|
+
*/
|
|
59
|
+
declare function toISODateString(input: DateInput): string;
|
|
60
|
+
/**
|
|
61
|
+
* Formats a date as ISO datetime string.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* toISOString(new Date('2024-01-15T14:30:00'));
|
|
65
|
+
* // => '2024-01-15T14:30:00.000Z'
|
|
66
|
+
*/
|
|
67
|
+
declare function toISOString(input: DateInput): string;
|
|
68
|
+
/**
|
|
69
|
+
* Formats a date as Unix timestamp (seconds).
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* toUnixTimestamp(new Date('2024-01-15T00:00:00Z'));
|
|
73
|
+
* // => 1705276800
|
|
74
|
+
*/
|
|
75
|
+
declare function toUnixTimestamp(input: DateInput): number;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a Date from Unix timestamp (seconds).
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* fromUnixTimestamp(1705276800);
|
|
81
|
+
* // => Date('2024-01-15T00:00:00Z')
|
|
82
|
+
*/
|
|
83
|
+
declare function fromUnixTimestamp(timestamp: number): Date;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Duration unit type.
|
|
87
|
+
*/
|
|
88
|
+
type DurationUnit = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'months' | 'years';
|
|
89
|
+
/**
|
|
90
|
+
* Adds time to a date.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* addTime(new Date('2024-01-15'), 1, 'days');
|
|
94
|
+
* // => Date('2024-01-16')
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* addTime(new Date('2024-01-15'), 2, 'weeks');
|
|
98
|
+
* // => Date('2024-01-29')
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* addTime(new Date('2024-01-15T10:00:00'), 30, 'minutes');
|
|
102
|
+
* // => Date('2024-01-15T10:30:00')
|
|
103
|
+
*/
|
|
104
|
+
declare function addTime(input: DateInput, value: number, unit: DurationUnit): Date;
|
|
105
|
+
/**
|
|
106
|
+
* Subtracts time from a date.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* subtractTime(new Date('2024-01-15'), 1, 'days');
|
|
110
|
+
* // => Date('2024-01-14')
|
|
111
|
+
*/
|
|
112
|
+
declare function subtractTime(input: DateInput, value: number, unit: DurationUnit): Date;
|
|
113
|
+
/**
|
|
114
|
+
* Gets the start of a time unit.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* startOf(new Date('2024-01-15T14:30:45'), 'day');
|
|
118
|
+
* // => Date('2024-01-15T00:00:00')
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* startOf(new Date('2024-01-15T14:30:45'), 'month');
|
|
122
|
+
* // => Date('2024-01-01T00:00:00')
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* startOf(new Date('2024-01-15T14:30:45'), 'hour');
|
|
126
|
+
* // => Date('2024-01-15T14:00:00')
|
|
127
|
+
*/
|
|
128
|
+
declare function startOf(input: DateInput, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'): Date;
|
|
129
|
+
/**
|
|
130
|
+
* Gets the end of a time unit.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* endOf(new Date('2024-01-15T14:30:45'), 'day');
|
|
134
|
+
* // => Date('2024-01-15T23:59:59.999')
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* endOf(new Date('2024-01-15'), 'month');
|
|
138
|
+
* // => Date('2024-01-31T23:59:59.999')
|
|
139
|
+
*/
|
|
140
|
+
declare function endOf(input: DateInput, unit: 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'): Date;
|
|
141
|
+
/**
|
|
142
|
+
* Gets the difference between two dates.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* diff(new Date('2024-01-15'), new Date('2024-01-10'), 'days');
|
|
146
|
+
* // => 5
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* diff(new Date('2024-03-01'), new Date('2024-01-01'), 'months');
|
|
150
|
+
* // => 2
|
|
151
|
+
*/
|
|
152
|
+
declare function diff(date1: DateInput, date2: DateInput, unit: DurationUnit): number;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Checks if a date is before another date.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* isBefore(new Date('2024-01-10'), new Date('2024-01-15'));
|
|
159
|
+
* // => true
|
|
160
|
+
*/
|
|
161
|
+
declare function isBefore(date1: DateInput, date2: DateInput): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Checks if a date is after another date.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* isAfter(new Date('2024-01-15'), new Date('2024-01-10'));
|
|
167
|
+
* // => true
|
|
168
|
+
*/
|
|
169
|
+
declare function isAfter(date1: DateInput, date2: DateInput): boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Checks if two dates are the same.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* isSameDate(new Date('2024-01-15'), new Date('2024-01-15'));
|
|
175
|
+
* // => true
|
|
176
|
+
*/
|
|
177
|
+
declare function isSameDate(date1: DateInput, date2: DateInput): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Checks if two dates are on the same day.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* isSameDay(new Date('2024-01-15T10:00'), new Date('2024-01-15T20:00'));
|
|
183
|
+
* // => true
|
|
184
|
+
*/
|
|
185
|
+
declare function isSameDay(date1: DateInput, date2: DateInput): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Checks if a date is between two dates.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* isBetween(new Date('2024-01-15'), new Date('2024-01-10'), new Date('2024-01-20'));
|
|
191
|
+
* // => true
|
|
192
|
+
*/
|
|
193
|
+
declare function isBetween(date: DateInput, start: DateInput, end: DateInput): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Checks if a date is today.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* isToday(new Date());
|
|
199
|
+
* // => true
|
|
200
|
+
*/
|
|
201
|
+
declare function isToday(input: DateInput): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Checks if a date is yesterday.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* isYesterday(new Date(Date.now() - 86400000));
|
|
207
|
+
* // => true
|
|
208
|
+
*/
|
|
209
|
+
declare function isYesterday(input: DateInput): boolean;
|
|
210
|
+
/**
|
|
211
|
+
* Checks if a date is tomorrow.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* isTomorrow(new Date(Date.now() + 86400000));
|
|
215
|
+
* // => true
|
|
216
|
+
*/
|
|
217
|
+
declare function isTomorrow(input: DateInput): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Checks if a date is in the past.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* isPast(new Date('2020-01-01'));
|
|
223
|
+
* // => true
|
|
224
|
+
*/
|
|
225
|
+
declare function isPast(input: DateInput): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* Checks if a date is in the future.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* isFuture(new Date('2030-01-01'));
|
|
231
|
+
* // => true
|
|
232
|
+
*/
|
|
233
|
+
declare function isFuture(input: DateInput): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* Checks if a year is a leap year.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* isLeapYear(2024);
|
|
239
|
+
* // => true
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* isLeapYear(2023);
|
|
243
|
+
* // => false
|
|
244
|
+
*/
|
|
245
|
+
declare function isLeapYear(year: number): boolean;
|
|
246
|
+
/**
|
|
247
|
+
* Checks if a date is a weekend (Saturday or Sunday).
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* isWeekend(new Date('2024-01-13')); // Saturday
|
|
251
|
+
* // => true
|
|
252
|
+
*/
|
|
253
|
+
declare function isWeekend(input: DateInput): boolean;
|
|
254
|
+
/**
|
|
255
|
+
* Checks if a date is a weekday (Monday to Friday).
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* isWeekday(new Date('2024-01-15')); // Monday
|
|
259
|
+
* // => true
|
|
260
|
+
*/
|
|
261
|
+
declare function isWeekday(input: DateInput): boolean;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Relative time options.
|
|
265
|
+
*/
|
|
266
|
+
interface RelativeTimeOptions {
|
|
267
|
+
locale?: string;
|
|
268
|
+
style?: 'long' | 'short' | 'narrow';
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Gets relative time string (e.g., "2 days ago", "in 3 hours").
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* timeAgo(new Date(Date.now() - 60000));
|
|
275
|
+
* // => '1 minute ago'
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* timeAgo(new Date(Date.now() - 3600000));
|
|
279
|
+
* // => '1 hour ago'
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* timeAgo(new Date(Date.now() + 86400000));
|
|
283
|
+
* // => 'in 1 day'
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* // With French locale
|
|
287
|
+
* timeAgo(new Date(Date.now() - 86400000), { locale: 'fr' });
|
|
288
|
+
* // => 'il y a 1 jour'
|
|
289
|
+
*/
|
|
290
|
+
declare function timeAgo(input: DateInput, options?: RelativeTimeOptions): string;
|
|
291
|
+
/**
|
|
292
|
+
* Gets a human-readable duration string.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* formatDuration(3661000);
|
|
296
|
+
* // => '1h 1m 1s'
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* formatDuration(86400000);
|
|
300
|
+
* // => '1d'
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* formatDuration(90061000);
|
|
304
|
+
* // => '1d 1h 1m 1s'
|
|
305
|
+
*/
|
|
306
|
+
declare function formatDuration(ms: number): string;
|
|
307
|
+
/**
|
|
308
|
+
* Parses a duration string to milliseconds.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* parseDuration('1h 30m');
|
|
312
|
+
* // => 5400000
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* parseDuration('2d 12h');
|
|
316
|
+
* // => 216000000
|
|
317
|
+
*/
|
|
318
|
+
declare function parseDuration(duration: string): number;
|
|
319
|
+
|
|
320
|
+
export { type DateInput, type DurationUnit, type RelativeTimeOptions, addTime, diff, endOf, formatDate, formatDuration, fromUnixTimestamp, isAfter, isBefore, isBetween, isFuture, isLeapYear, isPast, isSameDate, isSameDay, isToday, isTomorrow, isWeekday, isWeekend, isYesterday, parseDuration, startOf, subtractTime, timeAgo, toDate, toISODateString, toISOString, toUnixTimestamp };
|