@rtorcato/js-common 1.8.1 → 2.0.1
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 +24 -0
- package/README.md +77 -62
- package/dist/abortController/index.d.ts +29 -0
- package/dist/abortController/index.d.ts.map +1 -0
- package/dist/arrays/index.d.ts +134 -0
- package/dist/arrays/index.d.ts.map +1 -0
- package/dist/arrays/index.js +1 -1
- package/dist/boolean/index.d.ts +41 -0
- package/dist/boolean/index.d.ts.map +1 -0
- package/dist/boolean/index.js +1 -1
- package/dist/colors/index.d.ts +63 -0
- package/dist/colors/index.d.ts.map +1 -0
- package/dist/console/index.d.ts +16 -0
- package/dist/console/index.d.ts.map +1 -0
- package/dist/crypto/index.d.ts +34 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/currency/currencies.d.ts +16 -0
- package/dist/currency/currencies.d.ts.map +1 -0
- package/dist/currency/index.d.ts +170 -0
- package/dist/currency/index.d.ts.map +1 -0
- package/dist/date/index.d.ts +44 -0
- package/dist/date/index.d.ts.map +1 -0
- package/dist/datetime/index.d.ts +52 -0
- package/dist/datetime/index.d.ts.map +1 -0
- package/dist/emails/banned/index.d.ts +9 -0
- package/dist/emails/banned/index.d.ts.map +1 -0
- package/dist/emails/index.d.ts +26 -0
- package/dist/emails/index.d.ts.map +1 -0
- package/dist/env/index.d.ts +63 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/errors/index.d.ts +39 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +1 -1
- package/dist/events/index.d.ts +35 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/fetch/index.d.ts +38 -0
- package/dist/fetch/index.d.ts.map +1 -0
- package/dist/file/index.d.ts +32 -0
- package/dist/file/index.d.ts.map +1 -0
- package/dist/formatting/index.d.ts +40 -0
- package/dist/formatting/index.d.ts.map +1 -0
- package/dist/functions/index.d.ts +33 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/geometry/index.d.ts +58 -0
- package/dist/geometry/index.d.ts.map +1 -0
- package/dist/html/index.d.ts +31 -0
- package/dist/html/index.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +37 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/interval/index.d.ts +13 -0
- package/dist/interval/index.d.ts.map +1 -0
- package/dist/json/index.d.ts +28 -0
- package/dist/json/index.d.ts.map +1 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.d.ts.map +1 -0
- package/dist/logger/logger.d.ts +3 -0
- package/dist/logger/logger.d.ts.map +1 -0
- package/dist/logging/index.d.ts +29 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +1 -1
- package/dist/maps/index.d.ts +32 -0
- package/dist/maps/index.d.ts.map +1 -0
- package/dist/math/index.d.ts +37 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +1 -1
- package/dist/mime-types/db.d.ts +4605 -0
- package/dist/mime-types/db.d.ts.map +1 -0
- package/dist/mime-types/index.d.ts +25 -0
- package/dist/mime-types/index.d.ts.map +1 -0
- package/dist/node/index.d.ts +52 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/numbers/index.d.ts +82 -0
- package/dist/numbers/index.d.ts.map +1 -0
- package/dist/objects/index.d.ts +35 -0
- package/dist/objects/index.d.ts.map +1 -0
- package/dist/os/index.d.ts +26 -0
- package/dist/os/index.d.ts.map +1 -0
- package/dist/process/index.d.ts +31 -0
- package/dist/process/index.d.ts.map +1 -0
- package/dist/promises/index.d.ts +39 -0
- package/dist/promises/index.d.ts.map +1 -0
- package/dist/random/index.d.ts +33 -0
- package/dist/random/index.d.ts.map +1 -0
- package/dist/regex/index.d.ts +36 -0
- package/dist/regex/index.d.ts.map +1 -0
- package/dist/security/index.d.ts +14 -0
- package/dist/security/index.d.ts.map +1 -0
- package/dist/sets/index.d.ts +48 -0
- package/dist/sets/index.d.ts.map +1 -0
- package/dist/sleep/index.d.ts +27 -0
- package/dist/sleep/index.d.ts.map +1 -0
- package/dist/strings/index.d.ts +296 -0
- package/dist/strings/index.d.ts.map +1 -0
- package/dist/system/index.d.ts +36 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/time/index.d.ts +36 -0
- package/dist/time/index.d.ts.map +1 -0
- package/dist/try/attempt.d.ts +8 -0
- package/dist/try/attempt.d.ts.map +1 -0
- package/dist/try/index.d.ts +2 -0
- package/dist/try/index.d.ts.map +1 -0
- package/dist/try/trycatch.d.ts +12 -0
- package/dist/try/trycatch.d.ts.map +1 -0
- package/dist/types/common/index.d.ts +9 -0
- package/dist/types/env.d.ts +5 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/url/index.d.ts +40 -0
- package/dist/url/index.d.ts.map +1 -0
- package/dist/uuid/index.d.ts +99 -0
- package/dist/uuid/index.d.ts.map +1 -0
- package/dist/validation/index.d.ts +49 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +1 -1
- package/package.json +3 -16
- package/dist/chunks/chunk-DCFILRIS.js +0 -1
- package/dist/math/math.js +0 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the currency symbol for a given ISO 4217 currency code.
|
|
3
|
+
*
|
|
4
|
+
* Utilizes the `Intl.NumberFormat` API to format a number as currency and extract the symbol.
|
|
5
|
+
*
|
|
6
|
+
* @param currency - The ISO 4217 currency code (e.g., 'USD', 'EUR', 'JPY').
|
|
7
|
+
* @returns The currency symbol as a string (e.g., '$', '€', '¥'), or `undefined` if the symbol cannot be determined.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* getCurrencySymbol('USD') // '$'
|
|
12
|
+
* getCurrencySymbol('EUR') // '€'
|
|
13
|
+
* getCurrencySymbol('JPY') // '¥'
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const getCurrencySymbol: (currency: string) => string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the full display name of a currency.
|
|
19
|
+
*
|
|
20
|
+
* @param currency - The ISO 4217 currency code (e.g., 'USD', 'EUR').
|
|
21
|
+
* @param locale - The locale to use for the display name. Defaults to 'en'.
|
|
22
|
+
* @returns The full currency name (e.g., 'US Dollar'), or `undefined` if invalid.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* getCurrencyName('USD') // 'US Dollar'
|
|
27
|
+
* getCurrencyName('EUR') // 'Euro'
|
|
28
|
+
* getCurrencyName('JPY', 'ja') // '日本円'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function getCurrencyName(currency: string, locale?: string): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the default locale typically associated with a currency.
|
|
34
|
+
*
|
|
35
|
+
* @param currency - The ISO 4217 currency code.
|
|
36
|
+
* @returns The locale string (e.g., 'en-US' for USD), or 'en' as fallback.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* getCurrencyLocale('USD') // 'en-US'
|
|
41
|
+
* getCurrencyLocale('EUR') // 'de-DE'
|
|
42
|
+
* getCurrencyLocale('JPY') // 'ja-JP'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function getCurrencyLocale(currency: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Formats a given price value into a localized currency string.
|
|
48
|
+
*
|
|
49
|
+
* @param price - The numeric value or string representation of the price to format.
|
|
50
|
+
* @param currency - The ISO 4217 currency code. Defaults to 'USD'.
|
|
51
|
+
* @param locale - The locale to use for formatting. If not provided, uses the currency's default locale.
|
|
52
|
+
* @returns The formatted currency string.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* formatPrice(1234.56, 'USD') // '$1,234.56'
|
|
57
|
+
* formatPrice(1234.56, 'EUR') // '1.234,56 €'
|
|
58
|
+
* formatPrice(1234.56, 'JPY') // '¥1,235'
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function formatPrice(price: number | string, currency?: string, locale?: string): string;
|
|
62
|
+
/**
|
|
63
|
+
* Formats a price in compact notation (e.g., $1.2K, $1.5M).
|
|
64
|
+
*
|
|
65
|
+
* @param price - The numeric value to format.
|
|
66
|
+
* @param currency - The ISO 4217 currency code. Defaults to 'USD'.
|
|
67
|
+
* @param locale - The locale to use for formatting.
|
|
68
|
+
* @returns The formatted compact currency string.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* formatPriceCompact(1234) // '$1.2K'
|
|
73
|
+
* formatPriceCompact(1234567) // '$1.2M'
|
|
74
|
+
* formatPriceCompact(1234567890) // '$1.2B'
|
|
75
|
+
* formatPriceCompact(1500, 'EUR') // '1,5 Tsd. €'
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatPriceCompact(price: number | string, currency?: string, locale?: string): string;
|
|
79
|
+
/**
|
|
80
|
+
* Parses a given price string and returns its numeric value.
|
|
81
|
+
*
|
|
82
|
+
* @param value - The price string to parse.
|
|
83
|
+
* @returns The numeric value of the price, or `null` if the value cannot be parsed.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* parsePrice('$1,234.56') // 1234.56
|
|
88
|
+
* parsePrice('€1.234,56') // 1234.56
|
|
89
|
+
* parsePrice('invalid') // null
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function parsePrice(value: string): number | null;
|
|
93
|
+
/**
|
|
94
|
+
* Parses a currency string and extracts both the amount and currency code.
|
|
95
|
+
*
|
|
96
|
+
* @param value - The currency string to parse (e.g., '$1,234.56', 'EUR 100').
|
|
97
|
+
* @returns An object with `amount` and `currency`, or `null` if parsing fails.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* parseCurrencyString('$1,234.56') // { amount: 1234.56, currency: 'USD' }
|
|
102
|
+
* parseCurrencyString('€100') // { amount: 100, currency: 'EUR' }
|
|
103
|
+
* parseCurrencyString('1000 JPY') // { amount: 1000, currency: 'JPY' }
|
|
104
|
+
* parseCurrencyString('invalid') // null
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
export declare function parseCurrencyString(value: string): {
|
|
108
|
+
amount: number;
|
|
109
|
+
currency: string;
|
|
110
|
+
} | null;
|
|
111
|
+
/**
|
|
112
|
+
* Converts a given amount from one currency to another using the provided exchange rate.
|
|
113
|
+
*
|
|
114
|
+
* @param amount - The amount of money to convert.
|
|
115
|
+
* @param rate - The exchange rate to use for the conversion.
|
|
116
|
+
* @param decimals - The number of decimal places to include in the result. Defaults to 2.
|
|
117
|
+
* @returns The converted amount as a number.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* convertCurrency(100, 0.85) // 85 (e.g., USD to EUR)
|
|
122
|
+
* convertCurrency(100, 110.5, 0) // 11050 (e.g., USD to JPY)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function convertCurrency(amount: number, rate: number, decimals?: number): number;
|
|
126
|
+
/**
|
|
127
|
+
* Checks if the provided currency code is valid.
|
|
128
|
+
*
|
|
129
|
+
* This function lazily loads the currencies list to minimize bundle size impact.
|
|
130
|
+
*
|
|
131
|
+
* @param code - The currency code to validate (e.g., 'USD', 'eur').
|
|
132
|
+
* @returns Promise resolving to `true` if the currency code is valid; otherwise, `false`.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* await isValidCurrencyCode('USD') // true
|
|
137
|
+
* await isValidCurrencyCode('INVALID') // false
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function isValidCurrencyCode(code: string): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* Synchronously checks if a currency code is valid using the Intl API.
|
|
143
|
+
*
|
|
144
|
+
* This does not require loading the currencies list and has zero bundle size impact.
|
|
145
|
+
*
|
|
146
|
+
* @param code - The currency code to validate.
|
|
147
|
+
* @returns `true` if the currency code is valid; otherwise, `false`.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* isValidCurrency('USD') // true
|
|
152
|
+
* isValidCurrency('INVALID') // false
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
export declare function isValidCurrency(code: string): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Rounds a given number to a specified number of decimal places.
|
|
158
|
+
*
|
|
159
|
+
* @param value - The number to be rounded.
|
|
160
|
+
* @param decimals - The number of decimal places to round to. Defaults to 2.
|
|
161
|
+
* @returns The rounded number.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* roundTo(3.14159, 2) // 3.14
|
|
166
|
+
* roundTo(10.5, 0) // 11
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function roundTo(value: number, decimals?: number): number;
|
|
170
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/currency/index.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,KAAG,MAAM,GAAG,SAY7D,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAO,GAAG,MAAM,GAAG,SAAS,CAMnF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAkC1D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,SAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7F;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,QAAQ,SAAQ,EAChB,MAAM,CAAC,EAAE,MAAM,GACb,MAAM,CAQR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAavD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA2C9F;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAElF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGxE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOrD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAG3D"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns today's date as a YYYY-MM-DD string.
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
export declare function today(): string;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a Date object from a YYYY-MM-DD string.
|
|
8
|
+
* @param dateStr The date string.
|
|
9
|
+
* @returns {Date}
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseDate(dateStr: string): Date;
|
|
12
|
+
/**
|
|
13
|
+
* Formats a Date object as YYYY-MM-DD.
|
|
14
|
+
* @param date The Date object.
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatDate(date: Date): string;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the difference in days between two dates (date2 - date1).
|
|
20
|
+
* @param date1 The first date (string or Date).
|
|
21
|
+
* @param date2 The second date (string or Date).
|
|
22
|
+
* @returns {number}
|
|
23
|
+
*/
|
|
24
|
+
export declare function daysBetween(date1: string | Date, date2: string | Date): number;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if a year is a leap year.
|
|
27
|
+
* @param year The year (number or Date).
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
30
|
+
export declare function isLeapYear(year: number | Date): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Adds days to a date and returns a new Date object.
|
|
33
|
+
* @param date The date (string or Date).
|
|
34
|
+
* @param days Number of days to add.
|
|
35
|
+
* @returns {Date}
|
|
36
|
+
*/
|
|
37
|
+
export declare function addDays(date: string | Date, days: number): Date;
|
|
38
|
+
/**
|
|
39
|
+
* Returns the day of the week for a date (0=Sunday, 6=Saturday).
|
|
40
|
+
* @param date The date (string or Date).
|
|
41
|
+
* @returns {number}
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDayOfWeek(date: string | Date): number;
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAG9B;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAI9E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAGvD;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI/D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAGxD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the current date and time as an ISO string (YYYY-MM-DDTHH:mm:ss.sssZ).
|
|
3
|
+
*/
|
|
4
|
+
export declare function nowIso(): string;
|
|
5
|
+
/**
|
|
6
|
+
* Parses an ISO date-time string to a Date object. Returns null if invalid.
|
|
7
|
+
* @param iso The ISO string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseIsoDateTime(iso: string): Date | null;
|
|
10
|
+
/**
|
|
11
|
+
* Formats a Date as YYYY-MM-DD HH:mm:ss (local time).
|
|
12
|
+
* @param date The Date object.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatDateTimeLocal(date: Date): string;
|
|
15
|
+
/**
|
|
16
|
+
* Returns the timezone offset in minutes for a given date (local - UTC).
|
|
17
|
+
* @param date The Date object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTimezoneOffset(date?: Date): number;
|
|
20
|
+
/**
|
|
21
|
+
* Returns the UTC equivalent of a local Date.
|
|
22
|
+
* @param date The local Date object.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toUtcDate(date: Date): Date;
|
|
25
|
+
/**
|
|
26
|
+
* Returns the number of seconds since the Unix epoch (UTC).
|
|
27
|
+
*/
|
|
28
|
+
export declare function unixTimestamp(): number;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the number of milliseconds since the Unix epoch.
|
|
31
|
+
*/
|
|
32
|
+
export declare function unixMillis(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the difference in seconds between two Date objects.
|
|
35
|
+
* @param a First date.
|
|
36
|
+
* @param b Second date.
|
|
37
|
+
*/
|
|
38
|
+
export declare function secondsBetween(a: Date, b: Date): number;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the ISO week number (1–53) of a given date using UTC.
|
|
41
|
+
* @param date A JavaScript Date object.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getIsoWeek(date: Date): number;
|
|
44
|
+
/**
|
|
45
|
+
* Returns ISO week number and ISO week year (which may differ from calendar year).
|
|
46
|
+
* @param date Date object (UTC-safe)
|
|
47
|
+
*/
|
|
48
|
+
export declare function getIsoWeekInfo(date: Date): {
|
|
49
|
+
week: number;
|
|
50
|
+
year: number;
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datetime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAGzD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAMtD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,IAAiB,GAAG,MAAM,CAEjE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAY1C;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAEnC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,MAAM,CAEvD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAoB7C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAmBzE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the domain part of the given email is present in a list of forbidden domains.
|
|
3
|
+
*
|
|
4
|
+
* @param email - The email address to check.
|
|
5
|
+
* @param forbiddenEmails - A newline-separated string of forbidden email domains.
|
|
6
|
+
* @throws Will throw an error if the email is not formatted properly or if the domain is forbidden.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isEmailinBannedDomains: (email: string, forbiddenEmails: string) => void;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/emails/banned/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,EAAE,iBAAiB,MAAM,SAW5E,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates if a string is a valid email address (simple regex).
|
|
3
|
+
* @param email The email address to validate.
|
|
4
|
+
* @returns True if valid, false otherwise.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isValidEmail(email: string): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes an email address by trimming and converting to lowercase.
|
|
9
|
+
* @param email The email address to normalize.
|
|
10
|
+
* @returns The normalized email address.
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeEmail(email: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Masks an email address for privacy (e.g., j***@domain.com).
|
|
15
|
+
* @param email The email address to mask.
|
|
16
|
+
* @returns The masked email address.
|
|
17
|
+
*/
|
|
18
|
+
export declare function maskEmail(email: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Extracts the domain from an email address.
|
|
21
|
+
* @param email The email address.
|
|
22
|
+
* @returns The domain part of the email, or an empty string if invalid.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getEmailDomain(email: string): string;
|
|
25
|
+
export declare function isFreeEmailProvider(email: string): boolean;
|
|
26
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/emails/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGpD;AAiBD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the value of an environment variable by its key.
|
|
4
|
+
*
|
|
5
|
+
* @param key - The name of the environment variable to retrieve.
|
|
6
|
+
* @param defaultValue - An optional default value to return if the environment variable is not defined.
|
|
7
|
+
* @returns The value of the environment variable if it exists, otherwise the default value if provided.
|
|
8
|
+
* @throws {Error} If the environment variable is undefined and no default value is provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare const getENV: (key: string, defaultValue?: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Determines if the current environment is set to development.
|
|
13
|
+
*
|
|
14
|
+
* @returns {boolean} `true` if `process.env.NODE_ENV` is `'development'`, otherwise `false`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isDev: () => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Determines if the current environment is set to production.
|
|
19
|
+
*
|
|
20
|
+
* @returns {boolean} `true` if `process.env.NODE_ENV` is `'production'`, otherwise `false`.
|
|
21
|
+
*/
|
|
22
|
+
export declare const isProd: () => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Determines if the current environment is set to test.
|
|
25
|
+
*
|
|
26
|
+
* @returns {boolean} `true` if `process.env.NODE_ENV` is `'test'`, otherwise `false`.
|
|
27
|
+
*/
|
|
28
|
+
export declare const isTest: () => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the current NODE_ENV value, or 'development' if not set.
|
|
31
|
+
*
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
export declare const getNodeEnv: () => string;
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* Validates the environment variables against a Zod schema.
|
|
38
|
+
* Throws an error if any required variables are missing or invalid.
|
|
39
|
+
* @param {z.ZodObject<T>} EnvSchema - The Zod schema to validate against.
|
|
40
|
+
* @param {Record<string, string | undefined>} buildEnv - The environment variables to validate, defaults to `process.env`.
|
|
41
|
+
* @throws {Error} If validation fails, an error with a message listing missing variables is thrown.
|
|
42
|
+
*/
|
|
43
|
+
export declare function checkEnv<T extends z.ZodRawShape>(EnvSchema: z.ZodObject<T>, buildEnv?: Record<string, string | undefined>): z.core.$InferObjectOutput<T, {}>;
|
|
44
|
+
/**
|
|
45
|
+
* Schema for validating the root environment variables.
|
|
46
|
+
* It includes NODE_ENV, LOG_LEVEL, and PORT with their respective types and defaults.
|
|
47
|
+
*/
|
|
48
|
+
export declare const RootApiEnvSchema: z.ZodObject<{
|
|
49
|
+
NODE_ENV: z.ZodDefault<z.ZodEnum<{
|
|
50
|
+
development: "development";
|
|
51
|
+
production: "production";
|
|
52
|
+
test: "test";
|
|
53
|
+
}>>;
|
|
54
|
+
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
55
|
+
debug: "debug";
|
|
56
|
+
info: "info";
|
|
57
|
+
warn: "warn";
|
|
58
|
+
error: "error";
|
|
59
|
+
}>>;
|
|
60
|
+
PORT: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
export type RootApiEnvSchema = z.infer<typeof RootApiEnvSchema>;
|
|
63
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,EAAE,eAAe,MAAM,WAUxD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,KAAK,QAAO,OAExB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAO,OAEzB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,QAAO,OAEzB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAC/C,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EACzB,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,oCAc1D;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;iBAI3B,CAAA;AAEF,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAA"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new Error with a custom name and message.
|
|
3
|
+
* @param name The error name.
|
|
4
|
+
* @param message The error message.
|
|
5
|
+
* @returns The custom Error object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCustomError(name: string, message: string): Error;
|
|
8
|
+
/**
|
|
9
|
+
* Checks if an error is an instance of a specific error name.
|
|
10
|
+
* @param error The error to check.
|
|
11
|
+
* @param name The error name to match.
|
|
12
|
+
* @returns True if the error matches the name, false otherwise.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isErrorName(error: unknown, name: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the error message from an unknown error value.
|
|
17
|
+
* @param error The error value.
|
|
18
|
+
* @returns The error message, or a stringified version if not an Error.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
21
|
+
/**
|
|
22
|
+
* Throws an error if the condition is false.
|
|
23
|
+
* @param condition The condition to check.
|
|
24
|
+
* @param message The error message to throw if the condition is false.
|
|
25
|
+
*/
|
|
26
|
+
export declare function assert(condition: unknown, message: string): asserts condition;
|
|
27
|
+
/**
|
|
28
|
+
* Wraps a function and catches errors, returning a fallback value if an error occurs.
|
|
29
|
+
* Use this only when the fallback is genuinely safe and the error can be ignored.
|
|
30
|
+
* For typed error handling, prefer `tryCatch` from `@rtorcato/js-common/try`.
|
|
31
|
+
* @param fn The function to wrap.
|
|
32
|
+
* @param fallback The fallback value to return on error.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const result = await tryWithFallback(async () => fetchData(), [])
|
|
36
|
+
* // result will be [] if fetchData throws
|
|
37
|
+
*/
|
|
38
|
+
export declare function tryWithFallback<T>(fn: () => Promise<T> | T, fallback: T): Promise<T>;
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAItE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQtD;AAED;;;;GAIG;AAEH,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAI7E;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAM1F"}
|
package/dist/errors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function e(n,r){let t=new Error(r);return t.name=n,t}function o(n,r){return n instanceof Error&&n.name===r}function i(n){if(n instanceof Error)return n.message;if(typeof n=="string")return n;try{return JSON.stringify(n)}catch{return String(n)}}function s(n,r){if(!n)throw new Error(r)}async function a(n,r){try{return await n()}catch{return r}}export{s as assert,e as createCustomError,i as getErrorMessage,o as isErrorName,a as tryWithFallback};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds an event listener and returns a function to remove it.
|
|
3
|
+
* @param target The event target.
|
|
4
|
+
* @param type The event type.
|
|
5
|
+
* @param handler The event handler.
|
|
6
|
+
* @param options Event listener options.
|
|
7
|
+
* @returns {() => void} Unsubscribe function.
|
|
8
|
+
*/
|
|
9
|
+
export declare function on<K extends keyof HTMLElementEventMap>(target: EventTarget, type: K, handler: (event: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Dispatches a custom event on the target.
|
|
12
|
+
* @param target The event target.
|
|
13
|
+
* @param type The event type.
|
|
14
|
+
* @param detail Optional detail data.
|
|
15
|
+
* @returns {boolean} True if not canceled.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emit(target: EventTarget, type: string, detail?: unknown): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Waits for a single event to occur and resolves a promise.
|
|
20
|
+
* @param target The event target.
|
|
21
|
+
* @param type The event type.
|
|
22
|
+
* @returns {Promise<Event>} Resolves with the event object.
|
|
23
|
+
*/
|
|
24
|
+
export declare function once<K extends keyof HTMLElementEventMap>(target: EventTarget, type: K): Promise<HTMLElementEventMap[K]>;
|
|
25
|
+
/**
|
|
26
|
+
* Prevents the default action for an event.
|
|
27
|
+
* @param event The event object.
|
|
28
|
+
*/
|
|
29
|
+
export declare function preventDefault(event: Event): void;
|
|
30
|
+
/**
|
|
31
|
+
* Stops propagation for an event.
|
|
32
|
+
* @param event The event object.
|
|
33
|
+
*/
|
|
34
|
+
export declare function stopPropagation(event: Event): void;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,EAAE,CAAC,CAAC,SAAS,MAAM,mBAAmB,EACrD,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,IAAI,EAChD,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GACzC,MAAM,IAAI,CAGZ;AAED;;;;;;GAMG;AAEH,wBAAgB,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,MAAM,mBAAmB,EACvD,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,CAAC,GACL,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAQjC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAEjD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAElD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetches a resource with a timeout.
|
|
3
|
+
* @param url The URL to fetch.
|
|
4
|
+
* @param options Fetch options.
|
|
5
|
+
* @param timeout Timeout in milliseconds (default: 8000).
|
|
6
|
+
* @returns The parsed JSON response.
|
|
7
|
+
*/
|
|
8
|
+
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeout?: number): Promise<unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* Sends a POST request with a JSON body.
|
|
11
|
+
* @param url The URL to post to.
|
|
12
|
+
* @param body The body to send.
|
|
13
|
+
* @param options Additional fetch options.
|
|
14
|
+
* @returns The parsed JSON response.
|
|
15
|
+
*/
|
|
16
|
+
export declare function postJson<T = unknown, R = unknown>(url: string, body: T, options?: RequestInit): Promise<R>;
|
|
17
|
+
/**
|
|
18
|
+
* Sends a GET request and returns JSON.
|
|
19
|
+
* @param url The URL to fetch.
|
|
20
|
+
* @param options Additional fetch options.
|
|
21
|
+
* @returns The parsed JSON response.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getJson<T = unknown>(url: string, options?: RequestInit): Promise<T>;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches a resource and returns the response as text.
|
|
26
|
+
* @param url The URL to fetch.
|
|
27
|
+
* @param options Fetch options.
|
|
28
|
+
* @returns The response as text.
|
|
29
|
+
*/
|
|
30
|
+
export declare function fetchText(url: string, options?: RequestInit): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Handles fetch errors and returns a fallback value or throws.
|
|
33
|
+
* @param promise The fetch promise.
|
|
34
|
+
* @param fallback The fallback value to return on error.
|
|
35
|
+
* @returns The resolved value or the fallback.
|
|
36
|
+
*/
|
|
37
|
+
export declare function handleApiError<T>(promise: Promise<T>, fallback?: T): Promise<T>;
|
|
38
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,OAAO,SAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,OAAO,EACtD,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,EACP,OAAO,GAAE,WAAgB,GACvB,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,CAG7F;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAGvF;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAOrF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a file as a string (UTF-8).
|
|
3
|
+
* @param {string} filePath - The path to the file.
|
|
4
|
+
* @returns {Promise<string>} The file contents as a string.
|
|
5
|
+
*/
|
|
6
|
+
export declare function readFileAsString(filePath: string): Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* Writes a string to a file (UTF-8).
|
|
9
|
+
* @param {string} filePath - The path to the file.
|
|
10
|
+
* @param {string} data - The string data to write.
|
|
11
|
+
* @returns {Promise<void>}
|
|
12
|
+
*/
|
|
13
|
+
export declare function writeFileAsString(filePath: string, data: string): Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Checks if a file exists.
|
|
16
|
+
* @param {string} filePath - The path to the file.
|
|
17
|
+
* @returns {Promise<boolean>} True if the file exists, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare function fileExists(filePath: string): Promise<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Deletes a file.
|
|
22
|
+
* @param {string} filePath - The path to the file.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
export declare function deleteFile(filePath: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the file extension from a file path.
|
|
28
|
+
* @param {string} filePath - The path to the file.
|
|
29
|
+
* @returns {string} The file extension (including the dot), or an empty string if none.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getFileExtension(filePath: string): string;
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAExE;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnE;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEhE;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pads a string or number with leading zeros to a given length.
|
|
3
|
+
* @param value The value to pad.
|
|
4
|
+
* @param length The desired length.
|
|
5
|
+
* @returns The padded string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function padZero(value: string | number, length?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Formats a number with thousands separators.
|
|
10
|
+
* @param num The number to format.
|
|
11
|
+
* @param locale Optional locale string (default: 'en-US').
|
|
12
|
+
* @returns The formatted string.
|
|
13
|
+
*/
|
|
14
|
+
export declare function formatNumber(num: number, locale?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Formats a number as a percentage string.
|
|
17
|
+
* @param value The value to format (e.g. 0.25 for 25%).
|
|
18
|
+
* @param fractionDigits Number of decimal places (default: 0).
|
|
19
|
+
* @returns The formatted percentage string.
|
|
20
|
+
*/
|
|
21
|
+
export declare function formatPercent(value: number, fractionDigits?: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* Formats a Date as YYYY-MM-DD.
|
|
24
|
+
* @param date The date to format.
|
|
25
|
+
* @returns The formatted date string.
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatDate(date: Date): string;
|
|
28
|
+
/**
|
|
29
|
+
* Formats a Date as HH:MM:SS.
|
|
30
|
+
* @param date The date to format.
|
|
31
|
+
* @returns The formatted time string.
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatTime(date: Date): string;
|
|
34
|
+
/**
|
|
35
|
+
* Formats a Date as YYYY-MM-DD HH:MM:SS.
|
|
36
|
+
* @param date The date to format.
|
|
37
|
+
* @returns The formatted date-time string.
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatDateTime(date: Date): string;
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatting/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAE1E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,SAAI,GAAG,MAAM,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAEjD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a function that only calls the original function once.
|
|
3
|
+
* @param fn The function to wrap.
|
|
4
|
+
* @returns {Function}
|
|
5
|
+
*/
|
|
6
|
+
export declare function once<T extends (...args: any[]) => any>(fn: T): T;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a debounced version of a function.
|
|
9
|
+
* @param fn The function to debounce.
|
|
10
|
+
* @param wait Milliseconds to wait.
|
|
11
|
+
* @returns {Function}
|
|
12
|
+
*/
|
|
13
|
+
export declare function debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a throttled version of a function.
|
|
16
|
+
* @param fn The function to throttle.
|
|
17
|
+
* @param wait Milliseconds to wait between calls.
|
|
18
|
+
* @returns {Function}
|
|
19
|
+
*/
|
|
20
|
+
export declare function throttle<T extends (...args: any[]) => void>(fn: T, wait: number): T;
|
|
21
|
+
/**
|
|
22
|
+
* Composes functions from right to left.
|
|
23
|
+
* @param fns Functions to compose.
|
|
24
|
+
* @returns {Function}
|
|
25
|
+
*/
|
|
26
|
+
export declare function compose<T>(...fns: Array<(arg: T) => T>): (arg: T) => T;
|
|
27
|
+
/**
|
|
28
|
+
* Pipes functions from left to right.
|
|
29
|
+
* @param fns Functions to pipe.
|
|
30
|
+
* @returns {Function}
|
|
31
|
+
*/
|
|
32
|
+
export declare function pipe<T>(...fns: Array<(arg: T) => T>): (arg: T) => T;
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAUhE;AAED;;;;;GAKG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CAMnF;AAED;;;;;GAKG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,CASnF;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAEtE;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAEnE"}
|