@absoluteui/helpers 0.0.0-stage → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +47 -2
  4. package/SECURITY.md +102 -0
  5. package/dist/array/compare.d.ts +8 -0
  6. package/dist/array/compare.js +2 -0
  7. package/dist/array/index.d.ts +328 -0
  8. package/dist/array/index.js +2 -0
  9. package/dist/array/tree.d.ts +48 -0
  10. package/dist/array/tree.js +2 -0
  11. package/dist/async/batch.d.ts +103 -0
  12. package/dist/async/batch.js +2 -0
  13. package/dist/async/concurrency.d.ts +92 -0
  14. package/dist/async/concurrency.js +2 -0
  15. package/dist/async/control.d.ts +77 -0
  16. package/dist/async/control.js +2 -0
  17. package/dist/async/index.d.ts +8 -0
  18. package/dist/async/index.js +2 -0
  19. package/dist/async/signal.d.ts +95 -0
  20. package/dist/async/signal.js +2 -0
  21. package/dist/boolean/index.d.ts +83 -0
  22. package/dist/boolean/index.js +2 -0
  23. package/dist/business-calendar/days.d.ts +397 -0
  24. package/dist/business-calendar/days.js +2 -0
  25. package/dist/business-calendar/describe.d.ts +45 -0
  26. package/dist/business-calendar/describe.js +2 -0
  27. package/dist/business-calendar/engine.d.ts +305 -0
  28. package/dist/business-calendar/engine.js +2 -0
  29. package/dist/business-calendar/hours.d.ts +96 -0
  30. package/dist/business-calendar/hours.js +2 -0
  31. package/dist/business-calendar/index.d.ts +29 -0
  32. package/dist/business-calendar/index.js +2 -0
  33. package/dist/business-calendar/internal.d.ts +44 -0
  34. package/dist/business-calendar/internal.js +2 -0
  35. package/dist/business-calendar/rules.d.ts +260 -0
  36. package/dist/business-calendar/rules.js +2 -0
  37. package/dist/color/index.d.ts +200 -0
  38. package/dist/color/index.js +2 -0
  39. package/dist/color/named.d.ts +4 -0
  40. package/dist/color/named.js +2 -0
  41. package/dist/compare/index.d.ts +186 -0
  42. package/dist/compare/index.js +2 -0
  43. package/dist/convert/index.d.ts +152 -0
  44. package/dist/convert/index.js +2 -0
  45. package/dist/csv/index.d.ts +6 -0
  46. package/dist/csv/index.js +2 -0
  47. package/dist/csv/parse.d.ts +85 -0
  48. package/dist/csv/parse.js +12 -0
  49. package/dist/csv/stringify.d.ts +48 -0
  50. package/dist/csv/stringify.js +5 -0
  51. package/dist/date/calendar.d.ts +339 -0
  52. package/dist/date/calendar.js +2 -0
  53. package/dist/date/format.d.ts +66 -0
  54. package/dist/date/format.js +2 -0
  55. package/dist/date/index.d.ts +26 -0
  56. package/dist/date/index.js +2 -0
  57. package/dist/date/intervals.d.ts +110 -0
  58. package/dist/date/intervals.js +2 -0
  59. package/dist/date/intl-cache.d.ts +10 -0
  60. package/dist/date/intl-cache.js +2 -0
  61. package/dist/date/locale.d.ts +58 -0
  62. package/dist/date/locale.js +2 -0
  63. package/dist/date/plain-date.d.ts +105 -0
  64. package/dist/date/plain-date.js +2 -0
  65. package/dist/date/plain-time.d.ts +121 -0
  66. package/dist/date/plain-time.js +2 -0
  67. package/dist/date/zone.d.ts +121 -0
  68. package/dist/date/zone.js +2 -0
  69. package/dist/decimal/index.d.ts +149 -0
  70. package/dist/decimal/index.js +2 -0
  71. package/dist/ds/avl.d.ts +50 -0
  72. package/dist/ds/avl.js +2 -0
  73. package/dist/ds/bitset.d.ts +46 -0
  74. package/dist/ds/bitset.js +2 -0
  75. package/dist/ds/bloom.d.ts +41 -0
  76. package/dist/ds/bloom.js +2 -0
  77. package/dist/ds/caches.d.ts +141 -0
  78. package/dist/ds/caches.js +2 -0
  79. package/dist/ds/disjoint-set.d.ts +38 -0
  80. package/dist/ds/disjoint-set.js +2 -0
  81. package/dist/ds/emitter.d.ts +53 -0
  82. package/dist/ds/emitter.js +2 -0
  83. package/dist/ds/graph.d.ts +84 -0
  84. package/dist/ds/graph.js +2 -0
  85. package/dist/ds/heap.d.ts +49 -0
  86. package/dist/ds/heap.js +2 -0
  87. package/dist/ds/index.d.ts +20 -0
  88. package/dist/ds/index.js +2 -0
  89. package/dist/ds/internal.d.ts +19 -0
  90. package/dist/ds/internal.js +2 -0
  91. package/dist/ds/interval-tree.d.ts +49 -0
  92. package/dist/ds/interval-tree.js +2 -0
  93. package/dist/ds/linked-list.d.ts +54 -0
  94. package/dist/ds/linked-list.js +2 -0
  95. package/dist/ds/maps.d.ts +89 -0
  96. package/dist/ds/maps.js +2 -0
  97. package/dist/ds/ring.d.ts +99 -0
  98. package/dist/ds/ring.js +2 -0
  99. package/dist/ds/sorted.d.ts +104 -0
  100. package/dist/ds/sorted.js +2 -0
  101. package/dist/ds/stack.d.ts +28 -0
  102. package/dist/ds/stack.js +2 -0
  103. package/dist/ds/trie.d.ts +84 -0
  104. package/dist/ds/trie.js +2 -0
  105. package/dist/duration/index.d.ts +146 -0
  106. package/dist/duration/index.js +2 -0
  107. package/dist/encoding/index.d.ts +144 -0
  108. package/dist/encoding/index.js +2 -0
  109. package/dist/error/index.d.ts +316 -0
  110. package/dist/error/index.js +2 -0
  111. package/dist/fn/index.d.ts +129 -0
  112. package/dist/fn/index.js +2 -0
  113. package/dist/fn/memo.d.ts +46 -0
  114. package/dist/fn/memo.js +2 -0
  115. package/dist/fn/timing.d.ts +64 -0
  116. package/dist/fn/timing.js +2 -0
  117. package/dist/http/headers.d.ts +160 -0
  118. package/dist/http/headers.js +2 -0
  119. package/dist/http/index.d.ts +10 -0
  120. package/dist/http/index.js +2 -0
  121. package/dist/http/problem.d.ts +37 -0
  122. package/dist/http/problem.js +2 -0
  123. package/dist/http/response.d.ts +43 -0
  124. package/dist/http/response.js +2 -0
  125. package/dist/http/status.d.ts +169 -0
  126. package/dist/http/status.js +2 -0
  127. package/dist/index.d.ts +34 -0
  128. package/dist/index.js +2 -0
  129. package/dist/internal/keys.d.ts +6 -0
  130. package/dist/internal/keys.js +2 -0
  131. package/dist/is/index.d.ts +219 -0
  132. package/dist/is/index.js +2 -0
  133. package/dist/json/index.d.ts +9 -0
  134. package/dist/json/index.js +2 -0
  135. package/dist/json/internal.d.ts +12 -0
  136. package/dist/json/internal.js +2 -0
  137. package/dist/json/ndjson.d.ts +28 -0
  138. package/dist/json/ndjson.js +4 -0
  139. package/dist/json/parse.d.ts +45 -0
  140. package/dist/json/parse.js +2 -0
  141. package/dist/json/patch.d.ts +62 -0
  142. package/dist/json/patch.js +2 -0
  143. package/dist/json/pointer.d.ts +43 -0
  144. package/dist/json/pointer.js +2 -0
  145. package/dist/json/stringify.d.ts +42 -0
  146. package/dist/json/stringify.js +2 -0
  147. package/dist/linq/enumerable.d.ts +208 -0
  148. package/dist/linq/enumerable.js +2 -0
  149. package/dist/linq/index.d.ts +6 -0
  150. package/dist/linq/index.js +2 -0
  151. package/dist/linq/operators.d.ts +503 -0
  152. package/dist/linq/operators.js +2 -0
  153. package/dist/number/core.d.ts +164 -0
  154. package/dist/number/core.js +2 -0
  155. package/dist/number/format.d.ts +80 -0
  156. package/dist/number/format.js +2 -0
  157. package/dist/number/index.d.ts +12 -0
  158. package/dist/number/index.js +2 -0
  159. package/dist/number/internal.d.ts +18 -0
  160. package/dist/number/internal.js +2 -0
  161. package/dist/number/parse.d.ts +45 -0
  162. package/dist/number/parse.js +2 -0
  163. package/dist/number/words.d.ts +19 -0
  164. package/dist/number/words.js +2 -0
  165. package/dist/object/basic.d.ts +130 -0
  166. package/dist/object/basic.js +2 -0
  167. package/dist/object/deep.d.ts +90 -0
  168. package/dist/object/deep.js +2 -0
  169. package/dist/object/diff.d.ts +57 -0
  170. package/dist/object/diff.js +2 -0
  171. package/dist/object/index.d.ts +8 -0
  172. package/dist/object/index.js +2 -0
  173. package/dist/object/internal.d.ts +21 -0
  174. package/dist/object/internal.js +2 -0
  175. package/dist/object/path.d.ts +17 -0
  176. package/dist/object/path.js +2 -0
  177. package/dist/random/core.d.ts +14 -0
  178. package/dist/random/core.js +2 -0
  179. package/dist/random/index.d.ts +167 -0
  180. package/dist/random/index.js +2 -0
  181. package/dist/random/seeded.d.ts +27 -0
  182. package/dist/random/seeded.js +2 -0
  183. package/dist/sanitize/index.d.ts +8 -0
  184. package/dist/sanitize/index.js +2 -0
  185. package/dist/sanitize/pii.d.ts +48 -0
  186. package/dist/sanitize/pii.js +2 -0
  187. package/dist/sanitize/records.d.ts +100 -0
  188. package/dist/sanitize/records.js +2 -0
  189. package/dist/sanitize/text.d.ts +101 -0
  190. package/dist/sanitize/text.js +2 -0
  191. package/dist/set/index.d.ts +162 -0
  192. package/dist/set/index.js +2 -0
  193. package/dist/stats/index.d.ts +190 -0
  194. package/dist/stats/index.js +2 -0
  195. package/dist/string/index.d.ts +494 -0
  196. package/dist/string/index.js +8 -0
  197. package/dist/string/internal.d.ts +33 -0
  198. package/dist/string/internal.js +2 -0
  199. package/dist/string/words.d.ts +14 -0
  200. package/dist/string/words.js +2 -0
  201. package/dist/timezone/index.d.ts +76 -0
  202. package/dist/timezone/index.js +2 -0
  203. package/dist/url/index.d.ts +178 -0
  204. package/dist/url/index.js +2 -0
  205. package/dist/validate/builders.d.ts +6 -0
  206. package/dist/validate/builders.js +2 -0
  207. package/dist/validate/formats.d.ts +237 -0
  208. package/dist/validate/formats.js +2 -0
  209. package/dist/validate/index.d.ts +13 -0
  210. package/dist/validate/index.js +2 -0
  211. package/dist/validate/schema.d.ts +220 -0
  212. package/dist/validate/schema.js +2 -0
  213. package/dist/zip/index.d.ts +8 -0
  214. package/dist/zip/index.js +2 -0
  215. package/dist/zip/internal.d.ts +69 -0
  216. package/dist/zip/internal.js +2 -0
  217. package/dist/zip/reader.d.ts +56 -0
  218. package/dist/zip/reader.js +2 -0
  219. package/dist/zip/writer.d.ts +65 -0
  220. package/dist/zip/writer.js +2 -0
  221. package/package.json +150 -4
