@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.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +47 -2
- package/SECURITY.md +102 -0
- package/dist/array/compare.d.ts +8 -0
- package/dist/array/compare.js +2 -0
- package/dist/array/index.d.ts +328 -0
- package/dist/array/index.js +2 -0
- package/dist/array/tree.d.ts +48 -0
- package/dist/array/tree.js +2 -0
- package/dist/async/batch.d.ts +103 -0
- package/dist/async/batch.js +2 -0
- package/dist/async/concurrency.d.ts +92 -0
- package/dist/async/concurrency.js +2 -0
- package/dist/async/control.d.ts +77 -0
- package/dist/async/control.js +2 -0
- package/dist/async/index.d.ts +8 -0
- package/dist/async/index.js +2 -0
- package/dist/async/signal.d.ts +95 -0
- package/dist/async/signal.js +2 -0
- package/dist/boolean/index.d.ts +83 -0
- package/dist/boolean/index.js +2 -0
- package/dist/business-calendar/days.d.ts +397 -0
- package/dist/business-calendar/days.js +2 -0
- package/dist/business-calendar/describe.d.ts +45 -0
- package/dist/business-calendar/describe.js +2 -0
- package/dist/business-calendar/engine.d.ts +305 -0
- package/dist/business-calendar/engine.js +2 -0
- package/dist/business-calendar/hours.d.ts +96 -0
- package/dist/business-calendar/hours.js +2 -0
- package/dist/business-calendar/index.d.ts +29 -0
- package/dist/business-calendar/index.js +2 -0
- package/dist/business-calendar/internal.d.ts +44 -0
- package/dist/business-calendar/internal.js +2 -0
- package/dist/business-calendar/rules.d.ts +260 -0
- package/dist/business-calendar/rules.js +2 -0
- package/dist/color/index.d.ts +200 -0
- package/dist/color/index.js +2 -0
- package/dist/color/named.d.ts +4 -0
- package/dist/color/named.js +2 -0
- package/dist/compare/index.d.ts +186 -0
- package/dist/compare/index.js +2 -0
- package/dist/convert/index.d.ts +152 -0
- package/dist/convert/index.js +2 -0
- package/dist/csv/index.d.ts +6 -0
- package/dist/csv/index.js +2 -0
- package/dist/csv/parse.d.ts +85 -0
- package/dist/csv/parse.js +12 -0
- package/dist/csv/stringify.d.ts +48 -0
- package/dist/csv/stringify.js +5 -0
- package/dist/date/calendar.d.ts +339 -0
- package/dist/date/calendar.js +2 -0
- package/dist/date/format.d.ts +66 -0
- package/dist/date/format.js +2 -0
- package/dist/date/index.d.ts +26 -0
- package/dist/date/index.js +2 -0
- package/dist/date/intervals.d.ts +110 -0
- package/dist/date/intervals.js +2 -0
- package/dist/date/intl-cache.d.ts +10 -0
- package/dist/date/intl-cache.js +2 -0
- package/dist/date/locale.d.ts +58 -0
- package/dist/date/locale.js +2 -0
- package/dist/date/plain-date.d.ts +105 -0
- package/dist/date/plain-date.js +2 -0
- package/dist/date/plain-time.d.ts +121 -0
- package/dist/date/plain-time.js +2 -0
- package/dist/date/zone.d.ts +121 -0
- package/dist/date/zone.js +2 -0
- package/dist/decimal/index.d.ts +149 -0
- package/dist/decimal/index.js +2 -0
- package/dist/ds/avl.d.ts +50 -0
- package/dist/ds/avl.js +2 -0
- package/dist/ds/bitset.d.ts +46 -0
- package/dist/ds/bitset.js +2 -0
- package/dist/ds/bloom.d.ts +41 -0
- package/dist/ds/bloom.js +2 -0
- package/dist/ds/caches.d.ts +141 -0
- package/dist/ds/caches.js +2 -0
- package/dist/ds/disjoint-set.d.ts +38 -0
- package/dist/ds/disjoint-set.js +2 -0
- package/dist/ds/emitter.d.ts +53 -0
- package/dist/ds/emitter.js +2 -0
- package/dist/ds/graph.d.ts +84 -0
- package/dist/ds/graph.js +2 -0
- package/dist/ds/heap.d.ts +49 -0
- package/dist/ds/heap.js +2 -0
- package/dist/ds/index.d.ts +20 -0
- package/dist/ds/index.js +2 -0
- package/dist/ds/internal.d.ts +19 -0
- package/dist/ds/internal.js +2 -0
- package/dist/ds/interval-tree.d.ts +49 -0
- package/dist/ds/interval-tree.js +2 -0
- package/dist/ds/linked-list.d.ts +54 -0
- package/dist/ds/linked-list.js +2 -0
- package/dist/ds/maps.d.ts +89 -0
- package/dist/ds/maps.js +2 -0
- package/dist/ds/ring.d.ts +99 -0
- package/dist/ds/ring.js +2 -0
- package/dist/ds/sorted.d.ts +104 -0
- package/dist/ds/sorted.js +2 -0
- package/dist/ds/stack.d.ts +28 -0
- package/dist/ds/stack.js +2 -0
- package/dist/ds/trie.d.ts +84 -0
- package/dist/ds/trie.js +2 -0
- package/dist/duration/index.d.ts +146 -0
- package/dist/duration/index.js +2 -0
- package/dist/encoding/index.d.ts +144 -0
- package/dist/encoding/index.js +2 -0
- package/dist/error/index.d.ts +316 -0
- package/dist/error/index.js +2 -0
- package/dist/fn/index.d.ts +129 -0
- package/dist/fn/index.js +2 -0
- package/dist/fn/memo.d.ts +46 -0
- package/dist/fn/memo.js +2 -0
- package/dist/fn/timing.d.ts +64 -0
- package/dist/fn/timing.js +2 -0
- package/dist/http/headers.d.ts +160 -0
- package/dist/http/headers.js +2 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/index.js +2 -0
- package/dist/http/problem.d.ts +37 -0
- package/dist/http/problem.js +2 -0
- package/dist/http/response.d.ts +43 -0
- package/dist/http/response.js +2 -0
- package/dist/http/status.d.ts +169 -0
- package/dist/http/status.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -0
- package/dist/internal/keys.d.ts +6 -0
- package/dist/internal/keys.js +2 -0
- package/dist/is/index.d.ts +219 -0
- package/dist/is/index.js +2 -0
- package/dist/json/index.d.ts +9 -0
- package/dist/json/index.js +2 -0
- package/dist/json/internal.d.ts +12 -0
- package/dist/json/internal.js +2 -0
- package/dist/json/ndjson.d.ts +28 -0
- package/dist/json/ndjson.js +4 -0
- package/dist/json/parse.d.ts +45 -0
- package/dist/json/parse.js +2 -0
- package/dist/json/patch.d.ts +62 -0
- package/dist/json/patch.js +2 -0
- package/dist/json/pointer.d.ts +43 -0
- package/dist/json/pointer.js +2 -0
- package/dist/json/stringify.d.ts +42 -0
- package/dist/json/stringify.js +2 -0
- package/dist/linq/enumerable.d.ts +208 -0
- package/dist/linq/enumerable.js +2 -0
- package/dist/linq/index.d.ts +6 -0
- package/dist/linq/index.js +2 -0
- package/dist/linq/operators.d.ts +503 -0
- package/dist/linq/operators.js +2 -0
- package/dist/number/core.d.ts +164 -0
- package/dist/number/core.js +2 -0
- package/dist/number/format.d.ts +80 -0
- package/dist/number/format.js +2 -0
- package/dist/number/index.d.ts +12 -0
- package/dist/number/index.js +2 -0
- package/dist/number/internal.d.ts +18 -0
- package/dist/number/internal.js +2 -0
- package/dist/number/parse.d.ts +45 -0
- package/dist/number/parse.js +2 -0
- package/dist/number/words.d.ts +19 -0
- package/dist/number/words.js +2 -0
- package/dist/object/basic.d.ts +130 -0
- package/dist/object/basic.js +2 -0
- package/dist/object/deep.d.ts +90 -0
- package/dist/object/deep.js +2 -0
- package/dist/object/diff.d.ts +57 -0
- package/dist/object/diff.js +2 -0
- package/dist/object/index.d.ts +8 -0
- package/dist/object/index.js +2 -0
- package/dist/object/internal.d.ts +21 -0
- package/dist/object/internal.js +2 -0
- package/dist/object/path.d.ts +17 -0
- package/dist/object/path.js +2 -0
- package/dist/random/core.d.ts +14 -0
- package/dist/random/core.js +2 -0
- package/dist/random/index.d.ts +167 -0
- package/dist/random/index.js +2 -0
- package/dist/random/seeded.d.ts +27 -0
- package/dist/random/seeded.js +2 -0
- package/dist/sanitize/index.d.ts +8 -0
- package/dist/sanitize/index.js +2 -0
- package/dist/sanitize/pii.d.ts +48 -0
- package/dist/sanitize/pii.js +2 -0
- package/dist/sanitize/records.d.ts +100 -0
- package/dist/sanitize/records.js +2 -0
- package/dist/sanitize/text.d.ts +101 -0
- package/dist/sanitize/text.js +2 -0
- package/dist/set/index.d.ts +162 -0
- package/dist/set/index.js +2 -0
- package/dist/stats/index.d.ts +190 -0
- package/dist/stats/index.js +2 -0
- package/dist/string/index.d.ts +494 -0
- package/dist/string/index.js +8 -0
- package/dist/string/internal.d.ts +33 -0
- package/dist/string/internal.js +2 -0
- package/dist/string/words.d.ts +14 -0
- package/dist/string/words.js +2 -0
- package/dist/timezone/index.d.ts +76 -0
- package/dist/timezone/index.js +2 -0
- package/dist/url/index.d.ts +178 -0
- package/dist/url/index.js +2 -0
- package/dist/validate/builders.d.ts +6 -0
- package/dist/validate/builders.js +2 -0
- package/dist/validate/formats.d.ts +237 -0
- package/dist/validate/formats.js +2 -0
- package/dist/validate/index.d.ts +13 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/schema.d.ts +220 -0
- package/dist/validate/schema.js +2 -0
- package/dist/zip/index.d.ts +8 -0
- package/dist/zip/index.js +2 -0
- package/dist/zip/internal.d.ts +69 -0
- package/dist/zip/internal.js +2 -0
- package/dist/zip/reader.d.ts +56 -0
- package/dist/zip/reader.js +2 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/writer.js +2 -0
- package/package.json +150 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP status codes, methods and user-facing messages (RFC 9110). Pure data; no fetch.
|
|
3
|
+
*/
|
|
4
|
+
/** Named status codes (RFC 9110 and registered extensions). @example httpStatus.NOT_FOUND // => 404 */
|
|
5
|
+
export declare const httpStatus: Readonly<{
|
|
6
|
+
readonly CONTINUE: 100;
|
|
7
|
+
readonly SWITCHING_PROTOCOLS: 101;
|
|
8
|
+
readonly PROCESSING: 102;
|
|
9
|
+
readonly EARLY_HINTS: 103;
|
|
10
|
+
readonly OK: 200;
|
|
11
|
+
readonly CREATED: 201;
|
|
12
|
+
readonly ACCEPTED: 202;
|
|
13
|
+
readonly NON_AUTHORITATIVE_INFORMATION: 203;
|
|
14
|
+
readonly NO_CONTENT: 204;
|
|
15
|
+
readonly RESET_CONTENT: 205;
|
|
16
|
+
readonly PARTIAL_CONTENT: 206;
|
|
17
|
+
readonly MULTI_STATUS: 207;
|
|
18
|
+
readonly ALREADY_REPORTED: 208;
|
|
19
|
+
readonly IM_USED: 226;
|
|
20
|
+
readonly MULTIPLE_CHOICES: 300;
|
|
21
|
+
readonly MOVED_PERMANENTLY: 301;
|
|
22
|
+
readonly FOUND: 302;
|
|
23
|
+
readonly SEE_OTHER: 303;
|
|
24
|
+
readonly NOT_MODIFIED: 304;
|
|
25
|
+
readonly USE_PROXY: 305;
|
|
26
|
+
readonly TEMPORARY_REDIRECT: 307;
|
|
27
|
+
readonly PERMANENT_REDIRECT: 308;
|
|
28
|
+
readonly BAD_REQUEST: 400;
|
|
29
|
+
readonly UNAUTHORIZED: 401;
|
|
30
|
+
readonly PAYMENT_REQUIRED: 402;
|
|
31
|
+
readonly FORBIDDEN: 403;
|
|
32
|
+
readonly NOT_FOUND: 404;
|
|
33
|
+
readonly METHOD_NOT_ALLOWED: 405;
|
|
34
|
+
readonly NOT_ACCEPTABLE: 406;
|
|
35
|
+
readonly PROXY_AUTHENTICATION_REQUIRED: 407;
|
|
36
|
+
readonly REQUEST_TIMEOUT: 408;
|
|
37
|
+
readonly CONFLICT: 409;
|
|
38
|
+
readonly GONE: 410;
|
|
39
|
+
readonly LENGTH_REQUIRED: 411;
|
|
40
|
+
readonly PRECONDITION_FAILED: 412;
|
|
41
|
+
readonly CONTENT_TOO_LARGE: 413;
|
|
42
|
+
readonly URI_TOO_LONG: 414;
|
|
43
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
44
|
+
readonly RANGE_NOT_SATISFIABLE: 416;
|
|
45
|
+
readonly EXPECTATION_FAILED: 417;
|
|
46
|
+
readonly IM_A_TEAPOT: 418;
|
|
47
|
+
readonly MISDIRECTED_REQUEST: 421;
|
|
48
|
+
readonly UNPROCESSABLE_CONTENT: 422;
|
|
49
|
+
readonly LOCKED: 423;
|
|
50
|
+
readonly FAILED_DEPENDENCY: 424;
|
|
51
|
+
readonly TOO_EARLY: 425;
|
|
52
|
+
readonly UPGRADE_REQUIRED: 426;
|
|
53
|
+
readonly PRECONDITION_REQUIRED: 428;
|
|
54
|
+
readonly TOO_MANY_REQUESTS: 429;
|
|
55
|
+
readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
|
|
56
|
+
readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
|
|
57
|
+
readonly INTERNAL_SERVER_ERROR: 500;
|
|
58
|
+
readonly NOT_IMPLEMENTED: 501;
|
|
59
|
+
readonly BAD_GATEWAY: 502;
|
|
60
|
+
readonly SERVICE_UNAVAILABLE: 503;
|
|
61
|
+
readonly GATEWAY_TIMEOUT: 504;
|
|
62
|
+
readonly HTTP_VERSION_NOT_SUPPORTED: 505;
|
|
63
|
+
readonly VARIANT_ALSO_NEGOTIATES: 506;
|
|
64
|
+
readonly INSUFFICIENT_STORAGE: 507;
|
|
65
|
+
readonly LOOP_DETECTED: 508;
|
|
66
|
+
readonly NOT_EXTENDED: 510;
|
|
67
|
+
readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
68
|
+
}>;
|
|
69
|
+
export type HttpStatusName = keyof typeof httpStatus;
|
|
70
|
+
/**
|
|
71
|
+
* Standard reason phrase, or `''` for unregistered codes.
|
|
72
|
+
* @example statusText(404) // => 'Not Found'
|
|
73
|
+
*/
|
|
74
|
+
export declare function statusText(status: number): string;
|
|
75
|
+
/** 1xx. @example isInformational(103) // => true */
|
|
76
|
+
export declare function isInformational(status: number): boolean;
|
|
77
|
+
/** 2xx. @example isSuccess(204) // => true */
|
|
78
|
+
export declare function isSuccess(status: number): boolean;
|
|
79
|
+
/** 3xx. @example isRedirect(302) // => true */
|
|
80
|
+
export declare function isRedirect(status: number): boolean;
|
|
81
|
+
/** 4xx. @example isClientError(404) // => true */
|
|
82
|
+
export declare function isClientError(status: number): boolean;
|
|
83
|
+
/** 5xx. @example isServerError(503) // => true */
|
|
84
|
+
export declare function isServerError(status: number): boolean;
|
|
85
|
+
/** Statuses retried by default: 408, 425, 429, 500, 502, 503, 504. @example DEFAULT_RETRYABLE_STATUSES.has(503) // => true */
|
|
86
|
+
export declare const DEFAULT_RETRYABLE_STATUSES: ReadonlySet<number>;
|
|
87
|
+
/**
|
|
88
|
+
* True when a request that failed with `status` may succeed if retried. Combine with
|
|
89
|
+
* {@link isIdempotentMethod}: never blindly retry a POST.
|
|
90
|
+
* @example isRetryableStatus(503) // => true
|
|
91
|
+
*/
|
|
92
|
+
export declare function isRetryableStatus(status: number, retryable?: ReadonlySet<number> | readonly number[]): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* RFC 9110 section 9.2.2 idempotent methods: GET, HEAD, OPTIONS, TRACE, PUT, DELETE (case-insensitive).
|
|
95
|
+
* @example isIdempotentMethod('put') // => true
|
|
96
|
+
*/
|
|
97
|
+
export declare function isIdempotentMethod(method: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* RFC 9110 section 9.2.1 safe (read-only) methods: GET, HEAD, OPTIONS, TRACE.
|
|
100
|
+
* @example isSafeMethod('POST') // => false
|
|
101
|
+
*/
|
|
102
|
+
export declare function isSafeMethod(method: string): boolean;
|
|
103
|
+
/** Replacement messages by status; return `undefined` to fall back to the defaults. */
|
|
104
|
+
export type StatusMessageCatalog = (status: number) => string | undefined;
|
|
105
|
+
/** Messages keyed by status code, for translation files and overrides. */
|
|
106
|
+
export type StatusMessages = Readonly<Partial<Record<number, string>>>;
|
|
107
|
+
/**
|
|
108
|
+
* Plain-language English message for every registered status code, plus `0` (network failure),
|
|
109
|
+
* for alerts, toasts, and error summaries. Frozen; copy it as the starting point of a translation.
|
|
110
|
+
* @example DEFAULT_STATUS_MESSAGES[404] // => 'The item could not be found. It may have been moved or deleted.'
|
|
111
|
+
* @example Object.keys(DEFAULT_STATUS_MESSAGES).length // => 63
|
|
112
|
+
*/
|
|
113
|
+
export declare const DEFAULT_STATUS_MESSAGES: StatusMessages;
|
|
114
|
+
/** Status class of a code; `network` for 0 (no response). */
|
|
115
|
+
export type StatusClass = 'network' | 'informational' | 'success' | 'redirect' | 'client-error' | 'server-error' | 'unknown';
|
|
116
|
+
/**
|
|
117
|
+
* Status class of a code.
|
|
118
|
+
* @example statusClass(0) // => 'network'
|
|
119
|
+
* @example statusClass(422) // => 'client-error'
|
|
120
|
+
*/
|
|
121
|
+
export declare function statusClass(status: number): StatusClass;
|
|
122
|
+
/**
|
|
123
|
+
* Plain-language message for a status (0 = network failure). `catalog` entries win; then
|
|
124
|
+
* {@link DEFAULT_STATUS_MESSAGES}; then a message for the status class.
|
|
125
|
+
* @example userMessageForStatus(503) // => 'The service is temporarily unavailable. Try again in a few minutes.'
|
|
126
|
+
* @example
|
|
127
|
+
* userMessageForStatus(404, (s) => (s === 404 ? 'No such employee.' : undefined)); // => 'No such employee.'
|
|
128
|
+
* userMessageForStatus(499); // => 'The request could not be completed. Check the information and try again.'
|
|
129
|
+
*/
|
|
130
|
+
export declare function userMessageForStatus(status: number, catalog?: StatusMessageCatalog): string;
|
|
131
|
+
/**
|
|
132
|
+
* Catalog from a messages object.
|
|
133
|
+
* @example
|
|
134
|
+
* const catalog = statusMessageCatalog({ 404: 'No such employee.' });
|
|
135
|
+
* [catalog(404), catalog(500)]; // => ['No such employee.', undefined]
|
|
136
|
+
*/
|
|
137
|
+
export declare function statusMessageCatalog(messages: StatusMessages): StatusMessageCatalog;
|
|
138
|
+
/**
|
|
139
|
+
* Catalog for a locale from per-locale message objects, falling back from the full tag to its
|
|
140
|
+
* language (`fr-CA` -> `fr`). Missing entries fall through to the English defaults.
|
|
141
|
+
* @example
|
|
142
|
+
* const catalog = localizedStatusMessages({ fr: { 404: 'Élément introuvable.' } }, 'fr-CA');
|
|
143
|
+
* userMessageForStatus(404, catalog); // => 'Élément introuvable.'
|
|
144
|
+
* userMessageForStatus(503, catalog); // => 'The service is temporarily unavailable. Try again in a few minutes.'
|
|
145
|
+
*/
|
|
146
|
+
export declare function localizedStatusMessages(catalogs: Readonly<Record<string, StatusMessages>>, locale: string): StatusMessageCatalog;
|
|
147
|
+
/**
|
|
148
|
+
* One catalog from several; the first that defines a status wins.
|
|
149
|
+
* @example
|
|
150
|
+
* const app = composeStatusMessages(statusMessageCatalog({ 404: 'No such employee.' }), statusMessageCatalog({ 404: 'Not here.', 409: 'Someone else saved first.' }));
|
|
151
|
+
* [app(404), app(409), app(500)]; // => ['No such employee.', 'Someone else saved first.', undefined]
|
|
152
|
+
*/
|
|
153
|
+
export declare function composeStatusMessages(...catalogs: readonly (StatusMessageCatalog | undefined)[]): StatusMessageCatalog;
|
|
154
|
+
/** Everything a UI needs to describe a status. */
|
|
155
|
+
export interface StatusDescription {
|
|
156
|
+
readonly status: number;
|
|
157
|
+
/** Standard reason phrase, `''` when unregistered. */
|
|
158
|
+
readonly reason: string;
|
|
159
|
+
/** Plain-language message (`userMessageForStatus`). */
|
|
160
|
+
readonly message: string;
|
|
161
|
+
readonly statusClass: StatusClass;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Reason phrase, message, and class of a status.
|
|
165
|
+
* @example
|
|
166
|
+
* describeStatus(429);
|
|
167
|
+
* // => { status: 429, reason: 'Too Many Requests', message: 'Too many requests. Wait a moment and try again.', statusClass: 'client-error' }
|
|
168
|
+
*/
|
|
169
|
+
export declare function describeStatus(status: number, catalog?: StatusMessageCatalog): StatusDescription;
|
|
@@ -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 C=Object.freeze({CONTINUE:100,SWITCHING_PROTOCOLS:101,PROCESSING:102,EARLY_HINTS:103,OK:200,CREATED:201,ACCEPTED:202,NON_AUTHORITATIVE_INFORMATION:203,NO_CONTENT:204,RESET_CONTENT:205,PARTIAL_CONTENT:206,MULTI_STATUS:207,ALREADY_REPORTED:208,IM_USED:226,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,USE_PROXY:305,TEMPORARY_REDIRECT:307,PERMANENT_REDIRECT:308,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,CONTENT_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,IM_A_TEAPOT:418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_CONTENT:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511}),l=new Map([[100,"Continue"],[101,"Switching Protocols"],[102,"Processing"],[103,"Early Hints"],[200,"OK"],[201,"Created"],[202,"Accepted"],[203,"Non-Authoritative Information"],[204,"No Content"],[205,"Reset Content"],[206,"Partial Content"],[207,"Multi-Status"],[208,"Already Reported"],[226,"IM Used"],[300,"Multiple Choices"],[301,"Moved Permanently"],[302,"Found"],[303,"See Other"],[304,"Not Modified"],[305,"Use Proxy"],[307,"Temporary Redirect"],[308,"Permanent Redirect"],[400,"Bad Request"],[401,"Unauthorized"],[402,"Payment Required"],[403,"Forbidden"],[404,"Not Found"],[405,"Method Not Allowed"],[406,"Not Acceptable"],[407,"Proxy Authentication Required"],[408,"Request Timeout"],[409,"Conflict"],[410,"Gone"],[411,"Length Required"],[412,"Precondition Failed"],[413,"Content Too Large"],[414,"URI Too Long"],[415,"Unsupported Media Type"],[416,"Range Not Satisfiable"],[417,"Expectation Failed"],[418,"I'm a teapot"],[421,"Misdirected Request"],[422,"Unprocessable Content"],[423,"Locked"],[424,"Failed Dependency"],[425,"Too Early"],[426,"Upgrade Required"],[428,"Precondition Required"],[429,"Too Many Requests"],[431,"Request Header Fields Too Large"],[451,"Unavailable For Legal Reasons"],[500,"Internal Server Error"],[501,"Not Implemented"],[502,"Bad Gateway"],[503,"Service Unavailable"],[504,"Gateway Timeout"],[505,"HTTP Version Not Supported"],[506,"Variant Also Negotiates"],[507,"Insufficient Storage"],[508,"Loop Detected"],[510,"Not Extended"],[511,"Network Authentication Required"]]);function E(e){return l.get(e)??""}const o=(e,t)=>Number.isInteger(e)&&e>=t&&e<t+100;function h(e){return o(e,100)}function g(e){return o(e,200)}function p(e){return o(e,300)}function R(e){return o(e,400)}function m(e){return o(e,500)}const S=new Set([408,425,429,500,502,503,504]);function _(e,t=S){return Array.isArray(t)?t.includes(e):t.has(e)}const s=new Set(["GET","HEAD","OPTIONS","TRACE"]),f=new Set([...s,"PUT","DELETE"]);function I(e){return f.has(e.toUpperCase())}function D(e){return s.has(e.toUpperCase())}const d=Object.freeze({0:"Unable to connect. Check your internet connection and try again.",100:"The server is ready to receive the rest of the request.",101:"The connection is switching to a different protocol.",102:"The server is still processing the request.",103:"The server is preparing the response.",200:"Done.",201:"Created.",202:"Accepted. It will be processed shortly.",203:"Done. The information came from another source and may differ from the original.",204:"Done.",205:"Done. Clear the form to continue.",206:"Part of the content was returned.",207:"Done. Some parts have their own results.",208:"Done. Some items were already included.",226:"Done.",300:"Several versions are available. Choose one to continue.",301:"This item has moved to a new address.",302:"This item is temporarily at a different address.",303:"The result is available at a different address.",304:"The item has not changed.",305:"This item must be accessed through a proxy.",307:"This item is temporarily at a different address.",308:"This item has moved to a new address.",400:"Some of the information is not valid. Check it and try again.",401:"Your session has ended. Sign in again to continue.",402:"Payment is required to do this.",403:"You do not have permission to do this. Contact your administrator if you need access.",404:"The item could not be found. It may have been moved or deleted.",405:"This action is not available. Reload the page and try again.",406:"The server cannot provide this in a supported format.",407:"Sign in to the proxy server to continue.",408:"The request took too long. Check your connection and try again.",409:"This item was changed by someone else. Reload it and try again.",410:"This item is no longer available.",411:"The request was incomplete. Try again.",412:"This item was changed by someone else. Reload it and try again.",413:"The file or data is too large. Reduce its size and try again.",414:"The request is too long. Shorten your search or filters and try again.",415:"This file type is not supported. Choose a different file and try again.",416:"The requested part of the file is not available.",417:"The server could not meet the requirements of the request. Try again.",418:"The server cannot do this.",421:"The request reached the wrong server. Try again.",422:"Some of the information is not valid. Check it and try again.",423:"This item is locked. Try again later or contact the person who is editing it.",424:"This could not be completed because a related action failed.",425:"The server is not ready to process this yet. Try again.",426:"This needs a newer connection. Update your browser or app and try again.",428:"Reload this item before changing it, then try again.",429:"Too many requests. Wait a moment and try again.",431:"The request is too large. Clear the cookies for this site and try again.",451:"This content is not available for legal reasons.",500:"Something went wrong on our side. Try again later.",501:"This action is not supported.",502:"The service is temporarily unavailable. Try again in a few minutes.",503:"The service is temporarily unavailable. Try again in a few minutes.",504:"The service is taking too long to respond. Try again in a few minutes.",505:"The server does not support this connection. Try again later.",506:"The server is not set up correctly. Try again later.",507:"The server is out of storage. Try again later.",508:"The server stopped processing this request. Try again later.",510:"The server needs more information to complete this.",511:"Sign in to the network (for example, a Wi-Fi sign-in page) to continue."});function u(e){return e===0?"network":h(e)?"informational":g(e)?"success":p(e)?"redirect":R(e)?"client-error":m(e)?"server-error":"unknown"}const y={network:d[0]??"",informational:"The request is in progress.",success:"Done.",redirect:"This item is at a different address.","client-error":"The request could not be completed. Check the information and try again.","server-error":"Something went wrong on our side. Try again later.",unknown:"Something unexpected happened. Try again."};function N(e,t){const n=t?.(e);return n!==void 0?n:d[e]??y[u(e)]}function O(e){return t=>Object.hasOwn(e,t)?e[t]:void 0}function b(e,t){const n=[],r=t.split("-");for(let a=r.length;a>0;a--){const T=r.slice(0,a).join("-"),i=Object.entries(e).find(([c])=>c.toLowerCase()===T.toLowerCase());i&&n.push(i[1])}return A(...n.map(O))}function A(...e){return t=>{for(const n of e){const r=n?.(t);if(r!==void 0)return r}}}function U(e,t){return{status:e,reason:E(e),message:N(e,t),statusClass:u(e)}}export{S as DEFAULT_RETRYABLE_STATUSES,d as DEFAULT_STATUS_MESSAGES,A as composeStatusMessages,U as describeStatus,C as httpStatus,R as isClientError,I as isIdempotentMethod,h as isInformational,p as isRedirect,_ as isRetryableStatus,D as isSafeMethod,m as isServerError,g as isSuccess,b as localizedStatusMessages,u as statusClass,O as statusMessageCatalog,E as statusText,N as userMessageForStatus};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Root entry: every module as a namespace (`import { date } from '@absoluteui/helpers'`).
|
|
3
|
+
* Prefer subpath imports (`@absoluteui/helpers/date`) for the smallest bundles.
|
|
4
|
+
*/
|
|
5
|
+
export * as is from './is/index.js';
|
|
6
|
+
export * as convert from './convert/index.js';
|
|
7
|
+
export * as error from './error/index.js';
|
|
8
|
+
export * as array from './array/index.js';
|
|
9
|
+
export * as set from './set/index.js';
|
|
10
|
+
export * as object from './object/index.js';
|
|
11
|
+
export * as linq from './linq/index.js';
|
|
12
|
+
export * as string from './string/index.js';
|
|
13
|
+
export * as number from './number/index.js';
|
|
14
|
+
export * as decimal from './decimal/index.js';
|
|
15
|
+
export * as stats from './stats/index.js';
|
|
16
|
+
export * as boolean from './boolean/index.js';
|
|
17
|
+
export * as compare from './compare/index.js';
|
|
18
|
+
export * as random from './random/index.js';
|
|
19
|
+
export * as encoding from './encoding/index.js';
|
|
20
|
+
export * as zip from './zip/index.js';
|
|
21
|
+
export * as url from './url/index.js';
|
|
22
|
+
export * as color from './color/index.js';
|
|
23
|
+
export * as json from './json/index.js';
|
|
24
|
+
export * as csv from './csv/index.js';
|
|
25
|
+
export * as validate from './validate/index.js';
|
|
26
|
+
export * as sanitize from './sanitize/index.js';
|
|
27
|
+
export * as http from './http/index.js';
|
|
28
|
+
export * as fn from './fn/index.js';
|
|
29
|
+
export * as async from './async/index.js';
|
|
30
|
+
export * as ds from './ds/index.js';
|
|
31
|
+
export * as date from './date/index.js';
|
|
32
|
+
export * as timezone from './timezone/index.js';
|
|
33
|
+
export * as duration from './duration/index.js';
|
|
34
|
+
export * as businessCalendar from './business-calendar/index.js';
|
package/dist/index.js
ADDED
|
@@ -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*as o from"./is/index.js";import*as e from"./convert/index.js";import*as a from"./error/index.js";import*as s from"./array/index.js";import*as t from"./set/index.js";import*as m from"./object/index.js";import*as p from"./linq/index.js";import*as f from"./string/index.js";import*as x from"./number/index.js";import*as n from"./decimal/index.js";import*as i from"./stats/index.js";import*as c from"./boolean/index.js";import*as d from"./compare/index.js";import*as l from"./random/index.js";import*as b from"./encoding/index.js";import*as u from"./zip/index.js";import*as v from"./url/index.js";import*as z from"./color/index.js";import*as g from"./json/index.js";import*as j from"./csv/index.js";import*as y from"./validate/index.js";import*as h from"./sanitize/index.js";import*as q from"./http/index.js";import*as C from"./fn/index.js";import*as k from"./async/index.js";import*as w from"./ds/index.js";import*as A from"./date/index.js";import*as B from"./timezone/index.js";import*as D from"./duration/index.js";import*as E from"./business-calendar/index.js";export{s as array,k as async,c as boolean,E as businessCalendar,z as color,d as compare,e as convert,j as csv,A as date,n as decimal,w as ds,D as duration,b as encoding,a as error,C as fn,q as http,o as is,g as json,p as linq,x as number,m as object,l as random,h as sanitize,t as set,i as stats,f as string,B as timezone,v as url,y as validate,u as zip};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** True for keys that must never be written through a dynamic path. */
|
|
2
|
+
export declare function isUnsafeKey(key: PropertyKey): boolean;
|
|
3
|
+
/** Throws `HLP_UNSAFE_KEY` for `__proto__`, `constructor`, and `prototype`. */
|
|
4
|
+
export declare function assertSafeKey(key: PropertyKey): void;
|
|
5
|
+
/** Own enumerable property check that works for null-prototype objects. */
|
|
6
|
+
export declare function hasOwn(obj: object, key: PropertyKey): boolean;
|
|
@@ -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{ValidationError as t}from"../error/index.js";const r=new Set(["__proto__","constructor","prototype"]);function n(o){return typeof o=="string"&&r.has(o)}function a(o){if(n(o))throw new t("HLP_UNSAFE_KEY","Refusing to use an unsafe object key.")}function s(o,e){return Object.prototype.hasOwnProperty.call(o,e)}export{a as assertSafeKey,s as hasOwn,n as isUnsafeKey};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/** `null` or `undefined`. @example isNil(undefined) // => true */
|
|
2
|
+
export declare function isNil(value: unknown): value is null | undefined;
|
|
3
|
+
/**
|
|
4
|
+
* Neither `null` nor `undefined`. Useful as a filter: `arr.filter(isDefined)`.
|
|
5
|
+
* @example
|
|
6
|
+
* [1, null, 2, undefined].filter(isDefined); // => [1, 2]
|
|
7
|
+
*/
|
|
8
|
+
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* isString('EMP-001'); // => true
|
|
12
|
+
*/
|
|
13
|
+
export declare function isString(value: unknown): value is string;
|
|
14
|
+
/**
|
|
15
|
+
* Any `number`, including `NaN` and `Infinity`. Prefer `isFiniteNumber`.
|
|
16
|
+
* @example
|
|
17
|
+
* isNumber(NaN); // => true
|
|
18
|
+
*/
|
|
19
|
+
export declare function isNumber(value: unknown): value is number;
|
|
20
|
+
/** A number that is not `NaN` or `±Infinity`. @example isFiniteNumber(NaN) // => false */
|
|
21
|
+
export declare function isFiniteNumber(value: unknown): value is number;
|
|
22
|
+
/**
|
|
23
|
+
* @example
|
|
24
|
+
* isInteger(40.5); // => false
|
|
25
|
+
*/
|
|
26
|
+
export declare function isInteger(value: unknown): value is number;
|
|
27
|
+
/**
|
|
28
|
+
* Integer within `Number.MIN_SAFE_INTEGER..MAX_SAFE_INTEGER`.
|
|
29
|
+
* @example
|
|
30
|
+
* isSafeInteger(2 ** 53); // => false
|
|
31
|
+
*/
|
|
32
|
+
export declare function isSafeInteger(value: unknown): value is number;
|
|
33
|
+
/**
|
|
34
|
+
* @example
|
|
35
|
+
* isBigInt(10n); // => true
|
|
36
|
+
*/
|
|
37
|
+
export declare function isBigInt(value: unknown): value is bigint;
|
|
38
|
+
/**
|
|
39
|
+
* @example
|
|
40
|
+
* isBoolean('true'); // => false
|
|
41
|
+
*/
|
|
42
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
43
|
+
/**
|
|
44
|
+
* @example
|
|
45
|
+
* isSymbol(Symbol.iterator); // => true
|
|
46
|
+
*/
|
|
47
|
+
export declare function isSymbol(value: unknown): value is symbol;
|
|
48
|
+
/**
|
|
49
|
+
* @example
|
|
50
|
+
* isFunction(() => 1); // => true
|
|
51
|
+
*/
|
|
52
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
53
|
+
/**
|
|
54
|
+
* Any non-null object, including arrays.
|
|
55
|
+
* @example
|
|
56
|
+
* isObject([]); // => true
|
|
57
|
+
*/
|
|
58
|
+
export declare function isObject(value: unknown): value is object;
|
|
59
|
+
/**
|
|
60
|
+
* Object literal or `Object.create(null)`; not arrays, dates, maps, class instances.
|
|
61
|
+
* @example
|
|
62
|
+
* isPlainObject({ id: 1 }); // => true
|
|
63
|
+
* isPlainObject(new Date()); // => false
|
|
64
|
+
*/
|
|
65
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
66
|
+
/**
|
|
67
|
+
* @example
|
|
68
|
+
* isArray('abc'); // => false
|
|
69
|
+
*/
|
|
70
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
71
|
+
/**
|
|
72
|
+
* Non-empty array with a narrowed tuple type.
|
|
73
|
+
* @example
|
|
74
|
+
* const ids: number[] = [7, 9];
|
|
75
|
+
* if (isNonEmptyArray(ids)) ids[0].toFixed(); // first element typed as number
|
|
76
|
+
* isNonEmptyArray([]); // => false
|
|
77
|
+
*/
|
|
78
|
+
export declare function isNonEmptyArray<T>(value: readonly T[] | null | undefined): value is readonly [T, ...T[]];
|
|
79
|
+
/**
|
|
80
|
+
* Any valid `Date` (not `Invalid Date`).
|
|
81
|
+
* @example
|
|
82
|
+
* isValidDate(new Date('2026-13-45')); // => false
|
|
83
|
+
*/
|
|
84
|
+
export declare function isValidDate(value: unknown): value is Date;
|
|
85
|
+
/**
|
|
86
|
+
* @example
|
|
87
|
+
* isDate(new Date(NaN)); // => true
|
|
88
|
+
*/
|
|
89
|
+
export declare function isDate(value: unknown): value is Date;
|
|
90
|
+
/**
|
|
91
|
+
* @example
|
|
92
|
+
* isRegExp(/^EMP-/); // => true
|
|
93
|
+
*/
|
|
94
|
+
export declare function isRegExp(value: unknown): value is RegExp;
|
|
95
|
+
/**
|
|
96
|
+
* @example
|
|
97
|
+
* isMap(new Map()); // => true
|
|
98
|
+
*/
|
|
99
|
+
export declare function isMap(value: unknown): value is Map<unknown, unknown>;
|
|
100
|
+
/**
|
|
101
|
+
* @example
|
|
102
|
+
* isSet(new Set([1])); // => true
|
|
103
|
+
*/
|
|
104
|
+
export declare function isSet(value: unknown): value is Set<unknown>;
|
|
105
|
+
/**
|
|
106
|
+
* @example
|
|
107
|
+
* isError(new TypeError('Bad input.')); // => true
|
|
108
|
+
*/
|
|
109
|
+
export declare function isError(value: unknown): value is Error;
|
|
110
|
+
/**
|
|
111
|
+
* Has a callable `then`.
|
|
112
|
+
* @example
|
|
113
|
+
* isPromiseLike(Promise.resolve(1)); // => true
|
|
114
|
+
* isPromiseLike({ then: 1 }); // => false
|
|
115
|
+
*/
|
|
116
|
+
export declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
|
|
117
|
+
/**
|
|
118
|
+
* Implements `Symbol.iterator` (strings included).
|
|
119
|
+
* @example
|
|
120
|
+
* isIterable('abc'); // => true
|
|
121
|
+
* isIterable({}); // => false
|
|
122
|
+
*/
|
|
123
|
+
export declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* @example
|
|
126
|
+
* async function* rows() { yield 1; }
|
|
127
|
+
* isAsyncIterable(rows()); // => true
|
|
128
|
+
*/
|
|
129
|
+
export declare function isAsyncIterable(value: unknown): value is AsyncIterable<unknown>;
|
|
130
|
+
/**
|
|
131
|
+
* `ArrayBuffer`, typed array, or `DataView`.
|
|
132
|
+
* @example
|
|
133
|
+
* isBinary(new Uint8Array(4)); // => true
|
|
134
|
+
*/
|
|
135
|
+
export declare function isBinary(value: unknown): value is ArrayBuffer | ArrayBufferView;
|
|
136
|
+
/**
|
|
137
|
+
* `string | number | boolean | bigint | symbol | null | undefined`.
|
|
138
|
+
* @example
|
|
139
|
+
* isPrimitive(null); // => true
|
|
140
|
+
* isPrimitive({}); // => false
|
|
141
|
+
*/
|
|
142
|
+
export declare function isPrimitive(value: unknown): value is string | number | boolean | bigint | symbol | null | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Empty check: `null`/`undefined`, `''`, `[]`, empty `Map`/`Set`, `{}` with no own keys.
|
|
145
|
+
* Numbers and booleans are never empty.
|
|
146
|
+
* @example isEmpty({}) // => true
|
|
147
|
+
*/
|
|
148
|
+
export declare function isEmpty(value: unknown): boolean;
|
|
149
|
+
/**
|
|
150
|
+
* `null`, `undefined`, or a string with only whitespace.
|
|
151
|
+
* @example
|
|
152
|
+
* isBlank(' '); // => true
|
|
153
|
+
* isBlank(0); // => false
|
|
154
|
+
*/
|
|
155
|
+
export declare function isBlank(value: unknown): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Value is one of `options` (uses `SameValueZero`).
|
|
158
|
+
* @example
|
|
159
|
+
* const status: unknown = 'active';
|
|
160
|
+
* isOneOf(status, ['active', 'on-leave'] as const); // => true
|
|
161
|
+
*/
|
|
162
|
+
export declare function isOneOf<const T extends readonly unknown[]>(value: unknown, options: T): value is T[number];
|
|
163
|
+
/**
|
|
164
|
+
* Key exists as an own property; narrows the object type.
|
|
165
|
+
* @example
|
|
166
|
+
* const payload: unknown = JSON.parse('{"id":42}');
|
|
167
|
+
* hasKey(payload, 'id'); // => true
|
|
168
|
+
*/
|
|
169
|
+
export declare function hasKey<K extends PropertyKey>(value: unknown, key: K): value is Record<K, unknown>;
|
|
170
|
+
/**
|
|
171
|
+
* Running in a browser main thread or worker with `document` or `self`.
|
|
172
|
+
* @example
|
|
173
|
+
* isBrowserLike(); // true in a browser or worker, false in Node without a DOM
|
|
174
|
+
*/
|
|
175
|
+
export declare function isBrowserLike(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* @example
|
|
178
|
+
* const input: unknown = 'ada@example.com';
|
|
179
|
+
* assertString(input, 'input');
|
|
180
|
+
* input.toUpperCase(); // => 'ADA@EXAMPLE.COM'
|
|
181
|
+
* assertString(42, 'email'); // => throws HLP_TYPE_ASSERTION
|
|
182
|
+
*/
|
|
183
|
+
export declare function assertString(value: unknown, name?: string): asserts value is string;
|
|
184
|
+
/**
|
|
185
|
+
* @example
|
|
186
|
+
* assertFiniteNumber(Infinity, 'salary'); // => throws HLP_TYPE_ASSERTION
|
|
187
|
+
*/
|
|
188
|
+
export declare function assertFiniteNumber(value: unknown, name?: string): asserts value is number;
|
|
189
|
+
/**
|
|
190
|
+
* @example
|
|
191
|
+
* assertInteger(2.5, 'leaveDays'); // => throws HLP_TYPE_ASSERTION
|
|
192
|
+
*/
|
|
193
|
+
export declare function assertInteger(value: unknown, name?: string): asserts value is number;
|
|
194
|
+
/**
|
|
195
|
+
* @example
|
|
196
|
+
* assertBoolean('yes', 'active'); // => throws HLP_TYPE_ASSERTION
|
|
197
|
+
*/
|
|
198
|
+
export declare function assertBoolean(value: unknown, name?: string): asserts value is boolean;
|
|
199
|
+
/**
|
|
200
|
+
* @example
|
|
201
|
+
* assertPlainObject([], 'filters'); // => throws HLP_TYPE_ASSERTION
|
|
202
|
+
*/
|
|
203
|
+
export declare function assertPlainObject(value: unknown, name?: string): asserts value is Record<string, unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* @example
|
|
206
|
+
* assertArray({ length: 0 }, 'rows'); // => throws HLP_TYPE_ASSERTION
|
|
207
|
+
*/
|
|
208
|
+
export declare function assertArray(value: unknown, name?: string): asserts value is unknown[];
|
|
209
|
+
/**
|
|
210
|
+
* @example
|
|
211
|
+
* const manager: string | undefined = undefined;
|
|
212
|
+
* assertDefined(manager, 'manager'); // => throws HLP_TYPE_ASSERTION
|
|
213
|
+
*/
|
|
214
|
+
export declare function assertDefined<T>(value: T, name?: string): asserts value is NonNullable<T>;
|
|
215
|
+
/**
|
|
216
|
+
* @example
|
|
217
|
+
* assertValidDate(new Date('not a date'), 'hireDate'); // => throws HLP_TYPE_ASSERTION
|
|
218
|
+
*/
|
|
219
|
+
export declare function assertValidDate(value: unknown, name?: string): asserts value is Date;
|
package/dist/is/index.js
ADDED
|
@@ -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{ValidationError as o}from"../error/index.js";function f(n){return n==null}function a(n){return n!=null}function l(n){return typeof n=="string"}function c(n){return typeof n=="number"}function i(n){return typeof n=="number"&&Number.isFinite(n)}function p(n){return Number.isInteger(n)}function y(n){return Number.isSafeInteger(n)}function b(n){return typeof n=="bigint"}function w(n){return typeof n=="boolean"}function k(n){return typeof n=="symbol"}function g(n){return typeof n=="function"}function d(n){return typeof n=="object"&&n!==null}function r(n){if(typeof n!="object"||n===null)return!1;const e=Object.getPrototypeOf(n);return e===null||e===Object.prototype}function x(n){return Array.isArray(n)}function m(n){return Array.isArray(n)&&n.length>0}function u(n){return n instanceof Date&&!Number.isNaN(n.getTime())}function A(n){return n instanceof Date}function T(n){return n instanceof RegExp}function N(n){return n instanceof Map}function S(n){return n instanceof Set}function h(n){return n instanceof Error}function j(n){return(typeof n=="object"||typeof n=="function")&&n!==null&&typeof n.then=="function"}function I(n){return n!=null&&typeof n[Symbol.iterator]=="function"}function B(n){return n!=null&&typeof n[Symbol.asyncIterator]=="function"}function E(n){return n instanceof ArrayBuffer||ArrayBuffer.isView(n)}function O(n){return n===null||typeof n!="object"&&typeof n!="function"}function D(n){return n==null?!0:typeof n=="string"||Array.isArray(n)?n.length===0:n instanceof Map||n instanceof Set?n.size===0:ArrayBuffer.isView(n)||n instanceof ArrayBuffer?n.byteLength===0:r(n)?Object.keys(n).length===0:!1}function P(n){return n==null||typeof n=="string"&&n.trim().length===0}function R(n,e){return e.includes(n)}function L(n,e){return typeof n=="object"&&n!==null&&Object.prototype.hasOwnProperty.call(n,e)}function V(){return typeof globalThis.document<"u"||typeof globalThis.self<"u"&&typeof globalThis.importScripts=="function"}function t(n,e){throw new o("HLP_TYPE_ASSERTION",`Expected ${n}.`,e===void 0?{}:{details:{name:e}})}function F(n,e){typeof n!="string"&&t("a string",e)}function K(n,e){i(n)||t("a finite number",e)}function M(n,e){Number.isInteger(n)||t("an integer",e)}function v(n,e){typeof n!="boolean"&&t("a boolean",e)}function _(n,e){r(n)||t("a plain object",e)}function z(n,e){Array.isArray(n)||t("an array",e)}function H(n,e){n==null&&t("a defined value",e)}function Y(n,e){u(n)||t("a valid Date",e)}export{z as assertArray,v as assertBoolean,H as assertDefined,K as assertFiniteNumber,M as assertInteger,_ as assertPlainObject,F as assertString,Y as assertValidDate,L as hasKey,x as isArray,B as isAsyncIterable,b as isBigInt,E as isBinary,P as isBlank,w as isBoolean,V as isBrowserLike,A as isDate,a as isDefined,D as isEmpty,h as isError,i as isFiniteNumber,g as isFunction,p as isInteger,I as isIterable,N as isMap,f as isNil,m as isNonEmptyArray,c as isNumber,d as isObject,R as isOneOf,r as isPlainObject,O as isPrimitive,j as isPromiseLike,T as isRegExp,y as isSafeInteger,S as isSet,l as isString,k as isSymbol,u as isValidDate};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON helpers (docs/PLAN-HELPERS.md section 2 `json`): limited, pollution-safe parsing; tolerant and
|
|
3
|
+
* canonical stringify; JSON Pointer (RFC 6901), JSON Patch (RFC 6902), Merge Patch (RFC 7396), NDJSON.
|
|
4
|
+
*/
|
|
5
|
+
export { type JsonReviver, type SafeJsonParseOptions, type SafeJsonParseGuardOptions, safeJsonParse, parseJsonOrThrow, isValidJson } from './parse.js';
|
|
6
|
+
export { type SafeJsonStringifyOptions, safeJsonStringify, canonicalJson, prettyJson, jsonByteSize } from './stringify.js';
|
|
7
|
+
export { parsePointer, formatPointer, getByPointer, hasPointer, setByPointer, removeByPointer } from './pointer.js';
|
|
8
|
+
export { type JsonPatchOperation, type JsonPatchOptions, applyJsonPatch, tryApplyJsonPatch, createJsonPatch, applyMergePatch, createMergePatch } from './patch.js';
|
|
9
|
+
export { type ParseNdjsonOptions, parseNdjson, stringifyNdjson } from './ndjson.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{safeJsonParse as t,parseJsonOrThrow as r,isValidJson as s}from"./parse.js";import{safeJsonStringify as a,canonicalJson as p,prettyJson as i,jsonByteSize as y}from"./stringify.js";import{parsePointer as J,formatPointer as f,getByPointer as c,hasPointer as h,setByPointer as m,removeByPointer as O}from"./pointer.js";import{applyJsonPatch as S,tryApplyJsonPatch as d,createJsonPatch as l,applyMergePatch as x,createMergePatch as j}from"./patch.js";import{parseNdjson as v,stringifyNdjson as N}from"./ndjson.js";export{S as applyJsonPatch,x as applyMergePatch,p as canonicalJson,l as createJsonPatch,j as createMergePatch,f as formatPointer,c as getByPointer,h as hasPointer,s as isValidJson,y as jsonByteSize,r as parseJsonOrThrow,v as parseNdjson,J as parsePointer,i as prettyJson,O as removeByPointer,t as safeJsonParse,a as safeJsonStringify,m as setByPointer,N as stringifyNdjson,d as tryApplyJsonPatch};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type JsonContainer = Record<string, unknown> | unknown[];
|
|
2
|
+
export declare function isJsonContainer(value: unknown): value is JsonContainer;
|
|
3
|
+
/** Shallow copy of a container, keeping a null prototype. */
|
|
4
|
+
export declare function copyJsonContainer(value: JsonContainer): JsonContainer;
|
|
5
|
+
/** Deep copy of the plain-object/array structure (leaves shared). Assumes acyclic JSON data. */
|
|
6
|
+
export declare function cloneJson(value: unknown): unknown;
|
|
7
|
+
/** JSON data equality: key-order independent, numbers by value (`0 === -0`). */
|
|
8
|
+
export declare function jsonEqual(a: unknown, b: unknown): boolean;
|
|
9
|
+
/** Epoch ms for a strict ISO 8601 date-time string with `Z` or an offset; otherwise undefined. */
|
|
10
|
+
export declare function parseIsoDateTimeWithZone(text: string): number | undefined;
|
|
11
|
+
/** UTF-8 byte length of a string without allocating (lone surrogates count as U+FFFD, 3 bytes). */
|
|
12
|
+
export declare function utf8Length(text: string): number;
|
|
@@ -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{isPlainObject as f}from"../is/index.js";import{hasOwn as C}from"../internal/keys.js";import{daysInMonth as O}from"../date/plain-date.js";function D(n){return Array.isArray(n)||f(n)}function j(n){return Array.isArray(n)?n.slice():Object.getPrototypeOf(n)===null?Object.assign(Object.create(null),n):{...n}}function p(n){if(Array.isArray(n))return n.map(p);if(f(n)){const r=j(n);for(const e of Object.keys(r))r[e]=p(r[e]);return r}return n}function b(n,r){if(n===r)return!0;if(Array.isArray(n)){if(!Array.isArray(r)||n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!b(n[e],r[e]))return!1;return!0}if(f(n)&&f(r)){const e=Object.keys(n);if(e.length!==Object.keys(r).length)return!1;for(const t of e)if(!C(r,t)||!b(n[t],r[t]))return!1;return!0}return!1}const J=/^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:\d{2})$/;function E(n){if(n.length<17||n.length>40)return;const r=J.exec(n);if(!r)return;const[,e="",t="",o="",A="",N="",w="0",x="",s="Z"]=r;if(e==="-000000")return;const d=Number(e),i=Number(t),u=Number(o),l=Number(A),m=Number(N),a=Number(w);if(i<1||i>12||u<1||u>O(d,i)||l>23||m>59||a>59)return;let h=0;if(s!=="Z"){const g=Number(s.slice(1,3)),k=Number(s.slice(4,6));if(g>23||k>59)return;h=(s.startsWith("-")?-1:1)*(g*60+k)}const c=new Date(0);c.setUTCFullYear(d,i-1,u),c.setUTCHours(l,m-h,a,Math.floor(+`0.${x||"0"}`*1e3));const y=c.getTime();return Number.isNaN(y)?void 0:y}function M(n){let r=0;for(let e=0;e<n.length;e++){const t=n.charCodeAt(e);if(t<128)r+=1;else if(t<2048)r+=2;else if(t>=55296&&t<=56319&&e+1<n.length){const o=n.charCodeAt(e+1);o>=56320&&o<=57343?(r+=4,e++):r+=3}else r+=3}return r}export{p as cloneJson,j as copyJsonContainer,D as isJsonContainer,b as jsonEqual,E as parseIsoDateTimeWithZone,M as utf8Length};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Newline-delimited JSON (NDJSON / JSON Lines). */
|
|
2
|
+
import { HelperError, type Result } from '../error/index.js';
|
|
3
|
+
import { type SafeJsonParseOptions } from './parse.js';
|
|
4
|
+
import { type SafeJsonStringifyOptions } from './stringify.js';
|
|
5
|
+
export interface ParseNdjsonOptions extends Omit<SafeJsonParseOptions, 'maxLength'> {
|
|
6
|
+
/** Maximum total text length. Default 100,000,000. */
|
|
7
|
+
readonly maxLength?: number;
|
|
8
|
+
/** Maximum length of one line. Default 10,000,000. */
|
|
9
|
+
readonly maxLineLength?: number;
|
|
10
|
+
/** Maximum number of records. Default 1,000,000. */
|
|
11
|
+
readonly maxLines?: number;
|
|
12
|
+
/** `'fail'` (default) returns the first line error; `'skip'` drops bad lines. */
|
|
13
|
+
readonly onError?: 'fail' | 'skip';
|
|
14
|
+
/** Called for each bad line (1-based line number) in `'skip'` mode. */
|
|
15
|
+
readonly onLineError?: (line: number, error: HelperError) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parses NDJSON: one JSON value per line, blank lines ignored, `\r\n` accepted.
|
|
19
|
+
* Line errors carry `details.line` (1-based) and never the line's content.
|
|
20
|
+
* @example parseNdjson('{"a":1}\n{"a":2}\n') // => { ok: true, value: [{ a: 1 }, { a: 2 }] }
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseNdjson(text: string, options?: ParseNdjsonOptions): Result<unknown[], HelperError>;
|
|
23
|
+
/**
|
|
24
|
+
* Serializes values as NDJSON (each record terminated by `\n`). Values JSON cannot represent throw
|
|
25
|
+
* `HLP_JSON_NOT_SERIALIZABLE`.
|
|
26
|
+
* @example stringifyNdjson([{ a: 1 }, 2]) // => '{"a":1}\n2\n'
|
|
27
|
+
*/
|
|
28
|
+
export declare function stringifyNdjson(values: Iterable<unknown>, options?: Omit<SafeJsonStringifyOptions, 'indent'>): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{HelperError as _,LimitError as p,ValidationError as O,err as a,ok as S}from"../error/index.js";import{safeJsonParse as c}from"./parse.js";import{safeJsonStringify as h}from"./stringify.js";function w(n,l={}){const{maxLength:e=1e8,maxLineLength:f=1e7,maxLines:r=1e6,onError:L="fail",onLineError:N,...g}=l;if(typeof n!="string")return a(new O("HLP_JSON_INVALID_INPUT","JSON input must be a string."));if(n.length>e)return a(new p("HLP_JSON_TOO_LONG","NDJSON text exceeds the maximum length.",{details:{maxLength:e}}));const d=[];let u=0,i=0;for(;i<=n.length;){let s=n.indexOf(`
|
|
3
|
+
`,i);s===-1&&(s=n.length),u++;let o=n.slice(i,s);if(i=s+1,o.endsWith("\r")&&(o=o.slice(0,-1)),o.trim()==="")continue;if(d.length>=r)return a(new p("HLP_JSON_TOO_MANY_LINES","NDJSON has too many records.",{details:{maxLines:r}}));const t=c(o,{...g,maxLength:f});if(t.ok){d.push(t.value);continue}const m=new _(t.error.code,"An NDJSON line is not valid.",{kind:t.error.kind,details:{...t.error.details,line:u}});if(L==="fail")return a(m);N?.(u,m)}return S(d)}function x(n,l={}){let e="";for(const f of n){const r=h(f,l);if(r===void 0)throw new O("HLP_JSON_NOT_SERIALIZABLE","A value cannot be represented as JSON.");e+=`${r}
|
|
4
|
+
`}return e}export{w as parseNdjson,x as stringifyNdjson};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** Safe JSON parsing with limits and prototype-pollution protection. */
|
|
2
|
+
import { HelperError, type Result } from '../error/index.js';
|
|
3
|
+
/** Reviver called bottom-up like `JSON.parse`'s; returning `undefined` removes an object property. */
|
|
4
|
+
export type JsonReviver = (key: string, value: unknown, holder: Readonly<Record<string, unknown>> | readonly unknown[]) => unknown;
|
|
5
|
+
export interface SafeJsonParseOptions {
|
|
6
|
+
/** Maximum text length in UTF-16 code units. Default 10,000,000. */
|
|
7
|
+
readonly maxLength?: number;
|
|
8
|
+
/** Maximum nesting of arrays/objects. Default 256. */
|
|
9
|
+
readonly maxDepth?: number;
|
|
10
|
+
/** Maximum keys in any one object. Default 10,000. */
|
|
11
|
+
readonly maxKeys?: number;
|
|
12
|
+
/** `'error'` (default) fails on `__proto__`/`constructor`/`prototype` keys; `'strip'` removes them. */
|
|
13
|
+
readonly unsafeKeys?: 'error' | 'strip';
|
|
14
|
+
/** Revive ISO 8601 date-time strings that carry `Z` or an offset into `Date`s. Default false. */
|
|
15
|
+
readonly dates?: boolean;
|
|
16
|
+
/** Custom revivers, applied in order after the date reviver. */
|
|
17
|
+
readonly reviver?: JsonReviver | readonly JsonReviver[];
|
|
18
|
+
}
|
|
19
|
+
export interface SafeJsonParseGuardOptions<T> extends SafeJsonParseOptions {
|
|
20
|
+
/** Shape check; failing values produce `HLP_JSON_SHAPE`. */
|
|
21
|
+
readonly validate: (value: unknown) => value is T;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Parses JSON without throwing. Enforces length, depth and key-count limits (`LimitError`),
|
|
25
|
+
* rejects or strips prototype-pollution keys, and never echoes input in error messages.
|
|
26
|
+
* @example
|
|
27
|
+
* safeJsonParse('{"a":1}'); // => { ok: true, value: { a: 1 } }
|
|
28
|
+
* const r = safeJsonParse('{"a":');
|
|
29
|
+
* r.ok ? undefined : r.error.code; // => 'HLP_JSON_SYNTAX'
|
|
30
|
+
*/
|
|
31
|
+
export declare function safeJsonParse<T>(text: unknown, options: SafeJsonParseGuardOptions<T>): Result<T, HelperError>;
|
|
32
|
+
export declare function safeJsonParse(text: unknown, options?: SafeJsonParseOptions): Result<unknown, HelperError>;
|
|
33
|
+
/**
|
|
34
|
+
* Like `safeJsonParse` but throws the `HelperError`.
|
|
35
|
+
* @example
|
|
36
|
+
* const cfg = parseJsonOrThrow('{"retries":3}', { maxDepth: 32 }); // => { retries: 3 }
|
|
37
|
+
* parseJsonOrThrow('{"retries":'); // => throws HLP_JSON_SYNTAX
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseJsonOrThrow<T>(text: unknown, options: SafeJsonParseGuardOptions<T>): T;
|
|
40
|
+
export declare function parseJsonOrThrow(text: unknown, options?: SafeJsonParseOptions): unknown;
|
|
41
|
+
/**
|
|
42
|
+
* True when `text` parses within the limits.
|
|
43
|
+
* @example isValidJson('[1,2]') // => true
|
|
44
|
+
*/
|
|
45
|
+
export declare function isValidJson(text: unknown, options?: SafeJsonParseOptions): boolean;
|
|
@@ -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{HelperError as p,LimitError as w,ValidationError as d,err as O,ok as P}from"../error/index.js";import{isUnsafeKey as _}from"../internal/keys.js";import{parseIsoDateTimeWithZone as m}from"./internal.js";const N=1e7;function x(e,n){let r=0,a=!1;for(let t=0;t<e.length;t++){const s=e.charCodeAt(t);if(a)s===92?t++:s===34&&(a=!1);else if(s===34)a=!0;else if(s===123||s===91){if(++r>n)return!1}else(s===125||s===93)&&r--}return!0}function g(e){const n=[];e.dates&&n.push((a,t)=>{if(typeof t!="string")return t;const s=m(t);return s===void 0?t:new Date(s)});const{reviver:r}=e;if(typeof r=="function"?n.push(r):r&&n.push(...r),n.length!==0)return n.length===1?n[0]:(a,t,s)=>{let f=t;for(const l of n)if(f=l(a,f,s),f===void 0)return;return f}}function v(e,n){const{maxLength:r=N,maxDepth:a=256,maxKeys:t=1e4,unsafeKeys:s="error"}=n;if(typeof e!="string")throw new d("HLP_JSON_INVALID_INPUT","JSON input must be a string.");if(e.length>r)throw new w("HLP_JSON_TOO_LONG","JSON text exceeds the maximum length.",{details:{maxLength:r}});if(!x(e,a))throw new w("HLP_JSON_TOO_DEEP","JSON nesting exceeds the maximum depth.",{details:{maxDepth:a}});let f;try{f=JSON.parse(e)}catch{throw new d("HLP_JSON_SYNTAX","The text is not valid JSON.")}const l=g(n),c=(k,y,i)=>{if(typeof i=="object"&&i!==null)if(Array.isArray(i))for(let o=0;o<i.length;o++)i[o]=c(i,String(o),i[o]);else{const o=i,h=Object.keys(o);if(h.length>t)throw new w("HLP_JSON_TOO_MANY_KEYS","A JSON object has too many keys.",{details:{maxKeys:t}});for(const u of h){if(_(u)){if(s==="error")throw new d("HLP_JSON_UNSAFE_KEY","JSON contains an unsafe object key.");Reflect.deleteProperty(o,u);continue}const J=c(o,u,o[u]);J===void 0?Reflect.deleteProperty(o,u):o[u]=J}}if(!l)return i;try{return l(y,i,k)}catch(o){throw o instanceof p?o:new p("HLP_JSON_REVIVER","A JSON reviver failed.",{cause:o,kind:"validation"})}};return c({"":f},"",f)}function T(e){return e instanceof p?e:new p("HLP_JSON_PARSE","JSON parsing failed.",{cause:e})}function S(e,n={}){try{const r=v(e,n);return n.validate&&!n.validate(r)?O(new d("HLP_JSON_SHAPE","JSON does not have the expected shape.")):P(r)}catch(r){return O(T(r))}}function L(e,n={}){const r=S(e,n);if(!r.ok)throw r.error;return r.value}function b(e,n={}){return S(e,n).ok}export{b as isValidJson,L as parseJsonOrThrow,S as safeJsonParse};
|