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
|
@@ -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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunkCX7GJR55_js=require('../chunk-CX7GJR55.js');require('../chunk-WOT6VMZA.js');Object.defineProperty(exports,"addTime",{enumerable:true,get:function(){return chunkCX7GJR55_js.g}});Object.defineProperty(exports,"diff",{enumerable:true,get:function(){return chunkCX7GJR55_js.k}});Object.defineProperty(exports,"endOf",{enumerable:true,get:function(){return chunkCX7GJR55_js.j}});Object.defineProperty(exports,"formatDate",{enumerable:true,get:function(){return chunkCX7GJR55_js.b}});Object.defineProperty(exports,"formatDuration",{enumerable:true,get:function(){return chunkCX7GJR55_js.z}});Object.defineProperty(exports,"fromUnixTimestamp",{enumerable:true,get:function(){return chunkCX7GJR55_js.f}});Object.defineProperty(exports,"isAfter",{enumerable:true,get:function(){return chunkCX7GJR55_js.m}});Object.defineProperty(exports,"isBefore",{enumerable:true,get:function(){return chunkCX7GJR55_js.l}});Object.defineProperty(exports,"isBetween",{enumerable:true,get:function(){return chunkCX7GJR55_js.p}});Object.defineProperty(exports,"isFuture",{enumerable:true,get:function(){return chunkCX7GJR55_js.u}});Object.defineProperty(exports,"isLeapYear",{enumerable:true,get:function(){return chunkCX7GJR55_js.v}});Object.defineProperty(exports,"isPast",{enumerable:true,get:function(){return chunkCX7GJR55_js.t}});Object.defineProperty(exports,"isSameDate",{enumerable:true,get:function(){return chunkCX7GJR55_js.n}});Object.defineProperty(exports,"isSameDay",{enumerable:true,get:function(){return chunkCX7GJR55_js.o}});Object.defineProperty(exports,"isToday",{enumerable:true,get:function(){return chunkCX7GJR55_js.q}});Object.defineProperty(exports,"isTomorrow",{enumerable:true,get:function(){return chunkCX7GJR55_js.s}});Object.defineProperty(exports,"isWeekday",{enumerable:true,get:function(){return chunkCX7GJR55_js.x}});Object.defineProperty(exports,"isWeekend",{enumerable:true,get:function(){return chunkCX7GJR55_js.w}});Object.defineProperty(exports,"isYesterday",{enumerable:true,get:function(){return chunkCX7GJR55_js.r}});Object.defineProperty(exports,"parseDuration",{enumerable:true,get:function(){return chunkCX7GJR55_js.A}});Object.defineProperty(exports,"startOf",{enumerable:true,get:function(){return chunkCX7GJR55_js.i}});Object.defineProperty(exports,"subtractTime",{enumerable:true,get:function(){return chunkCX7GJR55_js.h}});Object.defineProperty(exports,"timeAgo",{enumerable:true,get:function(){return chunkCX7GJR55_js.y}});Object.defineProperty(exports,"toDate",{enumerable:true,get:function(){return chunkCX7GJR55_js.a}});Object.defineProperty(exports,"toISODateString",{enumerable:true,get:function(){return chunkCX7GJR55_js.c}});Object.defineProperty(exports,"toISOString",{enumerable:true,get:function(){return chunkCX7GJR55_js.d}});Object.defineProperty(exports,"toUnixTimestamp",{enumerable:true,get:function(){return chunkCX7GJR55_js.e}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{g as addTime,k as diff,j as endOf,b as formatDate,z as formatDuration,f as fromUnixTimestamp,m as isAfter,l as isBefore,p as isBetween,u as isFuture,v as isLeapYear,t as isPast,n as isSameDate,o as isSameDay,q as isToday,s as isTomorrow,x as isWeekday,w as isWeekend,r as isYesterday,A as parseDuration,i as startOf,h as subtractTime,y as timeAgo,a as toDate,c as toISODateString,d as toISOString,e as toUnixTimestamp}from'../chunk-X6JSYVIW.mjs';import'../chunk-JZXLCA2E.mjs';
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hash algorithm type.
|
|
3
|
+
*/
|
|
4
|
+
type HashAlgorithm = 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
5
|
+
/**
|
|
6
|
+
* Hashes a string using the specified algorithm.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* await hash('hello world', 'SHA-256');
|
|
10
|
+
* // => 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* await hash('password123', 'SHA-512');
|
|
14
|
+
* // => '...' (128 character hex string)
|
|
15
|
+
*/
|
|
16
|
+
declare function hash(data: string, algorithm?: HashAlgorithm): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Hashes a string using SHA-256.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* await sha256('hello world');
|
|
22
|
+
* // => 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9'
|
|
23
|
+
*/
|
|
24
|
+
declare function sha256(data: string): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Hashes a string using SHA-512.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* await sha512('hello world');
|
|
30
|
+
* // => '...' (128 character hex string)
|
|
31
|
+
*/
|
|
32
|
+
declare function sha512(data: string): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates an HMAC signature.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* await hmac('message', 'secret-key', 'SHA-256');
|
|
38
|
+
* // => '...' (hex string)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Verify webhook signature
|
|
42
|
+
* const signature = await hmac(payload, webhookSecret);
|
|
43
|
+
* if (signature === receivedSignature) {
|
|
44
|
+
* // Valid signature
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
declare function hmac(data: string, key: string, algorithm?: HashAlgorithm): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Compares two strings in constant time to prevent timing attacks.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const isValid = timingSafeEqual(providedHash, expectedHash);
|
|
53
|
+
*/
|
|
54
|
+
declare function timingSafeEqual(a: string, b: string): boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generates a random UUID (v4).
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* uuid();
|
|
61
|
+
* // => 'f47ac10b-58cc-4372-a567-0e02b2c3d479'
|
|
62
|
+
*/
|
|
63
|
+
declare function uuid(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Generates random bytes as a hex string.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* randomBytes(16);
|
|
69
|
+
* // => '1a2b3c4d5e6f7890abcdef1234567890'
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* // Generate a secure token
|
|
73
|
+
* const token = randomBytes(32);
|
|
74
|
+
*/
|
|
75
|
+
declare function randomBytes(length: number): string;
|
|
76
|
+
/**
|
|
77
|
+
* Generates a random string with specified characters.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* randomString(16);
|
|
81
|
+
* // => 'aB3xY9kLmN2pQrSt'
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* // Custom alphabet
|
|
85
|
+
* randomString(8, '0123456789');
|
|
86
|
+
* // => '48291037'
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* // Generate a password
|
|
90
|
+
* randomString(16, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%');
|
|
91
|
+
*/
|
|
92
|
+
declare function randomString(length: number, alphabet?: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Generates a random integer between min and max (inclusive).
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* randomInt(1, 100);
|
|
98
|
+
* // => 42
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* // Generate a random dice roll
|
|
102
|
+
* randomInt(1, 6);
|
|
103
|
+
* // => 4
|
|
104
|
+
*/
|
|
105
|
+
declare function randomInt(min: number, max: number): number;
|
|
106
|
+
/**
|
|
107
|
+
* Generates a secure token suitable for authentication.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* generateToken();
|
|
111
|
+
* // => 'a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6'
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* generateToken(64);
|
|
115
|
+
* // => '...' (64 character token)
|
|
116
|
+
*/
|
|
117
|
+
declare function generateToken(length?: number): string;
|
|
118
|
+
/**
|
|
119
|
+
* Generates a URL-safe random string (base64url).
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* urlSafeToken(32);
|
|
123
|
+
* // => 'xY9kLmN2pQrSt_aB3-Y9kLmN2pQrSt'
|
|
124
|
+
*/
|
|
125
|
+
declare function urlSafeToken(length: number): string;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Encodes a string to base64.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* base64Encode('Hello, World!');
|
|
132
|
+
* // => 'SGVsbG8sIFdvcmxkIQ=='
|
|
133
|
+
*/
|
|
134
|
+
declare function base64Encode(data: string): string;
|
|
135
|
+
/**
|
|
136
|
+
* Decodes a base64 string.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* base64Decode('SGVsbG8sIFdvcmxkIQ==');
|
|
140
|
+
* // => 'Hello, World!'
|
|
141
|
+
*/
|
|
142
|
+
declare function base64Decode(data: string): string;
|
|
143
|
+
/**
|
|
144
|
+
* Encodes a string to URL-safe base64.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* base64UrlEncode('Hello, World!');
|
|
148
|
+
* // => 'SGVsbG8sIFdvcmxkIQ'
|
|
149
|
+
*/
|
|
150
|
+
declare function base64UrlEncode(data: string): string;
|
|
151
|
+
/**
|
|
152
|
+
* Decodes a URL-safe base64 string.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* base64UrlDecode('SGVsbG8sIFdvcmxkIQ');
|
|
156
|
+
* // => 'Hello, World!'
|
|
157
|
+
*/
|
|
158
|
+
declare function base64UrlDecode(data: string): string;
|
|
159
|
+
/**
|
|
160
|
+
* Converts a string to hex.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* stringToHex('Hello');
|
|
164
|
+
* // => '48656c6c6f'
|
|
165
|
+
*/
|
|
166
|
+
declare function stringToHex(str: string): string;
|
|
167
|
+
/**
|
|
168
|
+
* Converts hex to a string.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* hexToString('48656c6c6f');
|
|
172
|
+
* // => 'Hello'
|
|
173
|
+
*/
|
|
174
|
+
declare function hexToString(hex: string): string;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a Uint8Array to hex string.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* bytesToHex(new Uint8Array([72, 101, 108, 108, 111]));
|
|
180
|
+
* // => '48656c6c6f'
|
|
181
|
+
*/
|
|
182
|
+
declare function bytesToHex(bytes: Uint8Array): string;
|
|
183
|
+
/**
|
|
184
|
+
* Converts a hex string to Uint8Array.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* hexToBytes('48656c6c6f');
|
|
188
|
+
* // => Uint8Array([72, 101, 108, 108, 111])
|
|
189
|
+
*/
|
|
190
|
+
declare function hexToBytes(hex: string): Uint8Array;
|
|
191
|
+
/**
|
|
192
|
+
* Encodes a string to UTF-8 bytes.
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* utf8Encode('Hello');
|
|
196
|
+
* // => Uint8Array([72, 101, 108, 108, 111])
|
|
197
|
+
*/
|
|
198
|
+
declare function utf8Encode(str: string): Uint8Array;
|
|
199
|
+
/**
|
|
200
|
+
* Decodes UTF-8 bytes to a string.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* utf8Decode(new Uint8Array([72, 101, 108, 108, 111]));
|
|
204
|
+
* // => 'Hello'
|
|
205
|
+
*/
|
|
206
|
+
declare function utf8Decode(bytes: Uint8Array): string;
|
|
207
|
+
|
|
208
|
+
export { type HashAlgorithm, base64Decode, base64Encode, base64UrlDecode, base64UrlEncode, bytesToHex, generateToken, hash, hexToBytes, hexToString, hmac, randomBytes, randomInt, randomString, sha256, sha512, stringToHex, timingSafeEqual, urlSafeToken, utf8Decode, utf8Encode, uuid };
|