@rtorcato/js-common 4.0.0 → 5.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.
Files changed (67) hide show
  1. package/AGENTS.md +16 -16
  2. package/README.md +25 -14
  3. package/dist/abortController/index.d.ts +3 -2
  4. package/dist/abortController/index.d.ts.map +1 -1
  5. package/dist/abortController/index.js +1 -1
  6. package/dist/arrays/arrays.test-d.js +1 -1
  7. package/dist/arrays/index.d.ts +52 -0
  8. package/dist/arrays/index.d.ts.map +1 -1
  9. package/dist/arrays/index.js +1 -1
  10. package/dist/chunks/chunk-6FGK7LS2.js +1 -0
  11. package/dist/chunks/chunk-NEODDZIS.js +1 -0
  12. package/dist/chunks/chunk-U2F5TMN2.js +1 -0
  13. package/dist/chunks/chunk-VSTXGIC3.js +1 -0
  14. package/dist/crypto/index.d.ts +15 -10
  15. package/dist/crypto/index.d.ts.map +1 -1
  16. package/dist/crypto/index.js +1 -1
  17. package/dist/date/index.d.ts +22 -2
  18. package/dist/date/index.d.ts.map +1 -1
  19. package/dist/date/index.js +1 -1
  20. package/dist/env/index.js +3 -1
  21. package/dist/fetch/index.d.ts +6 -3
  22. package/dist/fetch/index.d.ts.map +1 -1
  23. package/dist/fetch/index.js +1 -1
  24. package/dist/logger/index.d.ts.map +1 -1
  25. package/dist/logger/index.js +1 -1
  26. package/dist/numbers/index.d.ts +96 -3
  27. package/dist/numbers/index.d.ts.map +1 -1
  28. package/dist/numbers/index.js +1 -1
  29. package/dist/os/index.d.ts +0 -11
  30. package/dist/os/index.d.ts.map +1 -1
  31. package/dist/os/index.js +1 -1
  32. package/dist/promises/index.d.ts +51 -0
  33. package/dist/promises/index.d.ts.map +1 -1
  34. package/dist/promises/index.js +1 -1
  35. package/dist/promises/promises.test-d.js +1 -1
  36. package/dist/regex/index.d.ts +7 -0
  37. package/dist/regex/index.d.ts.map +1 -1
  38. package/dist/regex/index.js +1 -1
  39. package/dist/security/index.d.ts +0 -13
  40. package/dist/security/index.d.ts.map +1 -1
  41. package/dist/security/index.js +1 -1
  42. package/dist/sleep/index.d.ts +3 -2
  43. package/dist/sleep/index.d.ts.map +1 -1
  44. package/dist/sleep/index.js +1 -1
  45. package/dist/strings/index.d.ts +3 -2
  46. package/dist/strings/index.d.ts.map +1 -1
  47. package/dist/strings/index.js +1 -1
  48. package/dist/system/index.d.ts +22 -3
  49. package/dist/system/index.d.ts.map +1 -1
  50. package/dist/system/index.js +1 -1
  51. package/dist/try/index.d.ts +12 -0
  52. package/dist/try/index.d.ts.map +1 -1
  53. package/dist/try/index.js +1 -1
  54. package/dist/try/trycatch.test-d.js +1 -1
  55. package/dist/url/index.d.ts.map +1 -1
  56. package/dist/url/index.js +1 -1
  57. package/dist/validation/index.d.ts +0 -12
  58. package/dist/validation/index.d.ts.map +1 -1
  59. package/dist/validation/index.js +1 -1
  60. package/package.json +35 -24
  61. package/dist/chunks/chunk-AVPQVYSA.js +0 -1
  62. package/dist/chunks/chunk-FBDKWWIQ.js +0 -3
  63. package/dist/chunks/chunk-J4C2KNK5.js +0 -1
  64. package/dist/chunks/chunk-UQBVI52L.js +0 -1
  65. package/dist/index.d.ts +0 -2
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/index.js +0 -0
package/AGENTS.md CHANGED
@@ -2,16 +2,16 @@
2
2
 
3
3
  # Using @rtorcato/js-common
4
4
 
5
- `@rtorcato/js-common` is a tree-shakeable, ESM-only utility library for Node.js >= 22 (TypeScript-first, JSDoc on every public API). One subpath export per concern — 44 of them. The package root is intentionally empty.
5
+ `@rtorcato/js-common` is a tree-shakeable, ESM-only utility library for Node.js >= 22 (TypeScript-first, JSDoc on every public API). One subpath export per concern — 42 of them. There is no package root export.
6
6
 
7
7
  ## Rules
8
8
 
9
- 1. **Import from the subpath, never the package root.** The root export has no runtime code at all, so a root import gets you nothing.
9
+ 1. **Import from the subpath, never the package root.** The root has no `exports` entry at all, so a root import fails at resolve time (`ERR_PACKAGE_PATH_NOT_EXPORTED`) instead of silently binding nothing.
10
10
 
11
11
  ```ts
12
12
  // ✅ do
13
13
  import { slugify } from '@rtorcato/js-common/strings'
14
- // ❌ don't — the root export is empty by design
14
+ // ❌ don't — there is no root export; this throws at resolve time
15
15
  import { slugify } from '@rtorcato/js-common'
16
16
  ```
17
17
 
@@ -19,12 +19,12 @@
19
19
 
20
20
  | Looks like | Actually |
21
21
  |---|---|
22
- | `functions.once` vs `events.onceEvent` | `once(fn)` memoises a call; `onceEvent(target, type)` awaits a DOM event |
22
+ | `functions.once` vs `events.onceEvent` | `once(fn)` memoises a call; `onceEvent(target, type)` awaits an `EventTarget` event |
23
23
  | `logger` vs `logging` | `logger` is one configured pino instance; `logging` is `console` helpers with no runtime deps |
24
24
  | `try.tryCatch` vs `errors.tryWithFallback` | Result object vs swallow-and-fall-back — see rule 3 |
25
25
  | `date.formatDate` vs `datetime.formatDateTimeLocal` | a UTC calendar day vs a local instant |
26
26
 