@@ -0,0 +1,77 @@
1
+ import { type SignalOptions } from './signal.js';
2
+ export interface TimeoutOptions extends SignalOptions {
3
+ /** Message for the `TimeoutError` (developer text; never user input). */
4
+ readonly message?: string;
5
+ }
6
+ /**
7
+ * Rejects with `TimeoutError` (code `HLP_TIMEOUT`) if `work` does not settle within `ms`.
8
+ * When `work` is a function it receives an `AbortSignal` that aborts on timeout or outer abort,
9
+ * so the inner operation is actually cancelled.
10
+ * @example
11
+ * await timeout(Promise.resolve('ok'), 1_000); // => 'ok'
12
+ * await timeout((signal) => sleep(10_000, { signal }), 20); // => throws HLP_TIMEOUT
13
+ */
14
+ export declare function timeout<T>(work: PromiseLike<T> | ((signal: AbortSignal) => PromiseLike<T> | T), ms: number, options?: TimeoutOptions): Promise<T>;
15
+ export interface RetryOptions extends SignalOptions {
16
+ /** Retries after the first attempt (total attempts = retries + 1). Default 3. */
17
+ readonly retries?: number;
18
+ /** Base delay in ms for the first retry. Default 100. */
19
+ readonly minDelay?: number;
20
+ /** Delay cap in ms. Default 30 000. */
21
+ readonly maxDelay?: number;
22
+ /** Exponential growth factor (>= 1). Default 2. */
23
+ readonly factor?: number;
24
+ /** `'full'` (default): random in [0, d]; `'equal'`: d/2 + random in [0, d/2]; `'none'`: d. */
25
+ readonly jitter?: 'full' | 'equal' | 'none';
26
+ /** Decides whether to retry; abort errors are never retried. Default: always. */
27
+ readonly retryIf?: (error: Error, attempt: number) => boolean | PromiseLike<boolean>;
28
+ /** Overrides the computed delay (for example from a `Retry-After` header); return `undefined` to keep it. */
29
+ readonly delayFor?: (error: Error, attempt: number, computed: number) => number | undefined;
30
+ /** Called before waiting for each retry. */
31
+ readonly onRetry?: (error: Error, attempt: number, delayMs: number) => void;
32
+ /** Random source in [0, 1) for jitter, injectable for tests. Default: `crypto.getRandomValues`. */
33
+ readonly random?: () => number;
34
+ }
35
+ /**
36
+ * Backoff delay for retry number `attempt` (1-based): `min(maxDelay, minDelay * factor^(attempt-1))` with jitter.
37
+ * @example
38
+ * backoffDelay(3, { minDelay: 100, jitter: 'none' }); // => 400
39
+ */
40
+ export declare function backoffDelay(attempt: number, options?: Pick<RetryOptions, 'minDelay' | 'maxDelay' | 'factor' | 'jitter' | 'random'>): number;
41
+ /**
42
+ * Calls `fn(attempt, signal)` until it succeeds, retrying failures with exponential backoff and jitter.
43
+ * Never retries abort errors; stops immediately when `signal` aborts. Rejects with the last error (non-`Error` throws normalized by `toError`).
44
+ * @example
45
+ * let calls = 0;
46
+ * const data = await retry(
47
+ * async (attempt) => {
48
+ * calls = attempt;
49
+ * if (attempt < 3) throw new Error('Service unavailable.');
50
+ * return 'ok';
51
+ * },
52
+ * { retries: 4, minDelay: 1, jitter: 'none', retryIf: (e) => e.message === 'Service unavailable.' },
53
+ * );
54
+ * data; // => 'ok'
55
+ * calls; // => 3
56
+ */
57
+ export declare function retry<T>(fn: (attempt: number, signal: AbortSignal) => PromiseLike<T> | T, options?: RetryOptions): Promise<T>;
58
+ export interface PollOptions<T> extends SignalOptions {
59
+ /** Ms between the end of one call and the start of the next. Default 1000. */
60
+ readonly interval?: number;
61
+ /** Stop condition. Default: value is truthy. */
62
+ readonly until?: (value: T, attempt: number) => boolean;
63
+ /** Overall limit in ms; rejects with `TimeoutError` and aborts the in-flight call. */
64
+ readonly timeout?: number;
65
+ }
66
+ /**
67
+ * Calls `fn` repeatedly until `until(value)` holds, waiting `interval` ms between calls.
68
+ * @example
69
+ * let calls = 0;
70
+ * const job = await poll(async () => ({ status: ++calls < 3 ? 'running' : 'done' }), {
71
+ * until: (j) => j.status !== 'running',
72
+ * interval: 5,
73
+ * timeout: 1_000,
74
+ * });
75
+ * [job.status, calls]; // => ['done', 3]
76
+ */
77
+ export declare function poll<T>(fn: (signal: AbortSignal, attempt: number) => PromiseLike<T> | T, options?: PollOptions<T>): Promise<T>;
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{TimeoutError as w,ValidationError as T,isAbortError as x,toError as c}from"../error/index.js";import{abortReason as g,assertDelay as y,sleep as p,throwIfAborted as P}from"./signal.js";function A(i,e,m={}){y(e);const l=m.signal;return new Promise((s,n)=>{if(l?.aborted){n(g(l));return}const r=new AbortController;let o=!1;const t=()=>o?!1:(o=!0,clearTimeout(u),l?.removeEventListener("abort",b),!0),b=()=>{if(!l||!t())return;const a=g(l);r.abort(a),n(a)},u=setTimeout(()=>{if(!t())return;const a=new w("HLP_TIMEOUT",m.message??"The operation timed out.");r.abort(a),n(a)},e);l?.addEventListener("abort",b,{once:!0});let f;try{f=typeof i=="function"?i(r.signal):i}catch(a){t(),n(c(a));return}Promise.resolve(f).then(a=>{t()&&s(a)},a=>{t()&&n(c(a))})})}function h(){const i=new Uint32Array(1);return globalThis.crypto.getRandomValues(i),(i[0]??0)/2**32}function v(i,e={}){const{minDelay:m=100,maxDelay:l=3e4,factor:s=2,jitter:n="full",random:r=h}=e,o=Math.min(l,m*s**Math.max(0,i-1));return n==="none"?o:n==="equal"?o/2+r()*(o/2):r()*o}async function O(i,e={}){const{retries:m=3,minDelay:l=100,maxDelay:s=3e4,factor:n=2,signal:r}=e;if(!Number.isSafeInteger(m)||m<0)throw new T("HLP_ASYNC_INVALID_RETRIES","retries must be a non-negative integer.");if(y(l,"minDelay"),y(s,"maxDelay"),!Number.isFinite(n)||n<1)throw new T("HLP_ASYNC_INVALID_FACTOR","factor must be a finite number >= 1.");const o=r??new AbortController().signal;for(let t=1;;t++){P(r);try{return await i(t,o)}catch(b){const u=c(b);if(x(b)||r?.aborted||t>m||e.retryIf&&!await e.retryIf(u,t))throw u;const f=v(t,e),a=e.delayFor?.(u,t,f),d=Math.min(Math.max(0,a??f),s);e.onRetry?.(u,t,d),await p(d,{signal:r})}}}function E(i,e={}){const m=e.interval??1e3;y(m,"interval");const l=e.until??(r=>!!r),s=async r=>{for(let o=1;;o++){P(r);const t=await i(r,o);if(l(t,o))return t;await p(m,{signal:r})}};if(e.timeout!==void 0)return A(s,e.timeout,{signal:e.signal,message:"Polling timed out."});const n=e.signal;return s(n??new AbortController().signal)}export{v as backoffDelay,E as poll,O as retry,A as timeout};
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Async helpers (docs/PLAN-HELPERS.md section 2 `async`). Every waiting helper accepts an `AbortSignal`,
3
+ * clears its timers and listeners when settled, and rejects with `AbortError`/`TimeoutError` from `../error`.
4
+ */
5
+ export { MAX_DELAY_MS, abortReason, throwIfAborted, sleep, deferred, raceSignal, anySignal, timeoutSignal, withCancel, type Deferred, type SignalOptions, type Cancellable } from './signal.js';
6
+ export { timeout, retry, backoffDelay, poll, type TimeoutOptions, type RetryOptions, type PollOptions } from './control.js';
7
+ export { mapLimit, mapLimitSettled, partitionSettled, createLimiter, createSerialQueue, forEachAsync, type MapLimitOptions, type Limiter } from './concurrency.js';
8
+ export { createBatcher, singleFlight, debounceAsync, asyncPipe, toAsyncIterable, collectAsync, type Batcher, type BatcherOptions, type DebouncedAsync, type CollectOptions } from './batch.js';
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{MAX_DELAY_MS as o,abortReason as i,throwIfAborted as r,sleep as p,deferred as a,raceSignal as n,anySignal as l,timeoutSignal as c,withCancel as y}from"./signal.js";import{timeout as m,retry as f,backoffDelay as d,poll as A}from"./control.js";import{mapLimit as b,mapLimitSettled as h,partitionSettled as u,createLimiter as O,createSerialQueue as g,forEachAsync as L}from"./concurrency.js";import{createBatcher as D,singleFlight as B,debounceAsync as C,asyncPipe as M,toAsyncIterable as w,collectAsync as E}from"./batch.js";export{o as MAX_DELAY_MS,i as abortReason,l as anySignal,M as asyncPipe,d as backoffDelay,E as collectAsync,D as createBatcher,O as createLimiter,g as createSerialQueue,C as debounceAsync,a as deferred,L as forEachAsync,b as mapLimit,h as mapLimitSettled,u as partitionSettled,A as poll,n as raceSignal,f as retry,B as singleFlight,p as sleep,r as throwIfAborted,m as timeout,c as timeoutSignal,w as toAsyncIterable,y as withCancel};
@@ -0,0 +1,95 @@
1
+ import { HelperError } from '../error/index.js';
2
+ /** Largest delay `setTimeout` honours (about 24.8 days); larger values would fire immediately. */
3
+ export declare const MAX_DELAY_MS = 2147483647;
4
+ /** Throws `HLP_ASYNC_INVALID_MS` unless `ms` is a finite number in [0, MAX_DELAY_MS]. */
5
+ export declare function assertDelay(ms: number, name?: string): void;
6
+ /** Options accepted by every cancellable helper. */
7
+ export interface SignalOptions {
8
+ /** Aborts the operation; the promise rejects with `AbortError` (or the `HelperError` used as reason). */
9
+ readonly signal?: AbortSignal | undefined;
10
+ }
11
+ /**
12
+ * The error an aborted `signal` should reject with: its reason when that is a `HelperError`,
13
+ * `TimeoutError` for timeout reasons (`AbortSignal.timeout`), otherwise `AbortError` with the reason as `cause`.
14
+ * @example
15
+ * const controller = new AbortController();
16
+ * controller.abort();
17
+ * abortReason(controller.signal).code; // => 'HLP_ABORTED'
18
+ */
19
+ export declare function abortReason(signal: AbortSignal): HelperError;
20
+ /**
21
+ * Throws `abortReason(signal)` when `signal` is aborted.
22
+ * @example
23
+ * const controller = new AbortController();
24
+ * throwIfAborted(controller.signal); // no-op while not aborted
25
+ * controller.abort();
26
+ * throwIfAborted(controller.signal); // => throws HLP_ABORTED
27
+ */
28
+ export declare function throwIfAborted(signal: AbortSignal | undefined): void;
29
+ /**
30
+ * Resolves after `ms`; rejects with `AbortError` (and clears the timer) when `signal` aborts.
31
+ * @example
32
+ * await sleep(10);
33
+ * const controller = new AbortController();
34
+ * const pending = sleep(10_000, { signal: controller.signal });
35
+ * controller.abort();
36
+ * await pending; // => throws HLP_ABORTED
37
+ */
38
+ export declare function sleep(ms: number, options?: SignalOptions): Promise<void>;
39
+ /** `{ promise, resolve, reject }` for settling a promise from outside. */
40
+ export interface Deferred<T> {
41
+ readonly promise: Promise<T>;
42
+ readonly resolve: (value: T | PromiseLike<T>) => void;
43
+ readonly reject: (reason?: unknown) => void;
44
+ }
45
+ /**
46
+ * Creates a promise with external `resolve`/`reject` (native `Promise.withResolvers` when present).
47
+ * @example
48
+ * const ready = deferred<string>();
49
+ * setTimeout(() => ready.resolve('connected'), 0);
50
+ * await ready.promise; // => 'connected'
51
+ */
52
+ export declare function deferred<T>(): Deferred<T>;
53
+ /**
54
+ * Settles like `promise`, or rejects with `AbortError` as soon as `signal` aborts (the underlying work
55
+ * is not cancelled; pass the signal to it too). Removes its listener when settled.
56
+ * @example
57
+ * const controller = new AbortController();
58
+ * const never = new Promise<string>(() => {});
59
+ * const pending = raceSignal(never, controller.signal);
60
+ * controller.abort();
61
+ * await pending; // => throws HLP_ABORTED
62
+ */
63
+ export declare function raceSignal<T>(promise: PromiseLike<T>, signal: AbortSignal | undefined): Promise<T>;
64
+ /**
65
+ * Signal that aborts when any input aborts (native `AbortSignal.any` when present; `undefined` entries are ignored).
66
+ * @example
67
+ * const user = new AbortController();
68
+ * const signal = anySignal([user.signal, timeoutSignal(5_000)]);
69
+ * user.abort();
70
+ * signal.aborted; // => true
71
+ */
72
+ export declare function anySignal(signals: readonly (AbortSignal | undefined)[]): AbortSignal;
73
+ /**
74
+ * Signal that aborts after `ms` with a timeout reason (native `AbortSignal.timeout` when present).
75
+ * @example
76
+ * const signal = timeoutSignal(10);
77
+ * await sleep(1_000, { signal }); // => throws HLP_TIMEOUT
78
+ */
79
+ export declare function timeoutSignal(ms: number): AbortSignal;
80
+ /** A running operation that can be cancelled. */
81
+ export interface Cancellable<T> {
82
+ readonly promise: Promise<T>;
83
+ /** Aborts the signal passed to the work and rejects `promise` with `AbortError` (or `reason`). */
84
+ readonly cancel: (reason?: unknown) => void;
85
+ readonly signal: AbortSignal;
86
+ }
87
+ /**
88
+ * Starts `fn` with a fresh `AbortSignal` and returns a handle to cancel it.
89
+ * @example
90
+ * const search = withCancel((signal) => sleep(10_000, { signal }).then(() => ['Ada']));
91
+ * search.cancel();
92
+ * await search.promise; // => throws HLP_ABORTED
93
+ * search.signal.aborted; // => true
94
+ */
95
+ export declare function withCancel<T>(fn: (signal: AbortSignal) => PromiseLike<T> | T): Cancellable<T>;
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{AbortError as s,HelperError as f,TimeoutError as l,ValidationError as c,toError as b}from"../error/index.js";const m=2147483647;function u(n,e="ms"){if(!Number.isFinite(n)||n<0||n>m)throw new c("HLP_ASYNC_INVALID_MS","Delay must be a finite number of milliseconds within the timer range.",{details:{name:e}})}function a(n){const e=n.reason;return e instanceof f?e:typeof e=="object"&&e!==null&&e.name==="TimeoutError"?new l(void 0,void 0,{cause:e}):new s(void 0,void 0,{cause:e})}function A(n){if(n?.aborted)throw a(n)}function w(n,e={}){u(n);const{signal:r}=e;return new Promise((t,i)=>{if(r?.aborted){i(a(r));return}const o=()=>{clearTimeout(d),r&&i(a(r))},d=setTimeout(()=>{r?.removeEventListener("abort",o),t()},n);r?.addEventListener("abort",o,{once:!0})})}function T(){const n=Promise.withResolvers;if(typeof n=="function")return n.call(Promise);let e,r;return{promise:new Promise((i,o)=>{e=i,r=o}),resolve:e,reject:r}}function v(n,e){return e?new Promise((r,t)=>{if(e.aborted){t(a(e));return}const i=()=>{t(a(e))};e.addEventListener("abort",i,{once:!0}),Promise.resolve(n).then(o=>{e.removeEventListener("abort",i),r(o)},o=>{e.removeEventListener("abort",i),t(b(o))})}):Promise.resolve(n)}function g(n){const e=n.filter(o=>o!==void 0);if(typeof AbortSignal.any=="function")return AbortSignal.any(e);const r=new AbortController,t=()=>{for(const o of e)o.removeEventListener("abort",i)},i=function(){t(),r.abort(this.reason)};for(const o of e){if(o.aborted){t(),r.abort(o.reason);break}o.addEventListener("abort",i,{once:!0})}return r.signal}function S(n){if(u(n),typeof AbortSignal.timeout=="function")return AbortSignal.timeout(n);const e=new AbortController;return setTimeout(()=>{e.abort(new l)},n),e.signal}function y(n){const e=new AbortController;return{promise:v(Promise.resolve().then(()=>n(e.signal)),e.signal),signal:e.signal,cancel:t=>{e.abort(t??new s)}}}export{m as MAX_DELAY_MS,a as abortReason,g as anySignal,u as assertDelay,T as deferred,v as raceSignal,w as sleep,A as throwIfAborted,S as timeoutSignal,y as withCancel};
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Boolean helpers (docs/PLAN-HELPERS.md section 2 `boolean`): lenient parsing, logic operators,
3
+ * counting and text labels.
4
+ */
5
+ export interface ParseBooleanOptions {
6
+ /** Only accept booleans and `'true'`/`'false'` (case-insensitive, trimmed). Default false. */
7
+ readonly strict?: boolean;
8
+ /** Extra accepted words for `true` (compared case-insensitively after trimming), e.g. `['ja']`. */
9
+ readonly trueValues?: readonly string[];
10
+ /** Extra accepted words for `false`, e.g. `['nein']`. */
11
+ readonly falseValues?: readonly string[];
12
+ }
13
+ /**
14
+ * Parses `true/false/yes/no/y/n/on/off/1/0` (case-insensitive, trimmed), booleans and the numbers 1/0.
15
+ * Returns `undefined` for anything else.
16
+ * @example parseBoolean(' Yes ') // => true
17
+ * @example parseBoolean('maybe') // => undefined
18
+ */
19
+ export declare function parseBoolean(value: unknown, options?: ParseBooleanOptions): boolean | undefined;
20
+ /** Exclusive or. @example xor(true, false) // => true */
21
+ export declare function xor(a: boolean, b: boolean): boolean;
22
+ /** Equivalence (not xor). @example xnor(true, true) // => true */
23
+ export declare function xnor(a: boolean, b: boolean): boolean;
24
+ /** Not and. @example nand(true, true) // => false */
25
+ export declare function nand(a: boolean, b: boolean): boolean;
26
+ /** Not or. @example nor(false, false) // => true */
27
+ export declare function nor(a: boolean, b: boolean): boolean;
28
+ /** Material implication `a → b`. @example implies(true, false) // => false */
29
+ export declare function implies(a: boolean, b: boolean): boolean;
30
+ /** Negation. @example toggle(false) // => true */
31
+ export declare function toggle(value: boolean): boolean;
32
+ /** A boolean or a lazily evaluated boolean. */
33
+ export type BooleanLike = boolean | (() => boolean);
34
+ /**
35
+ * True when every item is true (thunks are evaluated lazily, short-circuiting). Empty -> true.
36
+ * @example all([true, () => 1 < 2]) // => true
37
+ */
38
+ export declare function all(values: Iterable<BooleanLike>): boolean;
39
+ /**
40
+ * True when at least one item is true (short-circuiting). Empty -> false.
41
+ * @example any([false, true]) // => true
42
+ */
43
+ export declare function any(values: Iterable<BooleanLike>): boolean;
44
+ /**
45
+ * True when no item is true (short-circuiting). Empty -> true.
46
+ * @example none([false, false]) // => true
47
+ */
48
+ export declare function none(values: Iterable<BooleanLike>): boolean;
49
+ /**
50
+ * Counts `true` items, or items passing `predicate`.
51
+ * @example countTrue([true, false, true]) // => 2
52
+ */
53
+ export declare function countTrue<T = boolean>(values: Iterable<T>, predicate?: (value: T) => boolean): number;
54
+ /**
55
+ * True when strictly more than half of the items are `true`. Empty or tied -> false.
56
+ * @example majority([true, true, false]) // => true
57
+ */
58
+ export declare function majority(values: Iterable<boolean>): boolean;
59
+ /** Labels for `booleanToLabel`. */
60
+ export interface BooleanLabels {
61
+ readonly true: string;
62
+ readonly false: string;
63
+ /** Used for `null`/`undefined`. */
64
+ readonly null?: string;
65
+ }
66
+ /**
67
+ * Text label for a boolean (never an icon alone; pass localized labels). The default labels are
68
+ * the locale-neutral JSON literals `'true'`/`'false'`, and `''` for nullish.
69
+ * @example booleanToLabel(true, { true: 'Active', false: 'Inactive', null: 'Unknown' }) // => 'Active'
70
+ */
71
+ export declare function booleanToLabel(value: boolean | null | undefined, labels?: BooleanLabels): string;
72
+ /**
73
+ * `'Yes'`/`'No'` (English defaults; pass localized labels for other languages), `''` for nullish.
74
+ * @example booleanToYesNo(false) // => 'No'
75
+ * @example booleanToYesNo(true, { true: 'Oui', false: 'Non' }) // => 'Oui'
76
+ */
77
+ export declare function booleanToYesNo(value: boolean | null | undefined, labels?: BooleanLabels): string;
78
+ /** JavaScript truthiness as a type-friendly predicate. @example [0, 1, ''].filter(isTruthy) // => [1] */
79
+ export declare function isTruthy<T>(value: T): value is Exclude<T, false | 0 | '' | null | undefined | 0n>;
80
+ /** JavaScript falsiness. @example isFalsy(0) // => true */
81
+ export declare function isFalsy(value: unknown): boolean;
82
+ /** `1` for true, `0` for false. @example boolToInt(true) // => 1 */
83
+ export declare function boolToInt(value: boolean): 0 | 1;
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ const a=new Set(["true","yes","y","on","1"]),u=new Set(["false","no","n","off","0"]),f=64;function b(e,n={}){if(typeof e=="boolean")return e;const{strict:o=!1}=n;if(typeof e=="number")return o?void 0:e===1?!0:e===0?!1:void 0;if(typeof e!="string"||e.length>f)return;const r=e.trim().toLowerCase();if(o)return r==="true"?!0:r==="false"?!1:void 0;if(a.has(r)||n.trueValues?.some(t=>t.trim().toLowerCase()===r))return!0;if(u.has(r)||n.falseValues?.some(t=>t.trim().toLowerCase()===r))return!1}function c(e,n){return e!==n}function d(e,n){return e===n}function p(e,n){return!(e&&n)}function x(e,n){return!(e||n)}function y(e,n){return!e||n}function T(e){return!e}const l=e=>typeof e=="function"?e():e;function L(e){for(const n of e)if(!l(n))return!1;return!0}function i(e){for(const n of e)if(l(n))return!0;return!1}function B(e){return!i(e)}function g(e,n=o=>o===!0){let o=0;for(const r of e)n(r)&&o++;return o}function m(e){let n=0,o=0;for(const r of e)r?n++:o++;return n>o}function s(e,n={true:"true",false:"false"}){return e==null?n.null??"":e?n.true:n.false}function k(e,n={true:"Yes",false:"No"}){return s(e,n)}function w(e){return!!e}function I(e){return!e}function S(e){return e?1:0}export{L as all,i as any,S as boolToInt,s as booleanToLabel,k as booleanToYesNo,g as countTrue,y as implies,I as isFalsy,w as isTruthy,m as majority,p as nand,B as none,x as nor,b as parseBoolean,T as toggle,d as xnor,c as xor};