@rtorcato/js-common 2.8.2 → 4.0.0
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/AGENTS.md +114 -0
- package/CHANGELOG.md +23 -0
- package/CONTRIBUTORS.md +5 -0
- package/README.md +75 -26
- package/dist/abortController/index.d.ts +30 -0
- package/dist/abortController/index.d.ts.map +1 -1
- package/dist/arrays/arrays.test-d.js +1 -1
- package/dist/arrays/index.d.ts +0 -63
- package/dist/arrays/index.d.ts.map +1 -1
- package/dist/arrays/index.js +1 -1
- package/dist/boolean/index.d.ts +10 -33
- package/dist/boolean/index.d.ts.map +1 -1
- package/dist/boolean/index.js +1 -1
- package/dist/chunks/chunk-AVPQVYSA.js +1 -0
- package/dist/chunks/chunk-H7PB4TAW.js +1 -0
- package/dist/chunks/chunk-HUTZTT4Y.js +1 -0
- package/dist/chunks/chunk-RBXTRLWB.js +1 -0
- package/dist/chunks/chunk-UQBVI52L.js +1 -0
- package/dist/cli/catalog.js +131 -0
- package/dist/cli/cli.mjs +16 -109
- package/dist/colors/index.d.ts +23 -3
- package/dist/colors/index.d.ts.map +1 -1
- package/dist/console/index.d.ts +12 -0
- package/dist/console/index.d.ts.map +1 -1
- package/dist/crypto/index.d.ts +23 -0
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/currency/currencies.d.ts +1 -1
- package/dist/currency/currencies.d.ts.map +1 -1
- package/dist/currency/currencies.js +1 -1
- package/dist/currency/index.d.ts +0 -14
- package/dist/currency/index.d.ts.map +1 -1
- package/dist/currency/index.js +1 -1
- package/dist/date/index.d.ts +16 -0
- package/dist/date/index.d.ts.map +1 -1
- package/dist/datetime/index.d.ts +21 -9
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js +1 -1
- package/dist/emails/index.d.ts +22 -0
- package/dist/emails/index.d.ts.map +1 -1
- package/dist/emails/index.js +1 -1
- package/dist/env/index.d.ts +24 -0
- package/dist/env/index.d.ts.map +1 -1
- package/dist/errors/index.d.ts +30 -2
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/events/index.d.ts +25 -1
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/fetch/index.d.ts +25 -0
- package/dist/fetch/index.d.ts.map +1 -1
- package/dist/file/index.d.ts +20 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/functions/functions.test-d.d.ts +2 -0
- package/dist/functions/functions.test-d.d.ts.map +1 -0
- package/dist/functions/functions.test-d.js +1 -0
- package/dist/functions/index.d.ts +32 -2
- package/dist/functions/index.d.ts.map +1 -1
- package/dist/functions/index.js +1 -1
- package/dist/geometry/index.d.ts +21 -0
- package/dist/geometry/index.d.ts.map +1 -1
- package/dist/html/index.d.ts +38 -0
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +1 -1
- package/dist/i18n/index.d.ts +23 -7
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/json/index.d.ts +27 -7
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +1 -1
- package/dist/logger/index.d.ts +16 -1
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/logging/index.d.ts +19 -0
- package/dist/logging/index.d.ts.map +1 -1
- package/dist/maps/index.d.ts +21 -0
- package/dist/maps/index.d.ts.map +1 -1
- package/dist/mime-types/db.d.ts +5 -922
- package/dist/mime-types/db.d.ts.map +1 -1
- package/dist/mime-types/db.js +1 -1
- package/dist/mime-types/index.d.ts +20 -0
- package/dist/mime-types/index.d.ts.map +1 -1
- package/dist/mime-types/index.js +1 -1
- package/dist/node/index.d.ts +0 -9
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/numbers/index.d.ts +28 -36
- package/dist/numbers/index.d.ts.map +1 -1
- package/dist/numbers/index.js +1 -1
- package/dist/objects/index.d.ts +23 -7
- package/dist/objects/index.d.ts.map +1 -1
- package/dist/objects/index.js +1 -1
- package/dist/objects/objects.test-d.js +1 -1
- package/dist/os/index.d.ts +18 -0
- package/dist/os/index.d.ts.map +1 -1
- package/dist/process/index.d.ts +18 -0
- package/dist/process/index.d.ts.map +1 -1
- package/dist/promises/index.d.ts +21 -26
- package/dist/promises/index.d.ts.map +1 -1
- package/dist/promises/index.js +1 -1
- package/dist/promises/promises.test-d.d.ts +2 -0
- package/dist/promises/promises.test-d.d.ts.map +1 -0
- package/dist/promises/promises.test-d.js +1 -0
- package/dist/random/index.d.ts +21 -0
- package/dist/random/index.d.ts.map +1 -1
- package/dist/regex/index.d.ts +23 -0
- package/dist/regex/index.d.ts.map +1 -1
- package/dist/security/index.d.ts +36 -4
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js +1 -1
- package/dist/sleep/index.d.ts +20 -0
- package/dist/sleep/index.d.ts.map +1 -1
- package/dist/strings/index.d.ts +0 -75
- package/dist/strings/index.d.ts.map +1 -1
- package/dist/strings/index.js +1 -1
- package/dist/system/index.d.ts +18 -0
- package/dist/system/index.d.ts.map +1 -1
- package/dist/time/index.d.ts +23 -4
- package/dist/time/index.d.ts.map +1 -1
- package/dist/try/index.d.ts +52 -1
- package/dist/try/index.d.ts.map +1 -1
- package/dist/try/index.js +1 -1
- package/dist/try/trycatch.test-d.js +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/url/index.d.ts +23 -0
- package/dist/url/index.d.ts.map +1 -1
- package/dist/url/index.js +1 -1
- package/dist/uuid/index.d.ts +5 -5
- package/dist/uuid/index.d.ts.map +1 -1
- package/dist/uuid/index.js +1 -1
- package/dist/validation/index.d.ts +25 -0
- package/dist/validation/index.d.ts.map +1 -1
- package/dist/validation/index.js +1 -1
- package/package.json +23 -37
- package/dist/chunks/chunk-5IA77ERW.js +0 -1
- package/dist/chunks/chunk-6J7HIWG6.js +0 -1
- package/dist/chunks/chunk-ARW46OJS.js +0 -1
- package/dist/chunks/chunk-W72HFHZY.js +0 -1
- package/dist/emails/banned/index.d.ts +0 -9
- package/dist/emails/banned/index.d.ts.map +0 -1
- package/dist/formatting/index.d.ts +0 -40
- package/dist/formatting/index.d.ts.map +0 -1
- package/dist/formatting/index.js +0 -1
- package/dist/interval/index.d.ts +0 -13
- package/dist/interval/index.d.ts.map +0 -1
- package/dist/interval/index.js +0 -1
- package/dist/logger/logger.d.ts +0 -7
- package/dist/logger/logger.d.ts.map +0 -1
- package/dist/logger/logger.js +0 -1
- package/dist/math/index.d.ts +0 -37
- package/dist/math/index.d.ts.map +0 -1
- package/dist/math/index.js +0 -1
- package/dist/sets/index.d.ts +0 -48
- package/dist/sets/index.d.ts.map +0 -1
- package/dist/sets/index.js +0 -1
- package/dist/try/attempt.d.ts +0 -8
- package/dist/try/attempt.d.ts.map +0 -1
- package/dist/try/attempt.js +0 -1
- package/dist/try/trycatch.d.ts +0 -29
- package/dist/try/trycatch.d.ts.map +0 -1
- package/dist/try/trycatch.js +0 -1
- /package/dist/chunks/{chunk-XAQ7VMV4.js → chunk-J4C2KNK5.js} +0 -0
package/dist/crypto/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hashes a string using the specified algorithm.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* hashString('hello')
|
|
7
|
+
* // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
|
|
8
|
+
* hashString('hello', 'md5') // '5d41402abc4b2a76b9719d911017c592'
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
3
11
|
* @param str The string to hash.
|
|
4
12
|
* @param algorithm The hash algorithm (default: 'sha256').
|
|
5
13
|
* @returns The hex-encoded hash.
|
|
@@ -7,12 +15,27 @@
|
|
|
7
15
|
export declare function hashString(str: string, algorithm?: string): string;
|
|
8
16
|
/**
|
|
9
17
|
* Generates a random hex string of the specified length (in bytes).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* randomHex(4) // '9f3c1ab7' (8 hex chars)
|
|
22
|
+
* randomHex() // 32 hex chars (16 bytes)
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
10
25
|
* @param length The number of bytes (not hex chars).
|
|
11
26
|
* @returns A random hex string.
|
|
12
27
|
*/
|
|
13
28
|
export declare function randomHex(length?: number): string;
|
|
14
29
|
/**
|
|
15
30
|
* Creates an HMAC hash of a string using a secret and algorithm.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* hmacHash('payload', 's3cret')
|
|
35
|
+
* // 'd1d0f5b6...' (64 hex chars, stable for the same input + secret)
|
|
36
|
+
* hmacHash('payload', 's3cret', 'sha1') // 40 hex chars
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
16
39
|
* @param str The string to hash.
|
|
17
40
|
* @param secret The secret key.
|
|
18
41
|
* @param algorithm The hash algorithm (default: 'sha256').
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,SAAW,GAAG,MAAM,CAEpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,MAAM,SAAK,GAAG,MAAM,CAE7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,SAAW,GAAG,MAAM,CAElF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencies.d.ts","sourceRoot":"","sources":["../../src/currency/currencies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,
|
|
1
|
+
{"version":3,"file":"currencies.d.ts","sourceRoot":"","sources":["../../src/currency/currencies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,UAAU,UA4Cf,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";var R=["CAD","USD","AUD","EUR","GBP","JPY","CHF","CNY","NZD","SGD","SEK","NOK","DKK","MXN","HKD","KRW","TRY","RUB","INR","BRL","ZAR","ILS","MYR","PHP","PLN","THB","TWD","CZK","HUF","IDR","BGN","RON","HRK","COP","CRC","XCD","XDR","XAG","XAU","XPT","XPD","XTS","XXX"],D=R;export{
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";var R=["CAD","USD","AUD","EUR","GBP","JPY","CHF","CNY","NZD","SGD","SEK","NOK","DKK","MXN","HKD","KRW","TRY","RUB","INR","BRL","ZAR","ILS","MYR","PHP","PLN","THB","TWD","CZK","HUF","IDR","BGN","RON","HRK","COP","CRC","XCD","XDR","XAG","XAU","XPT","XPD","XTS","XXX"],D=R;export{D as default};
|
package/dist/currency/index.d.ts
CHANGED
|
@@ -153,18 +153,4 @@ export declare function isValidCurrencyCode(code: string): Promise<boolean>;
|
|
|
153
153
|
* ```
|
|
154
154
|
*/
|
|
155
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
156
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +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,
|
|
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,CAevD;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"}
|
package/dist/currency/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";var o=null;async function a(){if(o)return o;let{default:r}=await import("./currencies.js");return o=r,r}var l=r=>{try{let
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";var o=null;async function a(){if(o)return o;let{default:r}=await import("./currencies.js");return o=r,r}var l=r=>{try{let e=new Intl.NumberFormat("en",{currency:r,style:"currency"}).formatToParts(0).find(n=>n.type==="currency");return e?.value==="\xA4"?void 0:e?.value}catch{return}};function m(r,e="en"){try{return new Intl.DisplayNames([e],{type:"currency"}).of(r.toUpperCase())}catch{return}}function i(r){return{USD:"en-US",EUR:"de-DE",GBP:"en-GB",JPY:"ja-JP",CNY:"zh-CN",CAD:"en-CA",AUD:"en-AU",CHF:"de-CH",NZD:"en-NZ",SGD:"en-SG",HKD:"zh-HK",KRW:"ko-KR",INR:"en-IN",BRL:"pt-BR",MXN:"es-MX",RUB:"ru-RU",ZAR:"en-ZA",SEK:"sv-SE",NOK:"nb-NO",DKK:"da-DK",PLN:"pl-PL",TRY:"tr-TR",THB:"th-TH",MYR:"ms-MY",PHP:"en-PH",IDR:"id-ID",CZK:"cs-CZ",HUF:"hu-HU",ILS:"he-IL",TWD:"zh-TW"}[r.toUpperCase()]??"en"}function p(r,e="USD",n){let t=n??i(e);return new Intl.NumberFormat(t,{style:"currency",currency:e}).format(Number(r))}function y(r,e="USD",n){let t=n??i(e);return new Intl.NumberFormat(t,{style:"currency",currency:e,notation:"compact",compactDisplay:"short"}).format(Number(r))}function s(r){let e=/\d\.\d{3},\d{2}$/.test(r),n=r;e&&(n=r.replace(/\./g,"").replace(",","."));let t=n.replace(/[^0-9.-]+/g,""),c=Number.parseFloat(t);return Number.isNaN(c)?null:c}function d(r){let e={$:"USD","\u20AC":"EUR","\xA3":"GBP","\xA5":"JPY","\u20B9":"INR","\u20BD":"RUB",R$:"BRL","\u20A9":"KRW","\u0E3F":"THB","\u20AA":"ILS","\u20B1":"PHP","\u20AB":"VND",kr:"SEK",CHF:"CHF",C$:"CAD",A$:"AUD",NZ$:"NZD",HK$:"HKD",S$:"SGD"},n=r.match(/\b([A-Z]{3})\b/);if(n?.[1]){let t=s(r);if(t!==null)return{amount:t,currency:n[1]}}for(let[t,c]of Object.entries(e))if(r.includes(t)){let u=s(r);if(u!==null)return{amount:u,currency:c}}return null}function f(r,e,n=2){return Number.parseFloat((r*e).toFixed(n))}async function g(r){return(await a()).includes(r.toUpperCase())}function C(r){try{return new Intl.NumberFormat("en",{style:"currency",currency:r}),!0}catch{return!1}}export{f as convertCurrency,p as formatPrice,y as formatPriceCompact,i as getCurrencyLocale,m as getCurrencyName,l as getCurrencySymbol,C as isValidCurrency,g as isValidCurrencyCode,d as parseCurrencyString,s as parsePrice};
|
package/dist/date/index.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns today's date as a YYYY-MM-DD string.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* today() // '2026-08-11'
|
|
7
|
+
* ```
|
|
3
8
|
*/
|
|
4
9
|
export declare function today(): string;
|
|
5
10
|
/**
|
|
6
11
|
* Returns a Date object from a YYYY-MM-DD string (parsed as local time).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* parseDate('2026-08-11') // Date for 2026-08-11 00:00:00 local time
|
|
16
|
+
* parseDate('2026-08-11').getFullYear() // 2026
|
|
17
|
+
* ```
|
|
7
18
|
*/
|
|
8
19
|
export declare function parseDate(dateStr: string): Date;
|
|
9
20
|
/**
|
|
10
21
|
* Formats a Date object as YYYY-MM-DD (UTC).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* formatDate(new Date('2026-08-11T23:30:00Z')) // '2026-08-11'
|
|
26
|
+
* ```
|
|
11
27
|
*/
|
|
12
28
|
export declare function formatDate(date: Date): string;
|
|
13
29
|
/**
|
package/dist/date/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AASA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/date/index.ts"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE9E;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAEhF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAGvD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAI/D;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAE/D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAInE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAExD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAIpD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAIlD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAGtD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAQ7E;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEpD;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAQlF"}
|
package/dist/datetime/index.d.ts
CHANGED
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Returns the current date and time as an ISO string (YYYY-MM-DDTHH:mm:ss.sssZ).
|
|
2
|
+
* Returns the current date and time as an ISO string (`YYYY-MM-DDTHH:mm:ss.sssZ`).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* nowIso() // '2026-08-11T14:03:27.913Z'
|
|
7
|
+
* ```
|
|
3
8
|
*/
|
|
4
9
|
export declare function nowIso(): string;
|
|
5
10
|
/**
|
|
6
11
|
* Parses an ISO date-time string to a Date object. Returns null if invalid.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* parseIsoDateTime('2026-08-11T14:03:27Z')?.getUTCHours() // 14
|
|
16
|
+
* parseIsoDateTime('not-a-date') // null
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
7
19
|
* @param iso The ISO string.
|
|
8
20
|
*/
|
|
9
21
|
export declare function parseIsoDateTime(iso: string): Date | null;
|
|
10
22
|
/**
|
|
11
|
-
* Formats a Date as YYYY-MM-DD HH:mm:ss (local time).
|
|
23
|
+
* Formats a Date as `YYYY-MM-DD HH:mm:ss` (local time).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* formatDateTimeLocal(new Date(2026, 7, 11, 9, 5, 3)) // '2026-08-11 09:05:03'
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
12
30
|
* @param date The Date object.
|
|
13
31
|
*/
|
|
14
32
|
export declare function formatDateTimeLocal(date: Date): string;
|
|
15
33
|
/**
|
|
16
|
-
* Returns the timezone offset in minutes for a given date (local
|
|
34
|
+
* Returns the timezone offset in minutes for a given date (local − UTC).
|
|
17
35
|
* @param date The Date object.
|
|
18
36
|
*/
|
|
19
37
|
export declare function getTimezoneOffset(date?: Date): number;
|
|
@@ -30,12 +48,6 @@ export declare function unixTimestamp(): number;
|
|
|
30
48
|
* Returns the number of milliseconds since the Unix epoch.
|
|
31
49
|
*/
|
|
32
50
|
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
51
|
/**
|
|
40
52
|
* Returns the ISO week number (1–53) of a given date using UTC.
|
|
41
53
|
* @param date A JavaScript Date object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datetime/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/datetime/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAE/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAGzD;AAED;;;;;;;;;GASG;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;;;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"}
|
package/dist/datetime/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function i(){return new Date().toISOString()}function c(e){let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function T(e){let t=n=>n.toString().padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}function l(e=new Date){return e.getTimezoneOffset()}function f(e){return new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}function m(){return Math.floor(Date.now()/1e3)}function
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function i(){return new Date().toISOString()}function c(e){let t=new Date(e);return Number.isNaN(t.getTime())?null:t}function T(e){let t=n=>n.toString().padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`}function l(e=new Date){return e.getTimezoneOffset()}function f(e){return new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()))}function m(){return Math.floor(Date.now()/1e3)}function U(){return Date.now()}function w(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())),n=t.getUTCDay(),s=n===0?7:n;t.setUTCDate(t.getUTCDate()+4-s);let o=new Date(Date.UTC(t.getUTCFullYear(),0,1)).getUTCDay(),a=o===0?7:o,D=new Date(Date.UTC(t.getUTCFullYear(),0,1+(4-a))),u=t.getTime()-D.getTime();return 1+Math.round(u/(10080*60*1e3))}function C(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()));t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let n=t.getUTCFullYear(),r=new Date(Date.UTC(n,0,1)).getUTCDay()||7,o=new Date(Date.UTC(n,0,1-r+1+(r>4?7:0))),a=t.getTime()-o.getTime();return{week:Math.floor(a/(10080*60*1e3))+1,year:n}}export{T as formatDateTimeLocal,w as getIsoWeek,C as getIsoWeekInfo,l as getTimezoneOffset,i as nowIso,c as parseIsoDateTime,f as toUtcDate,U as unixMillis,m as unixTimestamp};
|
package/dist/emails/index.d.ts
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Validates if a string is a valid email address (simple regex).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* isValidEmail('user@example.com') // true
|
|
7
|
+
* isValidEmail('user@example') // false
|
|
8
|
+
* isValidEmail('not an email') // false
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
3
11
|
* @param email The email address to validate.
|
|
4
12
|
* @returns True if valid, false otherwise.
|
|
5
13
|
*/
|
|
6
14
|
export declare function isValidEmail(email: string): boolean;
|
|
7
15
|
/**
|
|
8
16
|
* Normalizes an email address by trimming and converting to lowercase.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* normalizeEmail(' User@Example.COM ') // 'user@example.com'
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
9
23
|
* @param email The email address to normalize.
|
|
10
24
|
* @returns The normalized email address.
|
|
11
25
|
*/
|
|
12
26
|
export declare function normalizeEmail(email: string): string;
|
|
13
27
|
/**
|
|
14
28
|
* Masks an email address for privacy (e.g., j***@domain.com).
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* maskEmail('jane@example.com') // 'j***@example.com'
|
|
33
|
+
* maskEmail('a@example.com') // '*@example.com'
|
|
34
|
+
* maskEmail('nope') // 'nope'
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
15
37
|
* @param email The email address to mask.
|
|
16
38
|
* @returns The masked email address.
|
|
17
39
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/emails/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/emails/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAInD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGpD;AAaD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D"}
|
package/dist/emails/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function e(t){return/^[^\s@]+@[^\s
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function e(t){return/^[^\s@]+@[^\s@.]+(?:\.[^\s@.]+)+$/.test(t)}function s(t){return t.trim().toLowerCase()}function a(t){let[o,r]=t.split("@");return!o||!r?t:o.length<=1?`*@${r}`:`${o[0]}${"*".repeat(Math.max(1,o.length-1))}@${r}`}function n(t){let o=t.split("@");return o.length===2?o[1]??"":""}var i=["gmail.com","yahoo.com","outlook.com","hotmail.com","icloud.com","aol.com","zoho.com","mail.com"];function m(t){return i.includes(n(t))}export{n as getEmailDomain,m as isFreeEmailProvider,e as isValidEmail,a as maskEmail,s as normalizeEmail};
|
package/dist/env/index.d.ts
CHANGED
|
@@ -2,6 +2,14 @@ import { z } from 'zod';
|
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves the value of an environment variable by its key.
|
|
4
4
|
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* process.env.API_URL = 'https://api.example.com'
|
|
8
|
+
* getENV('API_URL') // 'https://api.example.com'
|
|
9
|
+
* getENV('MISSING', 'fallback') // 'fallback'
|
|
10
|
+
* getENV('MISSING') // throws Error: Undefined ENV variable - MISSING
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
5
13
|
* @param key - The name of the environment variable to retrieve.
|
|
6
14
|
* @param defaultValue - An optional default value to return if the environment variable is not defined.
|
|
7
15
|
* @returns The value of the environment variable if it exists, otherwise the default value if provided.
|
|
@@ -11,12 +19,28 @@ export declare const getENV: (key: string, defaultValue?: string) => string;
|
|
|
11
19
|
/**
|
|
12
20
|
* Determines if the current environment is set to development.
|
|
13
21
|
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* process.env.NODE_ENV = 'development'
|
|
25
|
+
* isDev() // true
|
|
26
|
+
* process.env.NODE_ENV = 'production'
|
|
27
|
+
* isDev() // false
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
14
30
|
* @returns {boolean} `true` if `process.env.NODE_ENV` is `'development'`, otherwise `false`.
|
|
15
31
|
*/
|
|
16
32
|
export declare const isDev: () => boolean;
|
|
17
33
|
/**
|
|
18
34
|
* Determines if the current environment is set to production.
|
|
19
35
|
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* process.env.NODE_ENV = 'production'
|
|
39
|
+
* isProd() // true
|
|
40
|
+
* process.env.NODE_ENV = 'test'
|
|
41
|
+
* isProd() // false
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
20
44
|
* @returns {boolean} `true` if `process.env.NODE_ENV` is `'production'`, otherwise `false`.
|
|
21
45
|
*/
|
|
22
46
|
export declare const isProd: () => boolean;
|
package/dist/env/index.d.ts.map
CHANGED
|
@@ -1 +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
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/env/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,EAAE,eAAe,MAAM,WAUxD,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,KAAK,QAAO,OAExB,CAAA;AAED;;;;;;;;;;;;GAYG;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"}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a new Error with a custom name and message.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const err = createCustomError('NotFoundError', 'user 42 is missing')
|
|
7
|
+
* err.name // 'NotFoundError'
|
|
8
|
+
* err.message // 'user 42 is missing'
|
|
9
|
+
* err instanceof Error // true
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
3
12
|
* @param name The error name.
|
|
4
13
|
* @param message The error message.
|
|
5
14
|
* @returns The custom Error object.
|
|
@@ -7,6 +16,15 @@
|
|
|
7
16
|
export declare function createCustomError(name: string, message: string): Error;
|
|
8
17
|
/**
|
|
9
18
|
* Checks if an error is an instance of a specific error name.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const err = createCustomError('NotFoundError', 'missing')
|
|
23
|
+
* isErrorName(err, 'NotFoundError') // true
|
|
24
|
+
* isErrorName(err, 'TypeError') // false
|
|
25
|
+
* isErrorName('oops', 'TypeError') // false
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
10
28
|
* @param error The error to check.
|
|
11
29
|
* @param name The error name to match.
|
|
12
30
|
* @returns True if the error matches the name, false otherwise.
|
|
@@ -14,6 +32,14 @@ export declare function createCustomError(name: string, message: string): Error;
|
|
|
14
32
|
export declare function isErrorName(error: unknown, name: string): boolean;
|
|
15
33
|
/**
|
|
16
34
|
* Gets the error message from an unknown error value.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* getErrorMessage(new Error('boom')) // 'boom'
|
|
39
|
+
* getErrorMessage('boom') // 'boom'
|
|
40
|
+
* getErrorMessage({ code: 500 }) // '{"code":500}'
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
17
43
|
* @param error The error value.
|
|
18
44
|
* @returns The error message, or a stringified version if not an Error.
|
|
19
45
|
*/
|
|
@@ -32,8 +58,10 @@ export declare function assert(condition: unknown, message: string): asserts con
|
|
|
32
58
|
* @param fallback The fallback value to return on error.
|
|
33
59
|
*
|
|
34
60
|
* @example
|
|
35
|
-
*
|
|
36
|
-
* //
|
|
61
|
+
* ```typescript
|
|
62
|
+
* await tryWithFallback(async () => fetchData(), []) // the data, or [] if it throws
|
|
63
|
+
* await tryWithFallback(() => JSON.parse('{'), {}) // {}
|
|
64
|
+
* ```
|
|
37
65
|
*/
|
|
38
66
|
export declare function tryWithFallback<T>(fn: () => Promise<T> | T, fallback: T): Promise<T>;
|
|
39
67
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAItE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;;GAYG;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;;;;;;;;;;;;GAYG;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/events/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds an event listener and returns a function to remove it.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const off = on(button, 'click', (event) => console.log(event.clientX))
|
|
7
|
+
* off() // listener removed
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
3
10
|
* @param target The event target.
|
|
4
11
|
* @param type The event type.
|
|
5
12
|
* @param handler The event handler.
|
|
@@ -9,6 +16,13 @@
|
|
|
9
16
|
export declare function on<K extends keyof HTMLElementEventMap>(target: EventTarget, type: K, handler: (event: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): () => void;
|
|
10
17
|
/**
|
|
11
18
|
* Dispatches a custom event on the target.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* on(window, 'click', () => {})
|
|
23
|
+
* emit(window, 'cart:add', { sku: 'A1' }) // true (nothing called preventDefault)
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
12
26
|
* @param target The event target.
|
|
13
27
|
* @param type The event type.
|
|
14
28
|
* @param detail Optional detail data.
|
|
@@ -17,11 +31,21 @@ export declare function on<K extends keyof HTMLElementEventMap>(target: EventTar
|
|
|
17
31
|
export declare function emit(target: EventTarget, type: string, detail?: unknown): boolean;
|
|
18
32
|
/**
|
|
19
33
|
* Waits for a single event to occur and resolves a promise.
|
|
34
|
+
*
|
|
35
|
+
* Named `onceEvent` rather than `once` so it cannot be confused with
|
|
36
|
+
* `functions.once`, which memoises a call rather than awaiting an event.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const event = await onceEvent(button, 'click')
|
|
41
|
+
* event.type // 'click'
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
20
44
|
* @param target The event target.
|
|
21
45
|
* @param type The event type.
|
|
22
46
|
* @returns {Promise<Event>} Resolves with the event object.
|
|
23
47
|
*/
|
|
24
|
-
export declare function
|
|
48
|
+
export declare function onceEvent<K extends keyof HTMLElementEventMap>(target: EventTarget, type: K): Promise<HTMLElementEventMap[K]>;
|
|
25
49
|
/**
|
|
26
50
|
* Prevents the default action for an event.
|
|
27
51
|
* @param event The event object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;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;;;;;;;;;;;;;GAaG;AAEH,wBAAgB,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO,CAEjF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,mBAAmB,EAC5D,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"}
|
package/dist/events/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"../chunks/chunk-ANN5UYCF.js";function r(e,n,t,o){return e.addEventListener(n,t,o),()=>e.removeEventListener(n,t,o)}function E(e,n,t){return e.dispatchEvent(new CustomEvent(n,{detail:t}))}function i(e,n){return new Promise(t=>{let o=v=>{e.removeEventListener(n,o),t(v)};e.addEventListener(n,o)})}function a(e){e.preventDefault()}function s(e){e.stopPropagation()}export{E as emit,r as on,i as
|
|
1
|
+
import"../chunks/chunk-ANN5UYCF.js";function r(e,n,t,o){return e.addEventListener(n,t,o),()=>e.removeEventListener(n,t,o)}function E(e,n,t){return e.dispatchEvent(new CustomEvent(n,{detail:t}))}function i(e,n){return new Promise(t=>{let o=v=>{e.removeEventListener(n,o),t(v)};e.addEventListener(n,o)})}function a(e){e.preventDefault()}function s(e){e.stopPropagation()}export{E as emit,r as on,i as onceEvent,a as preventDefault,s as stopPropagation};
|
package/dist/fetch/index.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fetches a resource with a timeout.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* await fetchWithTimeout('https://api.example.com/health') // { status: 'ok' }
|
|
7
|
+
* await fetchWithTimeout('https://slow.example.com', {}, 500)
|
|
8
|
+
* // rejects with AbortError after 500ms
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
3
11
|
* @param url The URL to fetch.
|
|
4
12
|
* @param options Fetch options.
|
|
5
13
|
* @param timeout Timeout in milliseconds (default: 8000).
|
|
@@ -8,6 +16,16 @@
|
|
|
8
16
|
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeout?: number): Promise<unknown>;
|
|
9
17
|
/**
|
|
10
18
|
* Sends a POST request with a JSON body.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const user = await postJson<{ name: string }, { id: number }>(
|
|
23
|
+
* 'https://api.example.com/users',
|
|
24
|
+
* { name: 'Ada' }
|
|
25
|
+
* )
|
|
26
|
+
* user.id // 42
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
11
29
|
* @param url The URL to post to.
|
|
12
30
|
* @param body The body to send.
|
|
13
31
|
* @param options Additional fetch options.
|
|
@@ -16,6 +34,13 @@ export declare function fetchWithTimeout(url: string, options?: RequestInit, tim
|
|
|
16
34
|
export declare function postJson<T = unknown, R = unknown>(url: string, body: T, options?: RequestInit): Promise<R>;
|
|
17
35
|
/**
|
|
18
36
|
* Sends a GET request and returns JSON.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const user = await getJson<{ id: number }>('https://api.example.com/users/42')
|
|
41
|
+
* user.id // 42
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
19
44
|
* @param url The URL to fetch.
|
|
20
45
|
* @param options Additional fetch options.
|
|
21
46
|
* @returns The parsed JSON response.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,OAAO,SAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAUlB;AAED;;;;;;;;;;;;;;;;GAgBG;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;;;;;;;;;;;;GAYG;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"}
|
package/dist/file/index.d.ts
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reads a file as a string (UTF-8).
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* await readFileAsString('./package.json') // '{\n "name": "@rtorcato/js-common",\n ...'
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
3
9
|
* @param {string} filePath - The path to the file.
|
|
4
10
|
* @returns {Promise<string>} The file contents as a string.
|
|
5
11
|
*/
|
|
6
12
|
export declare function readFileAsString(filePath: string): Promise<string>;
|
|
7
13
|
/**
|
|
8
14
|
* Writes a string to a file (UTF-8).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* await writeFileAsString('./out.txt', 'hello')
|
|
19
|
+
* await readFileAsString('./out.txt') // 'hello'
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
9
22
|
* @param {string} filePath - The path to the file.
|
|
10
23
|
* @param {string} data - The string data to write.
|
|
11
24
|
* @returns {Promise<void>}
|
|
@@ -13,6 +26,13 @@ export declare function readFileAsString(filePath: string): Promise<string>;
|
|
|
13
26
|
export declare function writeFileAsString(filePath: string, data: string): Promise<void>;
|
|
14
27
|
/**
|
|
15
28
|
* Checks if a file exists.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* await fileExists('./package.json') // true
|
|
33
|
+
* await fileExists('./nope.txt') // false
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
16
36
|
* @param {string} filePath - The path to the file.
|
|
17
37
|
* @returns {Promise<boolean>} True if the file exists, false otherwise.
|
|
18
38
|
*/
|
package/dist/file/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAsB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAExE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAED;;;;;;;;;;;GAWG;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 @@
|
|
|
1
|
+
{"version":3,"file":"functions.test-d.d.ts","sourceRoot":"","sources":["../../src/functions/functions.test-d.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as s,b as n,c as u}from"../chunks/chunk-RBXTRLWB.js";import"../chunks/chunk-ANN5UYCF.js";import{describe as f,expectTypeOf as t,it as o}from"vitest";f("functions \u2014 types",()=>{o("once preserves the wrapped function signature",()=>{let e=s((a,p)=>({id:a,label:p}));t(e).toEqualTypeOf(),t(e).parameters.toEqualTypeOf(),t(e).returns.toEqualTypeOf(),e("1","a")}),o("debounce preserves the wrapped function parameters",()=>{let e=n((a,p)=>{},100);t(e).parameters.toEqualTypeOf(),t(e).returns.toEqualTypeOf(),e(1,"a")}),o("throttle preserves the wrapped function parameters",()=>{let e=u(a=>{},100);t(e).parameters.toEqualTypeOf(),t(e).returns.toEqualTypeOf(),e({y:1})}),o("debounce/throttle return void even when the wrapped function returns a value",()=>{let r=e=>e*2;t(n(r,10)).returns.toEqualTypeOf(),t(u(r,10)).returns.toEqualTypeOf(),t(n(r,10)).parameters.toEqualTypeOf()})});
|
|
@@ -1,23 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a function that only calls the original function once.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* let calls = 0
|
|
7
|
+
* const init = once(() => ++calls)
|
|
8
|
+
* init() // 1
|
|
9
|
+
* init() // 1 (cached, not called again)
|
|
10
|
+
* calls // 1
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
3
13
|
* @param fn The function to wrap.
|
|
4
14
|
* @returns {Function}
|
|
5
15
|
*/
|
|
6
16
|
export declare function once<T extends (...args: any[]) => any>(fn: T): T;
|
|
7
17
|
/**
|
|
8
18
|
* Returns a debounced version of a function.
|
|
19
|
+
* The wrapper defers the call, so it always returns `undefined` — never `fn`'s return value.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const search = debounce((term: string) => console.log(term), 300)
|
|
24
|
+
* search('a')
|
|
25
|
+
* search('ab')
|
|
26
|
+
* search('abc') // only 'abc' is logged, 300ms after the last call
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
9
29
|
* @param fn The function to debounce.
|
|
10
30
|
* @param wait Milliseconds to wait.
|
|
11
31
|
* @returns {Function}
|
|
12
32
|
*/
|
|
13
|
-
export declare function debounce<T extends (...args: any[]) => void>(fn: T, wait: number): T;
|
|
33
|
+
export declare function debounce<T extends (...args: any[]) => void>(fn: T, wait: number): (...args: Parameters<T>) => void;
|
|
14
34
|
/**
|
|
15
35
|
* Returns a throttled version of a function.
|
|
36
|
+
* The wrapper drops calls inside the window, so it always returns `undefined` — never `fn`'s
|
|
37
|
+
* return value.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const onScroll = throttle(() => console.log(window.scrollY), 100)
|
|
42
|
+
* window.addEventListener('scroll', onScroll)
|
|
43
|
+
* // fires at most once every 100ms, leading edge first
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
16
46
|
* @param fn The function to throttle.
|
|
17
47
|
* @param wait Milliseconds to wait between calls.
|
|
18
48
|
* @returns {Function}
|
|
19
49
|
*/
|
|
20
|
-
export declare function throttle<T extends (...args: any[]) => void>(fn: T, wait: number): T;
|
|
50
|
+
export declare function throttle<T extends (...args: any[]) => void>(fn: T, wait: number): (...args: Parameters<T>) => void;
|
|
21
51
|
/**
|
|
22
52
|
* Composes functions from right to left.
|
|
23
53
|
* @param fns Functions to compose.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,wBAAgB,IAAI,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAUhE;AAED;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAC1D,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,MAAM,GACV,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;;;;;;;;;;;;;;GAeG;AAEH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAC1D,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,MAAM,GACV,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CASlC;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"}
|