27
- Where two modules used to ship the same name, the loser was deleted rather than aliased — [MODULE-BOUNDARIES.md](https://github.com/rtorcato/js-common/blob/main/MODULE-BOUNDARIES.md) records which side won and why.
27
+ Where two modules used to ship the same name, the loser was deleted — use `emails.isValidEmail`, `url.isValidUrl` and `process.getProcessPlatform` (not `validation.isEmail`, `validation.isUrl` or `os.getOsPlatform`). [MODULE-BOUNDARIES.md](https://github.com/rtorcato/js-common/blob/main/MODULE-BOUNDARIES.md) records which side won and why.
28
28
 
29
29
  3. **Three different error idioms — don't mix them up.**
30
30
 
@@ -44,7 +44,7 @@
44
44
 
45
45
  `tryCatch` in `errors` was renamed to `tryWithFallback` in 2.0; `tryCatch` now means the Result helper in `try`.
46
46
 
47
- 4. **Node-only modules.** `crypto`, `security`, and `file` import `node:crypto` / `node:fs`; `logger` uses pino. Don't ship these to a browser bundle. `events` is the opposite — it wraps DOM `EventTarget` and is browser-only. `os`, `process`, `node`, and `system` probe for `process` / `window` and degrade rather than throw.
47
+ 4. **Node-only modules.** `file` imports `node:fs`; `logger` uses pino. `crypto` is Web Crypto (`globalThis.crypto`), so it runs anywhere — `hashString` and `hmacHash` return promises. Don't ship `file` or `logger` to a browser bundle. `events` wraps `EventTarget` / `CustomEvent`, which are globals in browsers and Node ≥ 22, so it runs in both. `os`, `process`, `node`, `system`, and `i18n` probe for `process` / `window` / `navigator` and degrade rather than throw. `console` and `env` read `process` unguarded, so a browser bundle needs the bundler to define it. Everything else runs anywhere. `src/runtime-boundaries.test.ts` enforces this paragraph and the `Runtime:` line on each docs module page.
48
48
 
49
49
  5. **`./types` is types-only.** It has a `types` field and no `import` field on purpose — use it for `import type { Prettify, Merge } from '@rtorcato/js-common/types'` only.
50
50
 
@@ -57,13 +57,13 @@ Import from `@rtorcato/js-common/<module>`.
57
57
  | Module | Exports |
58
58
  |---|---|
59
59
  | abortController | createAbortController, abortPromise, withAbort, abortAfter |
60
- | arrays | unique, chunk, compact, shuffle |
60
+ | arrays | unique, chunk, compact, shuffle, partition, sortBy, zip |
61
61
  | boolean | toBoolean |
62
62
  | colors | randomColor, matchingTextColor, hexToRgb, rgbToHex, isValidHex, darken, lighten |
63
63
  | console | disableConsole, clearConsole |
64
64
  | crypto | hashString, randomHex, hmacHash, base64Encode, base64Decode |
65
65
  | currency | getCurrencySymbol, getCurrencyName, getCurrencyLocale, formatPrice, formatPriceCompact, parsePrice, parseCurrencyString, convertCurrency, isValidCurrencyCode, isValidCurrency |
66
- | date | today, parseDate, formatDate, daysBetween, diffInHours, diffInMinutes, isLeapYear, addDays, subDays, addMonths, getDayOfWeek, startOfDay, endOfDay, isWeekend, isSameDay, isToday, formatRelative |
66
+ | date | today, parseDate, formatDate, daysBetween, diffInHours, diffInMinutes, isLeapYear, addDays, subDays, addMonths, getDayOfWeek, startOfDay, endOfDay, isWeekend, isWeekday, isSameDay, isToday, formatRelative |
67
67
  | datetime | nowIso, parseIsoDateTime, formatDateTimeLocal, getTimezoneOffset, toUtcDate, unixTimestamp, unixMillis, getIsoWeek, getIsoWeekInfo |
68
68
  | emails | isValidEmail, normalizeEmail, maskEmail, getEmailDomain, isFreeEmailProvider |
69
69
  | env | getENV, isDev, isProd, isTest, getNodeEnv, checkEnv, RootApiEnvSchema |
@@ -79,25 +79,25 @@ Import from `@rtorcato/js-common/<module>`.
79
79
  | logger | logger (pino instance — pretty in dev, JSON in prod) |
80
80
  | logging | logWithTimestamp, info, warn, error, captureConsole, ConsoleLevel |
81
81
  | maps | invertMap, mapValues, mergeMaps, objectToMap, mapToObject |
82
- | mime-types | lookup, types, extensions, mimeTypes |
82
+ | mime-types | lookup, types, extensions, mimeTypes, FileExtension, MimeType, MimeValue |
83
83
  | node | nodeVersionCheck, getNodeMajorVersion, isNode, requireOptional |
84
- | numbers | clamp, roundTo, formatPercent, between, sum, average, mod |
84
+ | numbers | clamp, roundTo, formatPercent, FormatPercentOptions, between, sum, average, mod, variance, stdDev, median, percentile |
85
85
  | objects | isPlainObject, deepMerge, omit, pick |
86
- | os | getOsPlatform, getOsRelease, getOsArch, getHomeDir, getTmpDir |
86
+ | os | getOsRelease, getOsArch, getHomeDir, getTmpDir |
87
87
  | process | getProcessId, getProcessUptime, getCwd, getProcessPlatform, exitProcess, isCI |
88
- | promises | to, withTimeout |
88
+ | promises | to, withTimeout, mapLimit, retry, RetryOptions |
89
89
  | random | randomInt, randomFloat, randomBool, randomElement, randomString |
90
90
  | regex | escapeRegExp, testRegex, matchAll, replaceAllRegex, splitByRegex |
91
- | security | stripScriptish, isStrongPassword, generateSecureToken |
91
+ | security | stripScriptish, isStrongPassword |
92
92
  | sleep | sleep, sleepSync, sleepRandom, sleepWithAbort |
93
93
  | strings | titleCase, capitalize, camelCase, kebabCase, snakeCase, truncate, reverse, slugify, words, wordCount, pluralize, ordinalize, isBlank, mask, template |
94
94
  | system | isMacOs, isWindows, isLinux, isIOS, isAndroid, getPlatform, isTouchDevice |
95
95
  | time | nowTime, nowTimeShort, parseTime, formatTime, secondsBetween, pad2 |
96
- | try | tryCatch, isSuccess, Result, Success, Failure |
96
+ | try | tryCatch, tryCatchSync, isSuccess, Result, Success, Failure |
97
97
  | types | Prettify, Merge (types only) |
98
98
  | url | isValidUrl, getQueryParams, setQueryParam, removeQueryParam, joinUrl, getHostname |
99
99
  | uuid | getUUIDv7, getShortUUID, toShortUUID, fromShortUUID, isUUID, isUUIDv4, isNilUUID, getUUIDVersion, getNilUUID, uuidToBytes, bytesToUUID |
100
- | validation | isDefined, isString, isNumber, isBoolean, isArray, isObject, isEmail, isUrl |
100
+ | validation | isDefined, isString, isNumber, isBoolean, isArray, isObject |
101
101
 
102
102
  ## CLI
103
103
 
@@ -111,4 +111,4 @@ npx @rtorcato/js-common@latest text capitalize "hello world"
111
111
 
112
112
  See [CLI.md](https://github.com/rtorcato/js-common/blob/main/CLI.md) for the full command list.
113
113
 
114
- For full signatures and examples, see <https://rtorcato.github.io/js-common/>.
114
+ For full signatures and examples, see <https://docs.torcato.dev/js-common/>.
package/README.md CHANGED
@@ -15,11 +15,13 @@
15
15
  [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
16
16
  [![Node.js](https://img.shields.io/badge/Node.js-%3E%3D22.0.0-brightgreen.svg)](https://nodejs.org/)
17
17
  [![codecov](https://codecov.io/gh/rtorcato/js-common/branch/main/graph/badge.svg)](https://codecov.io/gh/rtorcato/js-common)
18
- [![Docs](https://img.shields.io/badge/docs-rtorcato.github.io%2Fjs--common-blue.svg)](https://rtorcato.github.io/js-common/)
18
+ [![Docs](https://img.shields.io/badge/docs-docs.torcato.dev%2Fjs--common-blue.svg)](https://docs.torcato.dev/js-common/)
19
19
 
20
20
  A comprehensive set of common JavaScript and TypeScript utilities for Node.js projects.
21
21
 
22
- 📘 **Documentation:** <https://rtorcato.github.io/js-common/>
22
+ > **Browser APIs live in [`@rtorcato/browser-common`](https://github.com/rtorcato/browser-common).** js-common covers runtime-agnostic JavaScript and Node.js. Wrappers around browser Web APIs, such as clipboard, storage, observers, geolocation, the DOM and user-agent detection, belong to browser-common. The two packages don't overlap.
23
+
24
+ 📘 **Documentation:** <https://docs.torcato.dev/js-common/>
23
25
 
24
26
  ## Features
25
27
 
@@ -27,7 +29,7 @@ A comprehensive set of common JavaScript and TypeScript utilities for Node.js pr
27
29
  - **TypeScript** — full type definitions, JSDoc on every public API
28
30
  - **CLI included** — optional binary for use in scripts and terminals
29
31
  - **Modular** — one module per concern, 42 subpaths
30
- - **Minimal runtime deps** — only `pino`, `uuid`, `short-uuid`, `zod`. CLI packages (`chalk`, `commander`, `figlet`, …) are `optionalDependencies` and only needed for the CLI.
32
+ - **No required runtime deps** — `zod` (`./env`), `pino` (`./logger`) and `uuid` + `short-uuid` (`./uuid`) are optional peers: install one only if you import its module. CLI packages (`chalk`, `commander`, `figlet`, …) are `optionalDependencies` and only needed for the CLI.
31
33
 
32
34
  ## Installation
33
35
 
@@ -35,6 +37,14 @@ A comprehensive set of common JavaScript and TypeScript utilities for Node.js pr
35
37
  npm install @rtorcato/js-common
36
38
  ```
37
39
 
40
+ Three modules need an optional peer you install yourself:
41
+
42
+ | Module | Peer |
43
+ |---|---|
44
+ | `./env` | `npm install zod` |
45
+ | `./logger` | `npm install pino` |
46
+ | `./uuid` | `npm install uuid short-uuid` |
47
+
38
48
  Pre-release builds are published to the `beta` dist-tag, so they never reach a plain `npm install`:
39
49
 
40
50
  ```bash
@@ -64,9 +74,11 @@ npx skills add https://github.com/rtorcato/js-common --skill js-common
64
74
 
65
75
  ## Migrating
66
76
 
67
- **3.x → 4.x** — everything the runtime already does was removed. `./sets` and `./interval` are gone as modules, and the pass-through wrappers inside surviving modules went with them: `promises.all`/`allSettled`/`race`/`delay`, `boolean.and`/`or`/`not`/`xor`, `strings.padStart`/`padEnd`/`replaceString`, `arrays.first`/`last`/`flatten`/`groupBy`, `numbers.isInteger`/`isFiniteNumber`/`min`/`max`, `objects.deepClone`, `json.deepCloneJson` and `uuid.getUUID`. Nothing moved to another module — the replacement is a JavaScript built-in in every case, which the Node 22 floor guarantees. Two are **not** drop-ins: `Object.groupBy` returns a null-prototype object with optional values, and `structuredClone` keeps `Date`s where the JSON round trip flattened them. The full before/after table is in the [migration guide](https://rtorcato.github.io/js-common/docs/guides/migration).
77
+ **4.x → 5.x** — `zod`, `pino`, `uuid` and `short-uuid` moved from `dependencies` to optional `peerDependencies`. If you import `./env`, add `zod`; `./logger`, add `pino`; `./uuid`, add `uuid` and `short-uuid`. Every other module is unaffected. Details in the [migration guide](https://docs.torcato.dev/js-common/docs/guides/migration).
68
78
 
69
- **2.x → 3.x** — every helper now has exactly one home. `./formatting` and `./math` are gone, and where two modules shipped the same name the loser was deleted rather than aliased, so you get a build error naming the fix. One helper was also renamed rather than moved: `sanitizeString` is now `stripScriptish`, because the old name promised sanitising it never did — it removes `<script>` blocks and inline `on*` handlers and nothing else. The full before/after map is in the [migration guide](https://rtorcato.github.io/js-common/docs/guides/migration); the reasoning is in [MODULE-BOUNDARIES.md](MODULE-BOUNDARIES.md).
79
+ **3.x → 4.x** — everything the runtime already does was removed. `./sets` and `./interval` are gone as modules, and the pass-through wrappers inside surviving modules went with them: `promises.all`/`allSettled`/`race`/`delay`, `boolean.and`/`or`/`not`/`xor`, `strings.padStart`/`padEnd`/`replaceString`, `arrays.first`/`last`/`flatten`/`groupBy`, `numbers.isInteger`/`isFiniteNumber`/`min`/`max`, `objects.deepClone`, `json.deepCloneJson` and `uuid.getUUID`. Nothing moved to another module — the replacement is a JavaScript built-in in every case, which the Node 22 floor guarantees. Two are **not** drop-ins: `Object.groupBy` returns a null-prototype object with optional values, and `structuredClone` keeps `Date`s where the JSON round trip flattened them. The full before/after table is in the [migration guide](https://docs.torcato.dev/js-common/docs/guides/migration).
80
+
81
+ **2.x → 3.x** — every helper now has exactly one home. `./formatting` and `./math` are gone, and where two modules shipped the same name the loser was deleted rather than aliased, so you get a build error naming the fix. One helper was also renamed rather than moved: `sanitizeString` is now `stripScriptish`, because the old name promised sanitising it never did — it removes `<script>` blocks and inline `on*` handlers and nothing else. The full before/after map is in the [migration guide](https://docs.torcato.dev/js-common/docs/guides/migration); the reasoning is in [MODULE-BOUNDARIES.md](MODULE-BOUNDARIES.md).
70
82
 
71
83
  **1.x → 2.x** — the only breaking change in 2.0 is a rename in the `errors` module:
72
84
 
@@ -148,6 +160,7 @@ import { nowTime, parseTime, secondsBetween } from '@rtorcato/js-common/time'
148
160
  ### Numbers
149
161
  ```typescript
150
162
  import { sum, average, roundTo, clamp, formatPercent } from '@rtorcato/js-common/numbers'
163
+ import { variance, stdDev, median, percentile } from '@rtorcato/js-common/numbers' // dispersion
151
164
  import { randomInt, randomFloat, randomBool, randomElement } from '@rtorcato/js-common/random'
152
165
  ```
153
166
 
@@ -161,7 +174,8 @@ import { detectLanguage, formatNumber, formatDateI18n, t } from '@rtorcato/js-co
161
174
 
162
175
  ### Security & Validation
163
176
  ```typescript
164
- import { isStrongPassword, generateSecureToken } from '@rtorcato/js-common/security'
177
+ import { isStrongPassword, stripScriptish } from '@rtorcato/js-common/security'
178
+ import { randomHex, hashString, hmacHash } from '@rtorcato/js-common/crypto'
165
179
  import { isValidEmail, maskEmail } from '@rtorcato/js-common/emails'
166
180
  import { isValidUrl } from '@rtorcato/js-common/url'
167
181
  import { isString, isNumber, isBoolean, isArray, isObject } from '@rtorcato/js-common/validation'
@@ -170,7 +184,7 @@ import { toBoolean } from '@rtorcato/js-common/boolean'
170
184
 
171
185
  ### Data Structures
172
186
  ```typescript
173
- import { unique, chunk, compact, shuffle } from '@rtorcato/js-common/arrays'
187
+ import { unique, chunk, compact, shuffle, partition, sortBy, zip } from '@rtorcato/js-common/arrays'
174
188
  import { deepMerge, pick, omit, isPlainObject } from '@rtorcato/js-common/objects'
175
189
  import { safeJsonParse, safeJsonStringify } from '@rtorcato/js-common/json'
176
190
  import { invertMap, mapValues, objectToMap, mapToObject } from '@rtorcato/js-common/maps'
@@ -178,7 +192,7 @@ import { invertMap, mapValues, objectToMap, mapToObject } from '@rtorcato/js-com
178
192
 
179
193
  ### Async & Control Flow
180
194
  ```typescript
181
- import { to, withTimeout } from '@rtorcato/js-common/promises'
195
+ import { retry, to, withTimeout } from '@rtorcato/js-common/promises'
182
196
  import { debounce, throttle, once } from '@rtorcato/js-common/functions'
183
197
  import { sleep } from '@rtorcato/js-common/sleep'
184
198
  import { tryCatch } from '@rtorcato/js-common/try'
@@ -189,9 +203,9 @@ import { createCustomError, getErrorMessage, assert } from '@rtorcato/js-common/
189
203
  ### System & Process
190
204
  ```typescript
191
205
  import { getENV, isDev, isProd, getNodeEnv, checkEnv } from '@rtorcato/js-common/env'
192
- import { getOsPlatform, getOsArch, getHomeDir } from '@rtorcato/js-common/os'
206
+ import { getOsArch, getOsRelease, getHomeDir } from '@rtorcato/js-common/os'
193
207
  import { getNodeMajorVersion, isNode, requireOptional } from '@rtorcato/js-common/node'
194
- import { getProcessId, getCwd, exitProcess, isCI } from '@rtorcato/js-common/process'
208
+ import { getProcessPlatform, getCwd, exitProcess, isCI } from '@rtorcato/js-common/process'
195
209
  import { isMacOs, isWindows, isLinux, getPlatform } from '@rtorcato/js-common/system'
196
210
  import { disableConsole, clearConsole } from '@rtorcato/js-common/console'
197
211
  ```
@@ -242,9 +256,6 @@ pnpm run check:fix
242
256
 
243
257
  # Type checking
244
258
  pnpm run typecheck
245
-
246
- # Run micro-benchmarks (scripts/benchmark.mjs)
247
- pnpm run benchmark
248
259
  ```
249
260
 
250
261
  ## Documentation site
@@ -259,7 +270,7 @@ pnpm --filter @rtorcato/js-common-docs dev
259
270
  pnpm --filter @rtorcato/js-common-docs build
260
271
  ```
261
272
 
262
- Live site: <https://rtorcato.github.io/js-common/>
273
+ Live site: <https://docs.torcato.dev/js-common/>
263
274
 
264
275
  ## Roadmap
265
276
 
@@ -16,7 +16,7 @@ export declare function createAbortController(): {
16
16
  signal: AbortSignal;
17
17
  };
18
18
  /**
19
- * Returns a promise that rejects when the given AbortSignal is aborted.
19
+ * Returns a promise that rejects with `signal.reason` when the given AbortSignal is aborted.
20
20
  *
21
21
  * @example
22
22
  * ```typescript
@@ -31,7 +31,8 @@ export declare function createAbortController(): {
31
31
  */
32
32
  export declare function abortPromise(signal: AbortSignal): Promise<never>;
33
33
  /**
34
- * Wraps a promise and rejects it if the signal is aborted.
34
+ * Wraps a promise and rejects it with `signal.reason` if the signal is aborted.
35
+ * The abort listener is removed once the promise settles.
35
36
  *
36
37
  * @example
37
38
  * ```typescript
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abortController/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB;;;EAGpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAchE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAEjF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAEjG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/abortController/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB;;;EAGpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,CAAC,CAKhE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAiBjF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAEjG"}
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";function n(){let r=new AbortController;return{controller:r,signal:r.signal}}function t(r){return new Promise((e,o)=>{r.aborted?o(new DOMException("Aborted","AbortError")):r.addEventListener("abort",()=>{o(new DOMException("Aborted","AbortError"))},{once:!0})})}function i(r,e){return Promise.race([r,t(e)])}function b(r,e){return setTimeout(()=>r.abort(),e)}export{b as abortAfter,t as abortPromise,n as createAbortController,i as withAbort};
1
+ import"../chunks/chunk-ANN5UYCF.js";function u(){let e=new AbortController;return{controller:e,signal:e.signal}}function s(e){return new Promise((r,o)=>{e.aborted?o(e.reason):e.addEventListener("abort",()=>o(e.reason),{once:!0})})}function a(e,r){return r.aborted?Promise.reject(r.reason):new Promise((o,n)=>{let b=()=>n(r.reason);r.addEventListener("abort",b,{once:!0});let i=()=>r.removeEventListener("abort",b);e.then(t=>{i(),o(t)},t=>{i(),n(t)})})}function c(e,r){return setTimeout(()=>e.abort(),r)}export{c as abortAfter,s as abortPromise,u as createAbortController,a as withAbort};
@@ -1 +1 @@
1
- import{a as r,b as t}from"../chunks/chunk-UQBVI52L.js";import"../chunks/chunk-ANN5UYCF.js";import{describe as a,expectTypeOf as e,it as u}from"vitest";a("arrays \u2014 types",()=>{u("unique preserves element type",()=>{e(r([1,2,3])).toEqualTypeOf(),e(r(["a"])).toEqualTypeOf()}),u("chunk returns array of arrays of the element type",()=>{e(t([1,2,3],2)).toEqualTypeOf(),e(t(["a","b"],1)).toEqualTypeOf()})});
1
+ import{a as p,b as a,e as n,f as u,g as y}from"../chunks/chunk-U2F5TMN2.js";import"../chunks/chunk-ANN5UYCF.js";import{describe as o,expectTypeOf as e,it as r}from"vitest";o("arrays \u2014 types",()=>{r("unique preserves element type",()=>{e(p([1,2,3])).toEqualTypeOf(),e(p(["a"])).toEqualTypeOf()}),r("chunk returns array of arrays of the element type",()=>{e(a([1,2,3],2)).toEqualTypeOf(),e(a(["a","b"],1)).toEqualTypeOf()})});o("arrays \u2014 grouping helper types",()=>{r("partition returns a tuple of element arrays",()=>{e(n([1,2],t=>t>1)).toEqualTypeOf()}),r("sortBy preserves the element type",()=>{e(u([1,2],t=>t)).toEqualTypeOf()}),r("zip pairs both element types",()=>{e(y([1],["a"])).toEqualTypeOf()})});
@@ -68,4 +68,56 @@ export declare function compact<T>(arr: T[]): T[];
68
68
  * @category Array Utilities
69
69
  */
70
70
  export declare function shuffle<T>(arr: T[]): T[];
71
+ /**
72
+ * Splits an array into two arrays: the elements that satisfy the predicate and
73
+ * the ones that do not. Order is preserved within each half.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * partition([1, 2, 3, 4], (n) => n % 2 === 0) // [[2, 4], [1, 3]]
78
+ * partition(['a', 'bb'], (s) => s.length > 1) // [['bb'], ['a']]
79
+ * ```
80
+ *
81
+ * @param arr The array to split
82
+ * @param predicate Called with each element and its index; truthy sends the element to the first half
83
+ * @returns A `[pass, fail]` tuple of new arrays
84
+ * @category Array Utilities
85
+ */
86
+ export declare function partition<T>(arr: T[], predicate: (value: T, index: number) => boolean): [T[], T[]];
87
+ /**
88
+ * Sorts an array by a derived key, without mutating the input.
89
+ * Keys are compared with `<` / `>`, so strings sort lexicographically and
90
+ * numbers numerically — unlike `Array#sort`, which stringifies everything.
91
+ * The sort is stable, so equal keys keep their original order.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * sortBy([{ n: 2 }, { n: 1 }], (o) => o.n) // [{ n: 1 }, { n: 2 }]
96
+ * sortBy([10, 9, 100], (n) => n) // [9, 10, 100] — not [10, 100, 9]
97
+ * sortBy(users, (u) => u.name, 'desc')
98
+ * ```
99
+ *
100
+ * @param arr The array to sort
101
+ * @param keyFn Maps an element to the value to sort by
102
+ * @param direction `'asc'` (default) or `'desc'`
103
+ * @returns A new sorted array
104
+ * @category Array Utilities
105
+ */
106
+ export declare function sortBy<T>(arr: T[], keyFn: (value: T) => number | string | bigint | Date, direction?: 'asc' | 'desc'): T[];
107
+ /**
108
+ * Pairs up two arrays element by element. The result is as long as the shorter
109
+ * input — surplus elements are dropped.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * zip([1, 2, 3], ['a', 'b', 'c']) // [[1, 'a'], [2, 'b'], [3, 'c']]
114
+ * zip([1, 2, 3], ['a']) // [[1, 'a']]
115
+ * ```
116
+ *
117
+ * @param a The first array
118
+ * @param b The second array
119
+ * @returns An array of `[a[i], b[i]]` pairs
120
+ * @category Array Utilities
121
+ */
122
+ export declare function zip<A, B>(a: A[], b: B[]): [A, B][];
71
123
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/arrays/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAOtD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAExC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAOxC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/arrays/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEvC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAOtD;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAExC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAOxC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAC1B,GAAG,EAAE,CAAC,EAAE,EACR,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,GAC7C,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAOZ;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACvB,GAAG,EAAE,CAAC,EAAE,EACR,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,EACpD,SAAS,GAAE,KAAK,GAAG,MAAc,GAC/B,CAAC,EAAE,CAWL;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAKlD"}
@@ -1 +1 @@
1
- import{a,b,c,d}from"../chunks/chunk-UQBVI52L.js";import"../chunks/chunk-ANN5UYCF.js";export{b as chunk,c as compact,d as shuffle,a as unique};
1
+ import{a,b,c,d,e,f,g}from"../chunks/chunk-U2F5TMN2.js";import"../chunks/chunk-ANN5UYCF.js";export{b as chunk,c as compact,e as partition,d as shuffle,f as sortBy,a as unique,g as zip};
@@ -0,0 +1 @@
1
+ function e(r){return r.error===null}async function u(r){try{return{data:await r(),error:null}}catch(t){return{data:null,error:t}}}function a(r){try{return{data:r(),error:null}}catch(t){return{data:null,error:t}}}export{e as a,u as b,a as c};
@@ -0,0 +1 @@
1
+ import{d as c}from"./chunk-VSTXGIC3.js";async function h(t){try{return[null,await t]}catch(e){return[e,void 0]}}function w(t,e,a=new Error("Timeout")){return Promise.race([t,new Promise((n,i)=>setTimeout(()=>i(a),e))])}async function b(t,e={}){let{retries:a=3,minDelay:n=100,maxDelay:i=1e4,jitter:s=!0,shouldRetry:m=()=>!0,signal:o}=e;for(let r=1;;r++){o?.throwIfAborted();try{return await t(r,o)}catch(l){if(o?.aborted)throw o.reason;if(r>a||!m(l,r))throw l}let u=Math.min(i,n*2**(r-1));await c(s?Math.random()*u:u,o)}}async function f(t,e,a){if(!Number.isInteger(e)||e<1)throw new RangeError(`limit must be a positive integer, got ${e}`);let n=Array.from(t),i=new Array(n.length),s=0,m=!1;async function o(){for(;!m&&s<n.length;){let r=s++;try{i[r]=await a(n[r],r)}catch(u){throw m=!0,u}}}return await Promise.all(Array.from({length:Math.min(e,n.length)},o)),i}export{h as a,w as b,b as c,f as d};
@@ -0,0 +1 @@
1
+ function s(o){return Array.from(new Set(o))}function i(o,t){if(t<1)throw new Error("Chunk size must be at least 1");let e=[];for(let r=0;r<o.length;r+=t)e.push(o.slice(r,r+t));return e}function T(o){return o.filter(Boolean)}function c(o){let t=o.slice();for(let e=t.length-1;e>0;e--){let r=Math.floor(Math.random()*(e+1));[t[e],t[r]]=[t[r],t[e]]}return t}function a(o,t){let e=[],r=[];return o.forEach((n,u)=>{(t(n,u)?e:r).push(n)}),[e,r]}function f(o,t,e="asc"){let r=e==="desc"?-1:1;return o.map((n,u)=>({value:n,index:u,key:t(n)})).sort((n,u)=>n.key<u.key?-r:n.key>u.key?r:n.index-u.index).map(n=>n.value)}function l(o,t){let e=Math.min(o.length,t.length),r=new Array(e);for(let n=0;n<e;n++)r[n]=[o[n],t[n]];return r}export{s as a,i as b,T as c,c as d,a as e,f,l as g};
@@ -0,0 +1 @@
1
+ var m=o=>new Promise(e=>setTimeout(e,o));function s(o){let e=Date.now()+o;for(;Date.now()<e;);}function u(o,e){let r=Math.floor(Math.random()*(e-o+1))+o;return new Promise(t=>setTimeout(t,r))}function b(o,e){return new Promise((r,t)=>{if(e?.aborted){t(e.reason);return}let n=()=>{clearTimeout(i),t(e?.reason)},i=setTimeout(()=>{e?.removeEventListener("abort",n),r()},o);e?.addEventListener("abort",n,{once:!0})})}export{m as a,s as b,u as c,b as d};
@@ -1,25 +1,29 @@
1
1
  /**
2
2
  * Hashes a string using the specified algorithm.
3
3
  *
4
+ * Web Crypto supports SHA-1/256/384/512 only — there is no md5. An unsupported
5
+ * algorithm rejects.
6
+ *
4
7
  * @example
5
8
  * ```typescript
6
- * hashString('hello')
9
+ * await hashString('hello')
7
10
  * // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
8
- * hashString('hello', 'md5') // '5d41402abc4b2a76b9719d911017c592'
11
+ * await hashString('hello', 'sha1') // 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d'
9
12
  * ```
10
13
  *
11
14
  * @param str The string to hash.
12
15
  * @param algorithm The hash algorithm (default: 'sha256').
13
16
  * @returns The hex-encoded hash.
14
17
  */
15
- export declare function hashString(str: string, algorithm?: string): string;
18
+ export declare function hashString(str: string, algorithm?: 'sha1' | 'sha256' | 'sha384' | 'sha512'): Promise<string>;
16
19
  /**
17
- * Generates a random hex string of the specified length (in bytes).
20
+ * Generates a cryptographically secure random hex string of the specified length (in bytes).
18
21
  *
19
22
  * @example
20
23
  * ```typescript
21
24
  * randomHex(4) // '9f3c1ab7' (8 hex chars)
22
25
  * randomHex() // 32 hex chars (16 bytes)
26
+ * randomHex(32) // 64 hex chars — a password-reset token
23
27
  * ```
24
28
  *
25
29
  * @param length The number of bytes (not hex chars).
@@ -31,9 +35,9 @@ export declare function randomHex(length?: number): string;
31
35
  *
32
36
  * @example
33
37
  * ```typescript
34
- * hmacHash('payload', 's3cret')
38
+ * await hmacHash('payload', 's3cret')
35
39
  * // 'd1d0f5b6...' (64 hex chars, stable for the same input + secret)
36
- * hmacHash('payload', 's3cret', 'sha1') // 40 hex chars
40
+ * await hmacHash('payload', 's3cret', 'sha1') // 40 hex chars
37
41
  * ```
38
42
  *
39
43
  * @param str The string to hash.
@@ -41,17 +45,18 @@ export declare function randomHex(length?: number): string;
41
45
  * @param algorithm The hash algorithm (default: 'sha256').
42
46
  * @returns The hex-encoded HMAC.
43
47
  */
44
- export declare function hmacHash(str: string, secret: string, algorithm?: string): string;
48
+ export declare function hmacHash(str: string, secret: string, algorithm?: 'sha1' | 'sha256' | 'sha384' | 'sha512'): Promise<string>;
45
49
  /**
46
- * Encodes a string to base64.
50
+ * Encodes a string (as UTF-8) to base64.
47
51
  * @param str The string to encode.
48
52
  * @returns The base64-encoded string.
49
53
  */
50
54
  export declare function base64Encode(str: string): string;
51
55
  /**
52
- * Decodes a base64 string.
53
- * @param b64 The base64 string to decode.
56
+ * Decodes a base64 string to a UTF-8 string.
57
+ * @param b64 The base64 string to decode (standard alphabet; padding optional).
54
58
  * @returns The decoded string.
59
+ * @throws {DOMException} When `b64` is not valid base64 (including the URL-safe `-`/`_` alphabet).
55
60
  */
56
61
  export declare function base64Decode(b64: string): string;
57
62
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto/index.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,UAAU,CAC/B,GAAG,EAAE,MAAM,EACX,SAAS,GAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAmB,GAC3D,OAAO,CAAC,MAAM,CAAC,CAGjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CAAC,MAAM,SAAK,GAAG,MAAM,CAE7C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,QAAQ,CAC7B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,SAAS,GAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAmB,GAC3D,OAAO,CAAC,MAAM,CAAC,CAUjB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";import{createHash as n,createHmac as i,randomBytes as s}from"node:crypto";function a(t,r="sha256"){return n(r).update(t).digest("hex")}function g(t=16){return s(t).toString("hex")}function u(t,r,e="sha256"){return i(e,r).update(t).digest("hex")}function f(t){return Buffer.from(t,"utf-8").toString("base64")}function c(t){return Buffer.from(t,"base64").toString("utf-8")}export{c as base64Decode,f as base64Encode,a as hashString,u as hmacHash,g as randomHex};
1
+ import"../chunks/chunk-ANN5UYCF.js";function e(r){return Array.from(new Uint8Array(r),n=>n.toString(16).padStart(2,"0")).join("")}function a(r){return`SHA-${r.replace(/^sha-?/i,"")}`}async function i(r,n="sha256"){let t=await crypto.subtle.digest(a(n),new TextEncoder().encode(r));return e(t)}function c(r=16){return e(crypto.getRandomValues(new Uint8Array(r)))}async function g(r,n,t="sha256"){let o=new TextEncoder,s=await crypto.subtle.importKey("raw",o.encode(n),{name:"HMAC",hash:a(t)},!1,["sign"]);return e(await crypto.subtle.sign("HMAC",s,o.encode(r)))}function d(r){return btoa(Array.from(new TextEncoder().encode(r),n=>String.fromCharCode(n)).join(""))}function h(r){return new TextDecoder().decode(Uint8Array.from(atob(r),n=>n.charCodeAt(0)))}export{h as base64Decode,d as base64Encode,i as hashString,g as hmacHash,c as randomHex};
@@ -27,7 +27,8 @@ export declare function parseDate(dateStr: string): Date;
27
27
  */
28
28
  export declare function formatDate(date: Date): string;
29
29
  /**
30
- * Returns the difference in days between two dates (date2 - date1).
30
+ * Returns the difference in days between two dates (date2 - date1), measured in
31
+ * local wall-clock time so a DST change doesn't cost or gain a day.
31
32
  */
32
33
  export declare function daysBetween(date1: string | Date, date2: string | Date): number;
33
34
  /**
@@ -52,6 +53,15 @@ export declare function addDays(date: string | Date, days: number): Date;
52
53
  export declare function subDays(date: string | Date, days: number): Date;
53
54
  /**
54
55
  * Adds months to a date and returns a new Date object.
56
+ *
57
+ * When the source day does not exist in the target month, the result clamps to that
58
+ * month's last day (as Temporal and date-fns do) instead of rolling into the next month.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * addMonths('2026-01-31', 1) // Date — Feb 28, not Mar 3
63
+ * addMonths('2024-01-31', 1) // Date — Feb 29 (leap year)
64
+ * ```
55
65
  */
56
66
  export declare function addMonths(date: string | Date, months: number): Date;
57
67
  /**
@@ -67,9 +77,19 @@ export declare function startOfDay(date: string | Date): Date;
67
77
  */
68
78
  export declare function endOfDay(date: string | Date): Date;
69
79
  /**
70
- * Returns true if the date falls on Saturday or Sunday.
80
+ * Returns true if the date falls on Saturday or Sunday (local time).
71
81
  */
72
82
  export declare function isWeekend(date: string | Date): boolean;
83
+ /**
84
+ * Returns true if the date falls on Monday through Friday (local time).
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * isWeekday('2026-06-12') // true (Friday)
89
+ * isWeekday('2026-06-13') // false (Saturday)
90
+ * ```
91
+ */
92
+ export declare function isWeekday(date: string | Date): boolean;
73
93
  /**
74
94
  * Returns true if the two dates fall on the same calendar day (local time).
75
95
  */
@@ -1 +1 @@
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"}
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;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAI9E;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;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CASnE;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;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAEtD;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"}
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";function n(t){return typeof t=="string"?s(t):new Date(t)}function c(){return new Date().toISOString().slice(0,10)}function s(t){return new Date(`${t}T00:00:00`)}function f(t){return t.toISOString().slice(0,10)}function M(t,e){return Math.floor((n(e).getTime()-n(t).getTime())/864e5)}function d(t,e){return Math.floor((n(e).getTime()-n(t).getTime())/36e5)}function _(t,e){return Math.floor((n(e).getTime()-n(t).getTime())/6e4)}function m(t){let e=t instanceof Date?t.getUTCFullYear():t;return e%4===0&&e%100!==0||e%400===0}function u(t,e){let r=n(t);return r.setDate(r.getDate()+e),r}function p(t,e){return u(t,-e)}function S(t,e){let r=n(t);return r.setMonth(r.getMonth()+e),r}function D(t){return n(t).getDay()}function i(t){let e=n(t);return e.setHours(0,0,0,0),e}function x(t){let e=n(t);return e.setHours(23,59,59,999),e}function y(t){let e=D(t);return e===0||e===6}function g(t,e){let r=n(t),a=n(e);return r.getFullYear()===a.getFullYear()&&r.getMonth()===a.getMonth()&&r.getDate()===a.getDate()}function E(t){return g(n(t),new Date)}function b(t,e=new Date){let r=i(n(t)),a=i(e),o=Math.round((r.getTime()-a.getTime())/864e5);return o===0?"today":o===1?"tomorrow":o===-1?"yesterday":o>0?`in ${o} days`:`${-o} days ago`}export{u as addDays,S as addMonths,M as daysBetween,d as diffInHours,_ as diffInMinutes,x as endOfDay,f as formatDate,b as formatRelative,D as getDayOfWeek,m as isLeapYear,g as isSameDay,E as isToday,y as isWeekend,s as parseDate,i as startOfDay,p as subDays,c as today};
1
+ import"../chunks/chunk-ANN5UYCF.js";function r(t){return typeof t=="string"?i(t):new Date(t)}function f(){return new Date().toISOString().slice(0,10)}function i(t){return new Date(`${t}T00:00:00`)}function M(t){return t.toISOString().slice(0,10)}function _(t,e){let n=o=>o.getTime()-o.getTimezoneOffset()*6e4;return Math.floor((n(r(e))-n(r(t)))/864e5)}function d(t,e){return Math.floor((r(e).getTime()-r(t).getTime())/36e5)}function l(t,e){return Math.floor((r(e).getTime()-r(t).getTime())/6e4)}function m(t){let e=t instanceof Date?t.getUTCFullYear():t;return e%4===0&&e%100!==0||e%400===0}function D(t,e){let n=r(t);return n.setDate(n.getDate()+e),n}function p(t,e){return D(t,-e)}function y(t,e){let n=r(t),o=n.getDate();n.setDate(1),n.setMonth(n.getMonth()+e);let a=new Date(n.getFullYear(),n.getMonth()+1,0).getDate();return n.setDate(Math.min(o,a)),n}function u(t){return r(t).getDay()}function s(t){let e=r(t);return e.setHours(0,0,0,0),e}function S(t){let e=r(t);return e.setHours(23,59,59,999),e}function g(t){let e=u(t);return e===0||e===6}function x(t){return!g(t)}function c(t,e){let n=r(t),o=r(e);return n.getFullYear()===o.getFullYear()&&n.getMonth()===o.getMonth()&&n.getDate()===o.getDate()}function E(t){return c(r(t),new Date)}function b(t,e=new Date){let n=s(r(t)),o=s(e),a=Math.round((n.getTime()-o.getTime())/864e5);return a===0?"today":a===1?"tomorrow":a===-1?"yesterday":a>0?`in ${a} days`:`${-a} days ago`}export{D as addDays,y as addMonths,_ as daysBetween,d as diffInHours,l as diffInMinutes,S as endOfDay,M as formatDate,b as formatRelative,u as getDayOfWeek,m as isLeapYear,c as isSameDay,E as isToday,x as isWeekday,g as isWeekend,i as parseDate,s as startOfDay,p as subDays,f as today};
package/dist/env/index.js CHANGED
@@ -1 +1,3 @@
1
- import{a,b,c,d,e,f,g}from"../chunks/chunk-FBDKWWIQ.js";import"../chunks/chunk-ANN5UYCF.js";export{g as RootApiEnvSchema,f as checkEnv,a as getENV,e as getNodeEnv,b as isDev,c as isProd,d as isTest};
1
+ import"../chunks/chunk-ANN5UYCF.js";import{z as n}from"zod";var c=(r,o)=>{let e=process.env[r.toString()];if(e===void 0&&o!==void 0)return o;if(e===void 0){let t=`Undefined ENV variable - ${r.toString()}`;throw new Error(t)}return e},d=()=>process.env.NODE_ENV==="development",p=()=>process.env.NODE_ENV==="production",E=()=>process.env.NODE_ENV==="test",u=()=>process.env.NODE_ENV||"development";function a(r,o=process.env){try{return r.parse(o)}catch(e){if(e instanceof n.ZodError){let t=`Missing required values in .env:
2
+ `;t+=Object.keys(e.flatten().fieldErrors).join(`
3
+ `);let s=new Error(t);throw s.stack="",s}throw e}}var f=n.object({NODE_ENV:n.enum(["development","test","production"]).default("development"),LOG_LEVEL:n.enum(["debug","info","warn","error"]).default("info"),PORT:n.coerce.number().default(3e3)});export{f as RootApiEnvSchema,a as checkEnv,c as getENV,u as getNodeEnv,d as isDev,p as isProd,E as isTest};
@@ -5,11 +5,14 @@
5
5
  * ```typescript
6
6
  * await fetchWithTimeout('https://api.example.com/health') // { status: 'ok' }
7
7
  * await fetchWithTimeout('https://slow.example.com', {}, 500)
8
- * // rejects with AbortError after 500ms
8
+ * // rejects with a TimeoutError DOMException after 500ms (covers the body read too)
9
+ * const controller = new AbortController()
10
+ * await fetchWithTimeout('https://api.example.com', { signal: controller.signal })
11
+ * // controller.abort() rejects with AbortError
9
12
  * ```
10
13
  *
11
14
  * @param url The URL to fetch.
12
- * @param options Fetch options.
15
+ * @param options Fetch options. A caller `signal` is honoured alongside the timeout.
13
16
  * @param timeout Timeout in milliseconds (default: 8000).
14
17
  * @returns The parsed JSON response.
15
18
  */
@@ -49,7 +52,7 @@ export declare function getJson<T = unknown>(url: string, options?: RequestInit)
49
52
  /**
50
53
  * Fetches a resource and returns the response as text.
51
54
  * @param url The URL to fetch.
52
- * @param options Fetch options.
55
+ * @param options Fetch options. A caller `signal` is honoured alongside the timeout.
53
56
  * @returns The response as text.
54
57
  */
55
58
  export declare function fetchText(url: string, options?: RequestInit): Promise<string>;
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fetch/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,OAAO,SAAO,GACZ,OAAO,CAAC,OAAO,CAAC,CAKlB;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"}
@@ -1 +1 @@
1
- import"../chunks/chunk-ANN5UYCF.js";async function i(n,t={},e=8e3){let o=new AbortController,r=setTimeout(()=>o.abort(),e);try{let s=await fetch(n,{...t,signal:o.signal});return clearTimeout(r),await s.json()}finally{clearTimeout(r)}}async function a(n,t,e={}){return await(await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...e.headers||{}},body:JSON.stringify(t),...e})).json()}async function c(n,t={}){return await(await fetch(n,{...t,method:"GET"})).json()}async function u(n,t={}){return await(await fetch(n,t)).text()}async function p(n,t){try{return await n}catch(e){if(t!==void 0)return t;throw e}}export{u as fetchText,i as fetchWithTimeout,c as getJson,p as handleApiError,a as postJson};
1
+ import"../chunks/chunk-ANN5UYCF.js";async function i(t,n={},e=8e3){let s=AbortSignal.timeout(e),o=n.signal?AbortSignal.any([n.signal,s]):s;return await(await fetch(t,{...n,signal:o})).json()}async function a(t,n,e={}){return await(await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...e.headers||{}},body:JSON.stringify(n),...e})).json()}async function c(t,n={}){return await(await fetch(t,{...n,method:"GET"})).json()}async function u(t,n={}){return await(await fetch(t,n)).text()}async function p(t,n){try{return await t}catch(e){if(n!==void 0)return n;throw e}}export{u as fetchText,i as fetchWithTimeout,c as getJson,p as handleApiError,a as postJson};
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAgBvB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,6BA0BQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAA;AAevB;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,6BA4BQ,CAAA"}
@@ -1 +1 @@
1
- import{b as e}from"../chunks/chunk-FBDKWWIQ.js";import"../chunks/chunk-ANN5UYCF.js";import{createRequire as t}from"node:module";import r from"pino";function o(){try{return t(import.meta.url).resolve("pino-pretty"),!0}catch{return!1}}var s=e()&&o()?r({level:"debug",transport:{target:"pino-pretty",options:{colorize:!0,ignore:"pid,hostname,time",levelFirst:!1,singleLine:!0,customColors:"err:red,info:blue",translateTime:"HH:MM:ss"}}}):r({level:"info"});export{s as logger};
1
+ import"../chunks/chunk-ANN5UYCF.js";import{createRequire as r}from"node:module";import e from"pino";function t(){try{return r(import.meta.url).resolve("pino-pretty"),!0}catch{return!1}}var i=process.env.NODE_ENV==="development"&&t()?e({level:"debug",transport:{target:"pino-pretty",options:{colorize:!0,ignore:"pid,hostname,time",levelFirst:!1,singleLine:!0,customColors:"err:red,info:blue",translateTime:"HH:MM:ss"}}}):e({level:"info"});export{i as logger};