@sudobility/types 1.9.52 → 1.9.54
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/dist/index.cjs +10 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/types/blockchain/index.cjs +30 -0
- package/dist/types/blockchain/index.d.ts +14 -0
- package/dist/types/blockchain/index.d.ts.map +1 -0
- package/dist/types/blockchain/index.js +30 -0
- package/dist/types/blockchain/index.js.map +1 -0
- package/dist/types/blockchain/validation.cjs +57 -1
- package/dist/types/blockchain/validation.d.ts +57 -1
- package/dist/types/blockchain/validation.d.ts.map +1 -1
- package/dist/types/blockchain/validation.js +57 -1
- package/dist/types/blockchain/validation.js.map +1 -1
- package/dist/types/business/enums.cjs +110 -25
- package/dist/types/business/enums.d.ts +110 -2
- package/dist/types/business/enums.d.ts.map +1 -1
- package/dist/types/business/enums.js +110 -25
- package/dist/types/business/enums.js.map +1 -1
- package/dist/types/common.cjs +7 -1
- package/dist/types/common.d.ts +134 -20
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +7 -1
- package/dist/types/common.js.map +1 -1
- package/dist/types/subscription/entitlements.cjs +14 -0
- package/dist/types/subscription/entitlements.d.ts +11 -0
- package/dist/types/subscription/entitlements.d.ts.map +1 -0
- package/dist/types/subscription/entitlements.js +14 -0
- package/dist/types/subscription/entitlements.js.map +1 -0
- package/dist/types/subscription/period.cjs +29 -0
- package/dist/types/subscription/period.d.ts +18 -0
- package/dist/types/subscription/period.d.ts.map +1 -0
- package/dist/types/subscription/period.js +29 -0
- package/dist/types/subscription/period.js.map +1 -0
- package/dist/utils/async-helpers.cjs +124 -10
- package/dist/utils/async-helpers.d.ts +129 -8
- package/dist/utils/async-helpers.d.ts.map +1 -1
- package/dist/utils/async-helpers.js +124 -10
- package/dist/utils/async-helpers.js.map +1 -1
- package/dist/utils/formatting/currency.cjs +5 -2
- package/dist/utils/formatting/currency.d.ts +5 -1
- package/dist/utils/formatting/currency.d.ts.map +1 -1
- package/dist/utils/formatting/currency.js +5 -2
- package/dist/utils/formatting/currency.js.map +1 -1
- package/dist/utils/formatting/date.cjs +67 -8
- package/dist/utils/formatting/date.d.ts +67 -8
- package/dist/utils/formatting/date.d.ts.map +1 -1
- package/dist/utils/formatting/date.js +67 -8
- package/dist/utils/formatting/date.js.map +1 -1
- package/dist/utils/formatting/string.cjs +150 -17
- package/dist/utils/formatting/string.d.ts +150 -17
- package/dist/utils/formatting/string.d.ts.map +1 -1
- package/dist/utils/formatting/string.js +150 -17
- package/dist/utils/formatting/string.js.map +1 -1
- package/dist/utils/validation/type-validation.cjs +94 -11
- package/dist/utils/validation/type-validation.d.ts +94 -11
- package/dist/utils/validation/type-validation.d.ts.map +1 -1
- package/dist/utils/validation/type-validation.js +94 -11
- package/dist/utils/validation/type-validation.js.map +1 -1
- package/package.json +6 -1
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Currency formatting utilities for USDC and other tokens
|
|
3
|
+
* Currency formatting utilities for USDC and other tokens.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.CLAIM_PERIOD_DAYS = exports.USDC_DECIMALS = void 0;
|
|
7
9
|
exports.formatUSDC = formatUSDC;
|
|
8
10
|
exports.parseUSDC = parseUSDC;
|
|
9
|
-
|
|
11
|
+
/** Number of decimal places for USDC token amounts. */
|
|
10
12
|
exports.USDC_DECIMALS = 6;
|
|
13
|
+
/** Revenue claim expiration period in days. */
|
|
11
14
|
exports.CLAIM_PERIOD_DAYS = 60;
|
|
12
15
|
/**
|
|
13
16
|
* Format USDC amount from smallest unit to human-readable string
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/formatting/currency.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"","sources":["../../../src/utils/formatting/currency.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAiBH,gCAEC;AAWD,8BAEC;AA9BD,uDAAuD;AAC1C,QAAA,aAAa,GAAG,CAAC,CAAC;AAE/B,+CAA+C;AAClC,QAAA,iBAAiB,GAAG,EAAE,CAAC;AAEpC;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,qBAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,SAAS,CAAC,MAAc;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,qBAAa,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Date formatting utilities
|
|
3
|
+
* Date formatting utilities.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.formatEmailDate = formatEmailDate;
|
|
@@ -11,7 +13,19 @@ exports.isDateInRange = isDateInRange;
|
|
|
11
13
|
exports.addDays = addDays;
|
|
12
14
|
exports.addHours = addHours;
|
|
13
15
|
/**
|
|
14
|
-
* Format a date for display in email list
|
|
16
|
+
* Format a date for display in email list.
|
|
17
|
+
* Returns time for today, "Yesterday", day name for the past week,
|
|
18
|
+
* or a short date for older messages.
|
|
19
|
+
*
|
|
20
|
+
* @param date - Date object or ISO date string
|
|
21
|
+
* @returns Formatted date string
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* formatEmailDate(new Date()); // "3:45 PM"
|
|
27
|
+
* formatEmailDate('2024-01-15'); // "Jan 15"
|
|
28
|
+
* ```
|
|
15
29
|
*/
|
|
16
30
|
function formatEmailDate(date) {
|
|
17
31
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
@@ -54,13 +68,32 @@ function formatEmailDate(date) {
|
|
|
54
68
|
});
|
|
55
69
|
}
|
|
56
70
|
/**
|
|
57
|
-
* Format a timestamp to ISO string
|
|
71
|
+
* Format a Unix timestamp (ms) to an ISO 8601 string.
|
|
72
|
+
*
|
|
73
|
+
* @param timestamp - Unix timestamp in milliseconds
|
|
74
|
+
* @returns ISO 8601 date string
|
|
75
|
+
* @since 1.0.0
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* formatTimestamp(1700000000000); // "2023-11-14T22:13:20.000Z"
|
|
80
|
+
* ```
|
|
58
81
|
*/
|
|
59
82
|
function formatTimestamp(timestamp) {
|
|
60
83
|
return new Date(timestamp).toISOString();
|
|
61
84
|
}
|
|
62
85
|
/**
|
|
63
|
-
* Format a date to a relative time string (e.g., "2 hours ago")
|
|
86
|
+
* Format a date to a relative time string (e.g., "2 hours ago").
|
|
87
|
+
*
|
|
88
|
+
* @param date - Date object, ISO string, or Unix timestamp (ms)
|
|
89
|
+
* @returns Human-readable relative time string
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* formatRelativeTime(Date.now() - 3600000); // "1 hour ago"
|
|
95
|
+
* formatRelativeTime('2024-01-01'); // "1 year ago"
|
|
96
|
+
* ```
|
|
64
97
|
*/
|
|
65
98
|
function formatRelativeTime(date) {
|
|
66
99
|
const dateObj = typeof date === 'string' || typeof date === 'number'
|
|
@@ -99,7 +132,17 @@ function formatRelativeTime(date) {
|
|
|
99
132
|
return diffYears === 1 ? '1 year ago' : `${diffYears} years ago`;
|
|
100
133
|
}
|
|
101
134
|
/**
|
|
102
|
-
* Parse a date string safely
|
|
135
|
+
* Parse a date string safely, returning null on invalid input.
|
|
136
|
+
*
|
|
137
|
+
* @param dateString - Date string to parse
|
|
138
|
+
* @returns Parsed Date or null if invalid
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* parseDate('2024-01-15'); // Date object
|
|
144
|
+
* parseDate('not-a-date'); // null
|
|
145
|
+
* ```
|
|
103
146
|
*/
|
|
104
147
|
function parseDate(dateString) {
|
|
105
148
|
try {
|
|
@@ -114,13 +157,24 @@ function parseDate(dateString) {
|
|
|
114
157
|
}
|
|
115
158
|
}
|
|
116
159
|
/**
|
|
117
|
-
* Check if a date
|
|
160
|
+
* Check if a date falls within an inclusive range.
|
|
161
|
+
*
|
|
162
|
+
* @param date - Date to check
|
|
163
|
+
* @param startDate - Range start (inclusive)
|
|
164
|
+
* @param endDate - Range end (inclusive)
|
|
165
|
+
* @returns True if date is within the range
|
|
166
|
+
* @since 1.0.0
|
|
118
167
|
*/
|
|
119
168
|
function isDateInRange(date, startDate, endDate) {
|
|
120
169
|
return date >= startDate && date <= endDate;
|
|
121
170
|
}
|
|
122
171
|
/**
|
|
123
|
-
* Add days
|
|
172
|
+
* Add (or subtract) days from a date. Returns a new Date instance.
|
|
173
|
+
*
|
|
174
|
+
* @param date - Starting date
|
|
175
|
+
* @param days - Number of days to add (negative to subtract)
|
|
176
|
+
* @returns New Date with days added
|
|
177
|
+
* @since 1.0.0
|
|
124
178
|
*/
|
|
125
179
|
function addDays(date, days) {
|
|
126
180
|
const result = new Date(date);
|
|
@@ -128,7 +182,12 @@ function addDays(date, days) {
|
|
|
128
182
|
return result;
|
|
129
183
|
}
|
|
130
184
|
/**
|
|
131
|
-
* Add hours
|
|
185
|
+
* Add (or subtract) hours from a date. Returns a new Date instance.
|
|
186
|
+
*
|
|
187
|
+
* @param date - Starting date
|
|
188
|
+
* @param hours - Number of hours to add (negative to subtract)
|
|
189
|
+
* @returns New Date with hours added
|
|
190
|
+
* @since 1.0.0
|
|
132
191
|
*/
|
|
133
192
|
function addHours(date, hours) {
|
|
134
193
|
const result = new Date(date);
|
|
@@ -1,33 +1,92 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Date formatting utilities
|
|
2
|
+
* Date formatting utilities.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
3
5
|
*/
|
|
4
6
|
import { Optional } from '../../types/common';
|
|
5
7
|
/**
|
|
6
|
-
* Format a date for display in email list
|
|
8
|
+
* Format a date for display in email list.
|
|
9
|
+
* Returns time for today, "Yesterday", day name for the past week,
|
|
10
|
+
* or a short date for older messages.
|
|
11
|
+
*
|
|
12
|
+
* @param date - Date object or ISO date string
|
|
13
|
+
* @returns Formatted date string
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* formatEmailDate(new Date()); // "3:45 PM"
|
|
19
|
+
* formatEmailDate('2024-01-15'); // "Jan 15"
|
|
20
|
+
* ```
|
|
7
21
|
*/
|
|
8
22
|
export declare function formatEmailDate(date: Date | string): string;
|
|
9
23
|
/**
|
|
10
|
-
* Format a timestamp to ISO string
|
|
24
|
+
* Format a Unix timestamp (ms) to an ISO 8601 string.
|
|
25
|
+
*
|
|
26
|
+
* @param timestamp - Unix timestamp in milliseconds
|
|
27
|
+
* @returns ISO 8601 date string
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* formatTimestamp(1700000000000); // "2023-11-14T22:13:20.000Z"
|
|
33
|
+
* ```
|
|
11
34
|
*/
|
|
12
35
|
export declare function formatTimestamp(timestamp: number): string;
|
|
13
36
|
/**
|
|
14
|
-
* Format a date to a relative time string (e.g., "2 hours ago")
|
|
37
|
+
* Format a date to a relative time string (e.g., "2 hours ago").
|
|
38
|
+
*
|
|
39
|
+
* @param date - Date object, ISO string, or Unix timestamp (ms)
|
|
40
|
+
* @returns Human-readable relative time string
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* formatRelativeTime(Date.now() - 3600000); // "1 hour ago"
|
|
46
|
+
* formatRelativeTime('2024-01-01'); // "1 year ago"
|
|
47
|
+
* ```
|
|
15
48
|
*/
|
|
16
49
|
export declare function formatRelativeTime(date: Date | string | number): string;
|
|
17
50
|
/**
|
|
18
|
-
* Parse a date string safely
|
|
51
|
+
* Parse a date string safely, returning null on invalid input.
|
|
52
|
+
*
|
|
53
|
+
* @param dateString - Date string to parse
|
|
54
|
+
* @returns Parsed Date or null if invalid
|
|
55
|
+
* @since 1.0.0
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* parseDate('2024-01-15'); // Date object
|
|
60
|
+
* parseDate('not-a-date'); // null
|
|
61
|
+
* ```
|
|
19
62
|
*/
|
|
20
63
|
export declare function parseDate(dateString: string): Optional<Date>;
|
|
21
64
|
/**
|
|
22
|
-
* Check if a date
|
|
65
|
+
* Check if a date falls within an inclusive range.
|
|
66
|
+
*
|
|
67
|
+
* @param date - Date to check
|
|
68
|
+
* @param startDate - Range start (inclusive)
|
|
69
|
+
* @param endDate - Range end (inclusive)
|
|
70
|
+
* @returns True if date is within the range
|
|
71
|
+
* @since 1.0.0
|
|
23
72
|
*/
|
|
24
73
|
export declare function isDateInRange(date: Date, startDate: Date, endDate: Date): boolean;
|
|
25
74
|
/**
|
|
26
|
-
* Add days
|
|
75
|
+
* Add (or subtract) days from a date. Returns a new Date instance.
|
|
76
|
+
*
|
|
77
|
+
* @param date - Starting date
|
|
78
|
+
* @param days - Number of days to add (negative to subtract)
|
|
79
|
+
* @returns New Date with days added
|
|
80
|
+
* @since 1.0.0
|
|
27
81
|
*/
|
|
28
82
|
export declare function addDays(date: Date, days: number): Date;
|
|
29
83
|
/**
|
|
30
|
-
* Add hours
|
|
84
|
+
* Add (or subtract) hours from a date. Returns a new Date instance.
|
|
85
|
+
*
|
|
86
|
+
* @param date - Starting date
|
|
87
|
+
* @param hours - Number of hours to add (negative to subtract)
|
|
88
|
+
* @returns New Date with hours added
|
|
89
|
+
* @since 1.0.0
|
|
31
90
|
*/
|
|
32
91
|
export declare function addHours(date: Date, hours: number): Date;
|
|
33
92
|
//# sourceMappingURL=date.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/date.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/date.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CA8C3D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CA6CvE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAC,CAU5D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,GACZ,OAAO,CAET;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAItD;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIxD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Date formatting utilities
|
|
3
|
+
* Date formatting utilities.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.formatEmailDate = formatEmailDate;
|
|
@@ -11,7 +13,19 @@ exports.isDateInRange = isDateInRange;
|
|
|
11
13
|
exports.addDays = addDays;
|
|
12
14
|
exports.addHours = addHours;
|
|
13
15
|
/**
|
|
14
|
-
* Format a date for display in email list
|
|
16
|
+
* Format a date for display in email list.
|
|
17
|
+
* Returns time for today, "Yesterday", day name for the past week,
|
|
18
|
+
* or a short date for older messages.
|
|
19
|
+
*
|
|
20
|
+
* @param date - Date object or ISO date string
|
|
21
|
+
* @returns Formatted date string
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* formatEmailDate(new Date()); // "3:45 PM"
|
|
27
|
+
* formatEmailDate('2024-01-15'); // "Jan 15"
|
|
28
|
+
* ```
|
|
15
29
|
*/
|
|
16
30
|
function formatEmailDate(date) {
|
|
17
31
|
const dateObj = typeof date === 'string' ? new Date(date) : date;
|
|
@@ -54,13 +68,32 @@ function formatEmailDate(date) {
|
|
|
54
68
|
});
|
|
55
69
|
}
|
|
56
70
|
/**
|
|
57
|
-
* Format a timestamp to ISO string
|
|
71
|
+
* Format a Unix timestamp (ms) to an ISO 8601 string.
|
|
72
|
+
*
|
|
73
|
+
* @param timestamp - Unix timestamp in milliseconds
|
|
74
|
+
* @returns ISO 8601 date string
|
|
75
|
+
* @since 1.0.0
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* formatTimestamp(1700000000000); // "2023-11-14T22:13:20.000Z"
|
|
80
|
+
* ```
|
|
58
81
|
*/
|
|
59
82
|
function formatTimestamp(timestamp) {
|
|
60
83
|
return new Date(timestamp).toISOString();
|
|
61
84
|
}
|
|
62
85
|
/**
|
|
63
|
-
* Format a date to a relative time string (e.g., "2 hours ago")
|
|
86
|
+
* Format a date to a relative time string (e.g., "2 hours ago").
|
|
87
|
+
*
|
|
88
|
+
* @param date - Date object, ISO string, or Unix timestamp (ms)
|
|
89
|
+
* @returns Human-readable relative time string
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* formatRelativeTime(Date.now() - 3600000); // "1 hour ago"
|
|
95
|
+
* formatRelativeTime('2024-01-01'); // "1 year ago"
|
|
96
|
+
* ```
|
|
64
97
|
*/
|
|
65
98
|
function formatRelativeTime(date) {
|
|
66
99
|
const dateObj = typeof date === 'string' || typeof date === 'number'
|
|
@@ -99,7 +132,17 @@ function formatRelativeTime(date) {
|
|
|
99
132
|
return diffYears === 1 ? '1 year ago' : `${diffYears} years ago`;
|
|
100
133
|
}
|
|
101
134
|
/**
|
|
102
|
-
* Parse a date string safely
|
|
135
|
+
* Parse a date string safely, returning null on invalid input.
|
|
136
|
+
*
|
|
137
|
+
* @param dateString - Date string to parse
|
|
138
|
+
* @returns Parsed Date or null if invalid
|
|
139
|
+
* @since 1.0.0
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* parseDate('2024-01-15'); // Date object
|
|
144
|
+
* parseDate('not-a-date'); // null
|
|
145
|
+
* ```
|
|
103
146
|
*/
|
|
104
147
|
function parseDate(dateString) {
|
|
105
148
|
try {
|
|
@@ -114,13 +157,24 @@ function parseDate(dateString) {
|
|
|
114
157
|
}
|
|
115
158
|
}
|
|
116
159
|
/**
|
|
117
|
-
* Check if a date
|
|
160
|
+
* Check if a date falls within an inclusive range.
|
|
161
|
+
*
|
|
162
|
+
* @param date - Date to check
|
|
163
|
+
* @param startDate - Range start (inclusive)
|
|
164
|
+
* @param endDate - Range end (inclusive)
|
|
165
|
+
* @returns True if date is within the range
|
|
166
|
+
* @since 1.0.0
|
|
118
167
|
*/
|
|
119
168
|
function isDateInRange(date, startDate, endDate) {
|
|
120
169
|
return date >= startDate && date <= endDate;
|
|
121
170
|
}
|
|
122
171
|
/**
|
|
123
|
-
* Add days
|
|
172
|
+
* Add (or subtract) days from a date. Returns a new Date instance.
|
|
173
|
+
*
|
|
174
|
+
* @param date - Starting date
|
|
175
|
+
* @param days - Number of days to add (negative to subtract)
|
|
176
|
+
* @returns New Date with days added
|
|
177
|
+
* @since 1.0.0
|
|
124
178
|
*/
|
|
125
179
|
function addDays(date, days) {
|
|
126
180
|
const result = new Date(date);
|
|
@@ -128,7 +182,12 @@ function addDays(date, days) {
|
|
|
128
182
|
return result;
|
|
129
183
|
}
|
|
130
184
|
/**
|
|
131
|
-
* Add hours
|
|
185
|
+
* Add (or subtract) hours from a date. Returns a new Date instance.
|
|
186
|
+
*
|
|
187
|
+
* @param date - Starting date
|
|
188
|
+
* @param hours - Number of hours to add (negative to subtract)
|
|
189
|
+
* @returns New Date with hours added
|
|
190
|
+
* @since 1.0.0
|
|
132
191
|
*/
|
|
133
192
|
function addHours(date, hours) {
|
|
134
193
|
const result = new Date(date);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/utils/formatting/date.ts"],"names":[],"mappings":";AAAA;;
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../../src/utils/formatting/date.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAmBH,0CA8CC;AAcD,0CAEC;AAeD,gDA6CC;AAeD,8BAUC;AAWD,sCAMC;AAUD,0BAIC;AAUD,4BAIC;AA/MD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,eAAe,CAAC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AAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAC3B,IAAU,EACV,SAAe,EACf,OAAa;IAEb,OAAO,IAAI,IAAI,SAAS,IAAI,IAAI,IAAI,OAAO,CAAC;AAC9C,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,OAAO,CAAC,IAAU,EAAE,IAAY;IAC9C,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,QAAQ,CAAC,IAAU,EAAE,KAAa;IAChD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* String formatting and manipulation utilities
|
|
3
|
+
* String formatting and manipulation utilities.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.truncate = truncate;
|
|
@@ -20,7 +22,18 @@ exports.randomString = randomString;
|
|
|
20
22
|
exports.pluralize = pluralize;
|
|
21
23
|
exports.formatNumber = formatNumber;
|
|
22
24
|
/**
|
|
23
|
-
* Truncate a string to a maximum length with
|
|
25
|
+
* Truncate a string to a maximum length with a suffix (default `...`).
|
|
26
|
+
*
|
|
27
|
+
* @param str - Input string
|
|
28
|
+
* @param maxLength - Maximum allowed length including suffix
|
|
29
|
+
* @param suffix - Truncation suffix (default: `'...'`)
|
|
30
|
+
* @returns Truncated string or original if within limit
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* truncate('Hello, World!', 8); // "Hello..."
|
|
36
|
+
* ```
|
|
24
37
|
*/
|
|
25
38
|
function truncate(str, maxLength, suffix = '...') {
|
|
26
39
|
if (!str || str.length <= maxLength) {
|
|
@@ -29,7 +42,16 @@ function truncate(str, maxLength, suffix = '...') {
|
|
|
29
42
|
return str.slice(0, maxLength - suffix.length) + suffix;
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
|
-
* Capitalize the first letter of a string
|
|
45
|
+
* Capitalize the first letter of a string.
|
|
46
|
+
*
|
|
47
|
+
* @param str - Input string
|
|
48
|
+
* @returns String with first character uppercased
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* capitalize('hello'); // "Hello"
|
|
54
|
+
* ```
|
|
33
55
|
*/
|
|
34
56
|
function capitalize(str) {
|
|
35
57
|
if (!str)
|
|
@@ -37,7 +59,16 @@ function capitalize(str) {
|
|
|
37
59
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
38
60
|
}
|
|
39
61
|
/**
|
|
40
|
-
* Convert a string to title case
|
|
62
|
+
* Convert a string to title case (capitalize each word).
|
|
63
|
+
*
|
|
64
|
+
* @param str - Input string
|
|
65
|
+
* @returns Title-cased string
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* toTitleCase('hello world'); // "Hello World"
|
|
71
|
+
* ```
|
|
41
72
|
*/
|
|
42
73
|
function toTitleCase(str) {
|
|
43
74
|
if (!str)
|
|
@@ -49,7 +80,16 @@ function toTitleCase(str) {
|
|
|
49
80
|
.join(' ');
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
52
|
-
* Convert a string to kebab
|
|
83
|
+
* Convert a string to kebab-case.
|
|
84
|
+
*
|
|
85
|
+
* @param str - Input string (camelCase, PascalCase, spaces, or underscores)
|
|
86
|
+
* @returns Kebab-cased string
|
|
87
|
+
* @since 1.0.0
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* toKebabCase('helloWorld'); // "hello-world"
|
|
92
|
+
* ```
|
|
53
93
|
*/
|
|
54
94
|
function toKebabCase(str) {
|
|
55
95
|
if (!str)
|
|
@@ -60,7 +100,16 @@ function toKebabCase(str) {
|
|
|
60
100
|
.toLowerCase();
|
|
61
101
|
}
|
|
62
102
|
/**
|
|
63
|
-
* Convert a string to
|
|
103
|
+
* Convert a string to camelCase.
|
|
104
|
+
*
|
|
105
|
+
* @param str - Input string (kebab-case, snake_case, or spaces)
|
|
106
|
+
* @returns camelCased string
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* toCamelCase('hello-world'); // "helloWorld"
|
|
112
|
+
* ```
|
|
64
113
|
*/
|
|
65
114
|
function toCamelCase(str) {
|
|
66
115
|
if (!str)
|
|
@@ -70,7 +119,16 @@ function toCamelCase(str) {
|
|
|
70
119
|
.replace(/^./, (char) => char.toLowerCase());
|
|
71
120
|
}
|
|
72
121
|
/**
|
|
73
|
-
* Convert a string to
|
|
122
|
+
* Convert a string to snake_case.
|
|
123
|
+
*
|
|
124
|
+
* @param str - Input string (camelCase, kebab-case, or spaces)
|
|
125
|
+
* @returns snake_cased string
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* toSnakeCase('helloWorld'); // "hello_world"
|
|
131
|
+
* ```
|
|
74
132
|
*/
|
|
75
133
|
function toSnakeCase(str) {
|
|
76
134
|
if (!str)
|
|
@@ -81,7 +139,11 @@ function toSnakeCase(str) {
|
|
|
81
139
|
.toLowerCase();
|
|
82
140
|
}
|
|
83
141
|
/**
|
|
84
|
-
*
|
|
142
|
+
* Collapse consecutive whitespace to a single space and trim.
|
|
143
|
+
*
|
|
144
|
+
* @param str - Input string
|
|
145
|
+
* @returns Normalized string
|
|
146
|
+
* @since 1.0.0
|
|
85
147
|
*/
|
|
86
148
|
function normalizeWhitespace(str) {
|
|
87
149
|
if (!str)
|
|
@@ -89,19 +151,36 @@ function normalizeWhitespace(str) {
|
|
|
89
151
|
return str.replace(/\s+/g, ' ').trim();
|
|
90
152
|
}
|
|
91
153
|
/**
|
|
92
|
-
* Check if a string is empty or only whitespace
|
|
154
|
+
* Check if a string is empty, undefined, null, or only whitespace.
|
|
155
|
+
*
|
|
156
|
+
* @param str - Input string (may be nullish)
|
|
157
|
+
* @returns True if blank
|
|
158
|
+
* @since 1.0.0
|
|
93
159
|
*/
|
|
94
160
|
function isBlank(str) {
|
|
95
161
|
return !str || str.trim().length === 0;
|
|
96
162
|
}
|
|
97
163
|
/**
|
|
98
|
-
*
|
|
164
|
+
* Type guard: check if a string is not empty and not only whitespace.
|
|
165
|
+
*
|
|
166
|
+
* @param str - Input string (may be nullish)
|
|
167
|
+
* @returns True (and narrows to `string`) if not blank
|
|
168
|
+
* @since 1.0.0
|
|
99
169
|
*/
|
|
100
170
|
function isNotBlank(str) {
|
|
101
171
|
return !isBlank(str);
|
|
102
172
|
}
|
|
103
173
|
/**
|
|
104
|
-
* Escape HTML special characters
|
|
174
|
+
* Escape HTML special characters (`&`, `<`, `>`, `"`, `'`).
|
|
175
|
+
*
|
|
176
|
+
* @param str - Input string
|
|
177
|
+
* @returns HTML-escaped string
|
|
178
|
+
* @since 1.0.0
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* escapeHtml('<b>Hi</b>'); // "<b>Hi</b>"
|
|
183
|
+
* ```
|
|
105
184
|
*/
|
|
106
185
|
function escapeHtml(str) {
|
|
107
186
|
if (!str)
|
|
@@ -116,7 +195,16 @@ function escapeHtml(str) {
|
|
|
116
195
|
return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
|
|
117
196
|
}
|
|
118
197
|
/**
|
|
119
|
-
* Remove HTML tags from a string
|
|
198
|
+
* Remove all HTML tags from a string.
|
|
199
|
+
*
|
|
200
|
+
* @param str - Input string with HTML
|
|
201
|
+
* @returns Plain text with tags removed
|
|
202
|
+
* @since 1.0.0
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* stripHtml('<p>Hello <b>world</b></p>'); // "Hello world"
|
|
207
|
+
* ```
|
|
120
208
|
*/
|
|
121
209
|
function stripHtml(str) {
|
|
122
210
|
if (!str)
|
|
@@ -124,7 +212,12 @@ function stripHtml(str) {
|
|
|
124
212
|
return str.replace(/<[^>]*>/g, '');
|
|
125
213
|
}
|
|
126
214
|
/**
|
|
127
|
-
* Extract initials from a name
|
|
215
|
+
* Extract initials from a name (e.g., "John Doe" -> "JD").
|
|
216
|
+
*
|
|
217
|
+
* @param name - Full name
|
|
218
|
+
* @param maxInitials - Maximum number of initials (default: 2)
|
|
219
|
+
* @returns Uppercase initials
|
|
220
|
+
* @since 1.0.0
|
|
128
221
|
*/
|
|
129
222
|
function getInitials(name, maxInitials = 2) {
|
|
130
223
|
if (!name)
|
|
@@ -137,7 +230,18 @@ function getInitials(name, maxInitials = 2) {
|
|
|
137
230
|
return initials;
|
|
138
231
|
}
|
|
139
232
|
/**
|
|
140
|
-
* Format bytes to human-readable size
|
|
233
|
+
* Format bytes to a human-readable size string (e.g., "1.5 MB").
|
|
234
|
+
*
|
|
235
|
+
* @param bytes - Size in bytes
|
|
236
|
+
* @param decimals - Decimal places (default: 2)
|
|
237
|
+
* @returns Formatted string like "1.5 MB"
|
|
238
|
+
* @since 1.0.0
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* formatBytes(1536); // "1.5 KB"
|
|
243
|
+
* formatBytes(0); // "0 Bytes"
|
|
244
|
+
* ```
|
|
141
245
|
*/
|
|
142
246
|
function formatBytes(bytes, decimals = 2) {
|
|
143
247
|
if (bytes === 0)
|
|
@@ -149,7 +253,13 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
149
253
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
150
254
|
}
|
|
151
255
|
/**
|
|
152
|
-
* Generate a random string
|
|
256
|
+
* Generate a random string of a given length.
|
|
257
|
+
*
|
|
258
|
+
* @param length - Desired string length
|
|
259
|
+
* @param charset - Character set: `'alpha'`, `'numeric'`,
|
|
260
|
+
* `'alphanumeric'` (default), `'hex'`, or a custom string
|
|
261
|
+
* @returns Random string
|
|
262
|
+
* @since 1.0.0
|
|
153
263
|
*/
|
|
154
264
|
function randomString(length, charset = 'alphanumeric') {
|
|
155
265
|
let chars;
|
|
@@ -176,7 +286,21 @@ function randomString(length, charset = 'alphanumeric') {
|
|
|
176
286
|
return result;
|
|
177
287
|
}
|
|
178
288
|
/**
|
|
179
|
-
* Pluralize a word based on count
|
|
289
|
+
* Pluralize a word based on count.
|
|
290
|
+
* Appends `'s'` by default when count is not 1.
|
|
291
|
+
*
|
|
292
|
+
* @param count - Item count
|
|
293
|
+
* @param singular - Singular form
|
|
294
|
+
* @param plural - Optional explicit plural form
|
|
295
|
+
* @returns Singular or plural form based on count
|
|
296
|
+
* @since 1.0.0
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* pluralize(1, 'item'); // "item"
|
|
301
|
+
* pluralize(3, 'item'); // "items"
|
|
302
|
+
* pluralize(2, 'child', 'children'); // "children"
|
|
303
|
+
* ```
|
|
180
304
|
*/
|
|
181
305
|
function pluralize(count, singular, plural) {
|
|
182
306
|
if (count === 1) {
|
|
@@ -185,7 +309,16 @@ function pluralize(count, singular, plural) {
|
|
|
185
309
|
return plural || `${singular}s`;
|
|
186
310
|
}
|
|
187
311
|
/**
|
|
188
|
-
* Format a number with commas as thousands separators
|
|
312
|
+
* Format a number with commas as thousands separators.
|
|
313
|
+
*
|
|
314
|
+
* @param num - Number to format
|
|
315
|
+
* @returns Formatted string (e.g., "1,234,567")
|
|
316
|
+
* @since 1.0.0
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* formatNumber(1234567); // "1,234,567"
|
|
321
|
+
* ```
|
|
189
322
|
*/
|
|
190
323
|
function formatNumber(num) {
|
|
191
324
|
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|