@absoluteui/helpers 0.0.0-stage → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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,76 @@
|
|
|
1
|
+
import { type InstantInput, type PlainDateTime } from '../date/index.js';
|
|
2
|
+
import { type ZonedToInstantOptions } from '../date/zone.js';
|
|
3
|
+
export { getLocalTimeZone, isValidTimeZone, offsetAt, instantToZoned, getPossibleInstants, getWallTimeStatus, zonedToInstant, nextTransition, previousTransition } from '../date/zone.js';
|
|
4
|
+
export type { Disambiguation, ZonedToInstantOptions, TransitionSearchOptions } from '../date/zone.js';
|
|
5
|
+
/**
|
|
6
|
+
* Formats an offset in milliseconds as `+/-HH:MM` (with `:SS` when seconds are non-zero, as for
|
|
7
|
+
* historic local mean time). Rounds to whole seconds; zero is `+00:00`.
|
|
8
|
+
* @example formatOffset(19_800_000) // => '+05:30'
|
|
9
|
+
*/
|
|
10
|
+
export declare function formatOffset(offsetMs: number): string;
|
|
11
|
+
/**
|
|
12
|
+
* Parses `Z` or `+/-HH:MM[:SS]` to milliseconds; `undefined` when invalid.
|
|
13
|
+
* @example parseOffset('-04:00') // => -14400000
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseOffset(text: string): number | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a wall-clock time in one zone to the wall-clock time in another.
|
|
18
|
+
* @example
|
|
19
|
+
* import { plainDateTime, plainTime } from '@absoluteui/helpers/date';
|
|
20
|
+
* convertWallTime(plainDateTime('2026-09-29', plainTime(9, 0)), 'Asia/Kolkata', 'America/New_York'); // => '2026-09-28T23:30:00'
|
|
21
|
+
*/
|
|
22
|
+
export declare function convertWallTime(dateTime: PlainDateTime, fromTimeZone: string, toTimeZone: string, options?: ZonedToInstantOptions): PlainDateTime;
|
|
23
|
+
/**
|
|
24
|
+
* Zone identifiers the runtime supports (`Intl.supportedValuesOf('timeZone')`), otherwise a
|
|
25
|
+
* small fallback list of common zones. Legacy ICU names are replaced by current IANA names
|
|
26
|
+
* (`Asia/Calcutta` -> `Asia/Kolkata`) when the runtime accepts them, unless `modernNames: false`.
|
|
27
|
+
* Always includes `UTC`. Sorted, without duplicates.
|
|
28
|
+
* @example listTimeZones().includes('Asia/Kolkata') // => true
|
|
29
|
+
*/
|
|
30
|
+
export declare function listTimeZones(options?: {
|
|
31
|
+
readonly modernNames?: boolean;
|
|
32
|
+
}): string[];
|
|
33
|
+
export interface TimeZoneNameOptions {
|
|
34
|
+
readonly locale?: string;
|
|
35
|
+
/** Default `'long'` ("India Standard Time"); `'longGeneric'` omits standard/daylight ("Pacific Time"). */
|
|
36
|
+
readonly style?: 'long' | 'short' | 'shortOffset' | 'longOffset' | 'shortGeneric' | 'longGeneric';
|
|
37
|
+
/** Instant whose standard/daylight name to use. Default now. */
|
|
38
|
+
readonly at?: InstantInput;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Localized display name of a zone.
|
|
42
|
+
* @example timeZoneName('Asia/Kolkata', { locale: 'en' }) // => 'India Standard Time'
|
|
43
|
+
* @example
|
|
44
|
+
* timeZoneName('America/New_York', { locale: 'en', at: Date.UTC(2026, 6, 1) }); // => 'Eastern Daylight Time'
|
|
45
|
+
* timeZoneName('America/New_York', { locale: 'en', style: 'longGeneric', at: Date.UTC(2026, 0, 1) }); // => 'Eastern Time'
|
|
46
|
+
*/
|
|
47
|
+
export declare function timeZoneName(timeZone: string, options?: TimeZoneNameOptions): string;
|
|
48
|
+
/**
|
|
49
|
+
* Standard (non-DST) offset of a zone in a year: the smaller of the January 1 and July 1 offsets.
|
|
50
|
+
* @example standardOffset(2026, 'America/New_York') // => -18000000
|
|
51
|
+
*/
|
|
52
|
+
export declare function standardOffset(year: number, timeZone?: string): number;
|
|
53
|
+
/**
|
|
54
|
+
* True when the zone observes daylight saving time at the instant: its offset is larger than
|
|
55
|
+
* `standardOffset` for that year. (Zones with "negative DST" such as Europe/Dublin report summer
|
|
56
|
+
* as DST, matching common usage; Africa/Casablanca reports its Ramadan offset as non-DST.)
|
|
57
|
+
* @example isDstAt(Date.UTC(2026, 6, 1), 'Europe/London') // => true
|
|
58
|
+
*/
|
|
59
|
+
export declare function isDstAt(instant: InstantInput, timeZone?: string): boolean;
|
|
60
|
+
/** `Intl.DateTimeFormat` options plus the zone and locale. */
|
|
61
|
+
export type ZonedFormatOptions = Omit<Intl.DateTimeFormatOptions, 'timeZone'> & {
|
|
62
|
+
readonly timeZone?: string;
|
|
63
|
+
readonly locale?: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Formats an instant in a zone with a cached `Intl.DateTimeFormat`. Default
|
|
67
|
+
* `{ dateStyle: 'medium', timeStyle: 'short' }`.
|
|
68
|
+
* @example formatInZone(Date.UTC(2026, 0, 1), { timeZone: 'Asia/Tokyo', locale: 'en', timeStyle: 'short' }) // => '9:00 AM'
|
|
69
|
+
*/
|
|
70
|
+
export declare function formatInZone(instant: InstantInput, options?: ZonedFormatOptions): string;
|
|
71
|
+
/**
|
|
72
|
+
* RFC 3339 / ISO 8601 string of an instant as wall time in a zone with its offset,
|
|
73
|
+
* for example `2026-03-08T03:00:00-04:00`.
|
|
74
|
+
* @example formatZonedIso(Date.UTC(2026, 2, 8, 7), 'America/New_York') // => '2026-03-08T03:00:00-04:00'
|
|
75
|
+
*/
|
|
76
|
+
export declare function formatZonedIso(instant: InstantInput, timeZone?: string): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as h}from"../error/index.js";import{formatPlainDateTime as y,plainDate as l,toEpochDay as A}from"../date/index.js";import{dateTimeFormat as f}from"../date/intl-cache.js";import{parseOffsetText as T}from"../date/plain-time.js";import{instantToZoned as u,isValidTimeZone as b,offsetAtMs as c,resolveTimeZone as s,toEpochMs as m,zonedToInstant as Z}from"../date/zone.js";import{getLocalTimeZone as j,isValidTimeZone as v,offsetAt as w,instantToZoned as B,getPossibleInstants as H,getWallTimeStatus as V,zonedToInstant as $,nextTransition as J,previousTransition as R}from"../date/zone.js";function O(n){if(!Number.isFinite(n))throw new h("HLP_TZ_INVALID_OFFSET","Offset must be a finite number.");const a=Math.round(n/1e3),e=Math.abs(a),t=Math.floor(e/3600),o=Math.floor(e%3600/60),r=e%60,i=g=>String(g).padStart(2,"0");return`${a<0?"-":"+"}${i(t)}:${i(o)}${r?`:${i(r)}`:""}`}function C(n){return T(n)}function D(n,a,e,t={}){return u(Z(n,a,t),e)}const d=Object.freeze(["UTC","Africa/Cairo","Africa/Johannesburg","Africa/Lagos","Africa/Nairobi","America/Anchorage","America/Bogota","America/Chicago","America/Denver","America/Halifax","America/Los_Angeles","America/Mexico_City","America/New_York","America/Phoenix","America/Santiago","America/Sao_Paulo","America/St_Johns","America/Toronto","Asia/Bangkok","Asia/Dhaka","Asia/Dubai","Asia/Hong_Kong","Asia/Jakarta","Asia/Jerusalem","Asia/Karachi","Asia/Kathmandu","Asia/Kolkata","Asia/Riyadh","Asia/Seoul","Asia/Shanghai","Asia/Singapore","Asia/Tehran","Asia/Tokyo","Atlantic/Reykjavik","Australia/Adelaide","Australia/Brisbane","Australia/Lord_Howe","Australia/Perth","Australia/Sydney","Europe/Amsterdam","Europe/Berlin","Europe/Istanbul","Europe/London","Europe/Madrid","Europe/Moscow","Europe/Paris","Pacific/Auckland","Pacific/Chatham","Pacific/Honolulu"]),p=Object.freeze({"Africa/Asmera":"Africa/Asmara","America/Buenos_Aires":"America/Argentina/Buenos_Aires","America/Catamarca":"America/Argentina/Catamarca","America/Coral_Harbour":"America/Atikokan","America/Cordoba":"America/Argentina/Cordoba","America/Godthab":"America/Nuuk","America/Indianapolis":"America/Indiana/Indianapolis","America/Jujuy":"America/Argentina/Jujuy","America/Louisville":"America/Kentucky/Louisville","America/Mendoza":"America/Argentina/Mendoza","Asia/Calcutta":"Asia/Kolkata","Asia/Katmandu":"Asia/Kathmandu","Asia/Rangoon":"Asia/Yangon","Asia/Saigon":"Asia/Ho_Chi_Minh","Atlantic/Faeroe":"Atlantic/Faroe","Europe/Kiev":"Europe/Kyiv","Pacific/Enderbury":"Pacific/Kanton","Pacific/Ponape":"Pacific/Pohnpei","Pacific/Truk":"Pacific/Chuuk"});function N(n={}){const a=Intl;let e;try{e=typeof a.supportedValuesOf=="function"?a.supportedValuesOf("timeZone"):[...d]}catch{e=[...d]}return(n.modernNames??!0)&&(e=e.map(t=>{const o=Object.prototype.hasOwnProperty.call(p,t)?p[t]:void 0;return o!==void 0&&b(o)?o:t})),e.push("UTC"),[...new Set(e)].sort()}function k(n,a={}){const e=s(n),t=a.at===void 0?Date.now():m(a.at);return f(a.locale,{timeZone:e,timeZoneName:a.style??"long"}).formatToParts(t).find(r=>r.type==="timeZoneName")?.value??e}function I(n,a){const e=s(a),t=c(A(l(n,1,1))*864e5,e),o=c(A(l(n,7,1))*864e5,e);return Math.min(t,o)}function M(n,a){const e=m(n),t=s(a),o=u(e,t).date.year;return c(e,t)>I(o,t)}function K(n,a={}){const e=m(n),t=s(a.timeZone),{locale:o}=a,r=Object.keys(a).some(i=>i!=="locale"&&i!=="timeZone"&&i!=="calendar"&&i!=="numberingSystem"&&i!=="hour12"&&i!=="hourCycle");return f(o,{...a,...r?{}:{dateStyle:"medium",timeStyle:"short"},timeZone:t}).format(e)}function z(n,a){const e=m(n),t=s(a);return`${y(u(e,t))}${O(c(e,t))}`}export{D as convertWallTime,K as formatInZone,O as formatOffset,z as formatZonedIso,j as getLocalTimeZone,H as getPossibleInstants,V as getWallTimeStatus,B as instantToZoned,M as isDstAt,v as isValidTimeZone,N as listTimeZones,J as nextTransition,w as offsetAt,C as parseOffset,R as previousTransition,I as standardOffset,k as timeZoneName,$ as zonedToInstant};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/** A single query value. `undefined` is always skipped; `null` becomes an empty value unless `skipNull`. */
|
|
2
|
+
export type QueryPrimitive = string | number | boolean | bigint | Date | null | undefined;
|
|
3
|
+
/** Values accepted by `buildQuery`: primitives, arrays of primitives, and nested objects (bracket notation). */
|
|
4
|
+
export type QueryInputValue = QueryPrimitive | readonly QueryPrimitive[] | QueryInput;
|
|
5
|
+
export interface QueryInput {
|
|
6
|
+
readonly [key: string]: QueryInputValue;
|
|
7
|
+
}
|
|
8
|
+
/** Parsed query value. */
|
|
9
|
+
export type QueryValue = string | string[] | QueryObject;
|
|
10
|
+
/** Null-prototype object returned by `parseQuery`. */
|
|
11
|
+
export interface QueryObject {
|
|
12
|
+
[key: string]: QueryValue;
|
|
13
|
+
}
|
|
14
|
+
export type ArrayFormat = 'repeat' | 'brackets' | 'comma';
|
|
15
|
+
export interface BuildQueryOptions {
|
|
16
|
+
/** `repeat`: `a=1&a=2` (default); `brackets`: `a[]=1&a[]=2`; `comma`: `a=1,2`. */
|
|
17
|
+
readonly arrayFormat?: ArrayFormat;
|
|
18
|
+
/** Skip `null` values instead of emitting `key=`. Default false. */
|
|
19
|
+
readonly skipNull?: boolean;
|
|
20
|
+
/** Sort keys (code-unit order) for stable output. Default false. */
|
|
21
|
+
readonly sort?: boolean;
|
|
22
|
+
/** Prefix the result with `?` when it is not empty. Default false. */
|
|
23
|
+
readonly prefix?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Builds a query string (without `?` unless `prefix`). Spaces encode as `%20`.
|
|
27
|
+
* Nested objects use bracket notation. Unsafe keys (`__proto__`, ...) throw `HLP_UNSAFE_KEY`.
|
|
28
|
+
* @example
|
|
29
|
+
* buildQuery({ q: 'a b', tag: ['x', 'y'], page: 2 }); // => 'q=a%20b&tag=x&tag=y&page=2'
|
|
30
|
+
* buildQuery({ tag: ['x', 'y'] }, { arrayFormat: 'comma' }); // => 'tag=x,y'
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildQuery(params: QueryInput, options?: BuildQueryOptions): string;
|
|
33
|
+
export interface ParseQueryOptions {
|
|
34
|
+
/** `comma` additionally splits values on `,`. Repeated keys and `a[]` always produce arrays. Default `repeat`. */
|
|
35
|
+
readonly arrayFormat?: ArrayFormat;
|
|
36
|
+
/** Maximum number of parameters. Default 1000; exceeding throws `HLP_URL_TOO_MANY_PARAMS`. */
|
|
37
|
+
readonly maxParams?: number;
|
|
38
|
+
/** Maximum bracket nesting (`a[b][c]` is 2). Default 5; exceeding throws `HLP_URL_TOO_DEEP`. */
|
|
39
|
+
readonly maxDepth?: number;
|
|
40
|
+
/** Maximum input length in characters. Default 65 536; exceeding throws `HLP_URL_QUERY_TOO_LONG`. */
|
|
41
|
+
readonly maxLength?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Parses a query string (leading `?` optional; `+` decodes as a space) into null-prototype objects.
|
|
45
|
+
* Supports repeated keys, `a[]=` arrays and `a[b][c]=` nesting. Parameters with unsafe keys
|
|
46
|
+
* (`__proto__`, `constructor`, `prototype`) are dropped; conflicting shapes keep the first value.
|
|
47
|
+
* @example
|
|
48
|
+
* parseQuery('?q=a+b&tag=x&tag=y&user[name]=Ann'); // => { q: 'a b', tag: ['x', 'y'], user: { name: 'Ann' } }
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseQuery(qs: string, options?: ParseQueryOptions): QueryObject;
|
|
51
|
+
export interface JoinUrlOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Resolve `.` and `..` in the joined segments and throw `HLP_URL_PATH_TRAVERSAL` if they would
|
|
54
|
+
* climb above the base path. Also treats `\` and encoded dots (`%2e`) as traversal. Default false.
|
|
55
|
+
*/
|
|
56
|
+
readonly confine?: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Joins a base URL and path segments with exactly one `/` between parts. Keeps the base's
|
|
60
|
+
* protocol, authority, query and fragment. Pass `{ confine: true }` last to block `..` escapes.
|
|
61
|
+
* Segments are not encoded: use `encodePathSegment` for untrusted values.
|
|
62
|
+
* @example
|
|
63
|
+
* joinUrl('https://api.example.com/v1/', '/users/', 42); // => 'https://api.example.com/v1/users/42'
|
|
64
|
+
* joinUrl('/files', '../etc', { confine: true }); // => throws HLP_URL_PATH_TRAVERSAL
|
|
65
|
+
*/
|
|
66
|
+
export declare function joinUrl(base: string, ...parts: readonly (string | number | JoinUrlOptions)[]): string;
|
|
67
|
+
/**
|
|
68
|
+
* Percent-encodes one path segment, including `/`, `?`, `#`; `.` and `..` are encoded so they cannot traverse.
|
|
69
|
+
* @example
|
|
70
|
+
* encodePathSegment('a/b c'); // => 'a%2Fb%20c'
|
|
71
|
+
* encodePathSegment('..'); // => '%2E%2E'
|
|
72
|
+
*/
|
|
73
|
+
export declare function encodePathSegment(segment: string | number): string;
|
|
74
|
+
/**
|
|
75
|
+
* Returns `url` with `params` set: existing keys named in `params` are replaced, others kept;
|
|
76
|
+
* an `undefined` value removes the key. Works with relative URLs and keeps the fragment.
|
|
77
|
+
* @example
|
|
78
|
+
* withQuery('/list?page=1&q=x#top', { page: 2 }); // => '/list?q=x&page=2#top'
|
|
79
|
+
*/
|
|
80
|
+
export declare function withQuery(url: string, params: QueryInput, options?: BuildQueryOptions): string;
|
|
81
|
+
/**
|
|
82
|
+
* Removes the given query keys (or the whole query when `keys` is omitted). Keeps the fragment.
|
|
83
|
+
* @example
|
|
84
|
+
* removeQuery('/a?x=1&y=2', ['x']); // => '/a?y=2'
|
|
85
|
+
* removeQuery('/a?x=1#f'); // => '/a#f'
|
|
86
|
+
*/
|
|
87
|
+
export declare function removeQuery(url: string, keys?: readonly string[]): string;
|
|
88
|
+
/**
|
|
89
|
+
* First value of a query parameter, decoded; `undefined` when absent.
|
|
90
|
+
* @example
|
|
91
|
+
* getQueryParam('https://x.test/?a=1&a=2', 'a'); // => '1'
|
|
92
|
+
*/
|
|
93
|
+
export declare function getQueryParam(url: string, key: string): string | undefined;
|
|
94
|
+
export interface IsSafeUrlOptions {
|
|
95
|
+
/** Lowercase schemes without `:`. Default `['http', 'https', 'mailto', 'tel']`. */
|
|
96
|
+
readonly allowedSchemes?: readonly string[];
|
|
97
|
+
/** Accept relative URLs (`/a`, `a/b`, `?q`, `#f`, `//host/a`). Default true. */
|
|
98
|
+
readonly allowRelative?: boolean;
|
|
99
|
+
/** Maximum length. Default 8192. */
|
|
100
|
+
readonly maxLength?: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* True when `url` is safe to put in `href`/`src`: scheme on the allow-list (rejects `javascript:`,
|
|
104
|
+
* `data:`, `vbscript:`), no control characters (blocks `java\tscript:`), and parseable.
|
|
105
|
+
* @example
|
|
106
|
+
* isSafeUrl('https://example.com'); // => true
|
|
107
|
+
* isSafeUrl(' JaVa\tScRiPt:alert(1)'); // => false
|
|
108
|
+
*/
|
|
109
|
+
export declare function isSafeUrl(url: string, options?: IsSafeUrlOptions): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* True for URLs with a scheme (`https:`, `mailto:`); protocol-relative `//host` is not absolute.
|
|
112
|
+
* @example
|
|
113
|
+
* isAbsoluteUrl('https://a.test'); // => true
|
|
114
|
+
* isAbsoluteUrl('/a'); // => false
|
|
115
|
+
*/
|
|
116
|
+
export declare function isAbsoluteUrl(url: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Parses a URL, returning `undefined` instead of throwing.
|
|
119
|
+
* @example
|
|
120
|
+
* parseUrl('not a url'); // => undefined
|
|
121
|
+
* parseUrl('/a', 'https://x.test')?.href; // => 'https://x.test/a'
|
|
122
|
+
*/
|
|
123
|
+
export declare function parseUrl(url: string | URL, base?: string | URL): URL | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* True when both absolute URLs have the same origin (scheme, host, port). Opaque origins never match.
|
|
126
|
+
* @example
|
|
127
|
+
* isSameOrigin('https://a.test/x', 'https://A.test:443/y'); // => true
|
|
128
|
+
*/
|
|
129
|
+
export declare function isSameOrigin(a: string | URL, b: string | URL): boolean;
|
|
130
|
+
export interface SafeRedirectOptions {
|
|
131
|
+
/** Absolute origins that may be redirected to (for example `['https://app.example.com']`). Default none. */
|
|
132
|
+
readonly allowedOrigins?: readonly string[];
|
|
133
|
+
/** Returned when `target` is unsafe. Default `'/'`. */
|
|
134
|
+
readonly fallback?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Open-redirect guard. Accepts same-site paths starting with a single `/` and absolute
|
|
138
|
+
* http(s) URLs whose origin is allowed; rejects `//evil.com`, `/\evil.com`, schemes, and control characters.
|
|
139
|
+
* @example
|
|
140
|
+
* safeRedirectTarget('/dashboard?tab=1'); // => '/dashboard?tab=1'
|
|
141
|
+
* safeRedirectTarget('//evil.com'); // => '/'
|
|
142
|
+
*/
|
|
143
|
+
export declare function safeRedirectTarget(target: string | null | undefined, options?: SafeRedirectOptions): string;
|
|
144
|
+
export interface NormalizeUrlOptions {
|
|
145
|
+
/** Sort query parameters by key (stable). Default false. */
|
|
146
|
+
readonly sortQuery?: boolean;
|
|
147
|
+
/** Drop the `#fragment`. Default false. */
|
|
148
|
+
readonly removeFragment?: boolean;
|
|
149
|
+
/** Drop a trailing `/` from non-root paths. Default false. */
|
|
150
|
+
readonly removeTrailingSlash?: boolean;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Normalizes an absolute URL: lowercase scheme and host, default port removed, dot segments resolved,
|
|
154
|
+
* plus optional query sort and fragment removal. Returns `undefined` when unparseable.
|
|
155
|
+
* @example
|
|
156
|
+
* normalizeUrl('HTTPS://Example.COM:443/a/../b?z=1&a=2#x', { sortQuery: true, removeFragment: true });
|
|
157
|
+
* // 'https://example.com/b?a=2&z=1'
|
|
158
|
+
*/
|
|
159
|
+
export declare function normalizeUrl(url: string, options?: NormalizeUrlOptions): string | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Hostname of an absolute URL (lowercase, no port); `undefined` when unparseable.
|
|
162
|
+
* @example
|
|
163
|
+
* getDomain('https://Sub.Example.com:8080/x'); // => 'sub.example.com'
|
|
164
|
+
*/
|
|
165
|
+
export declare function getDomain(url: string): string | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Last path segment, percent-decoded; `undefined` when the path ends with `/`. Works for relative URLs.
|
|
168
|
+
* @example
|
|
169
|
+
* getFileNameFromUrl('https://x.test/files/report%202026.pdf?v=1'); // => 'report 2026.pdf'
|
|
170
|
+
*/
|
|
171
|
+
export declare function getFileNameFromUrl(url: string): string | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Lowercase file extension without the dot, from a URL or path; `undefined` when none (dotfiles have none).
|
|
174
|
+
* @example
|
|
175
|
+
* getExtension('/a/photo.JPG?x=1'); // => 'jpg'
|
|
176
|
+
* getExtension('.env'); // => undefined
|
|
177
|
+
*/
|
|
178
|
+
export declare function getExtension(urlOrPath: string): string | undefined;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as A,ValidationError as E}from"../error/index.js";import{hasOwn as T,isUnsafeKey as $}from"../internal/keys.js";const L=encodeURIComponent,H=32;function I(e){if(e instanceof Date){if(Number.isNaN(e.getTime()))throw new E("HLP_URL_INVALID_DATE","A query value is an invalid date.");return e.toISOString()}return String(e)}const W=e=>typeof e=="object"&&e!==null&&!Array.isArray(e)&&!(e instanceof Date);function z(e,n={}){const{arrayFormat:t="repeat",skipNull:r=!1,sort:i=!1}=n,o=[],s=(d,g,c)=>{if(c>H)throw new A("HLP_URL_TOO_DEEP","Query nesting exceeds the limit.");const f=Object.keys(d);i&&f.sort();for(const x of f){if($(x))throw new E("HLP_UNSAFE_KEY","Refusing to use an unsafe object key.");const h=d[x],a=g===""?L(x):`${g}%5B${L(x)}%5D`;if(h!==void 0){if(h===null){r||o.push(`${a}=`);continue}if(Array.isArray(h)){const y=h.filter(u=>u!==void 0&&!(r&&u===null));if(t==="comma")y.length&&o.push(`${a}=${y.map(u=>u===null?"":L(I(u))).join(",")}`);else{const u=t==="brackets"?`${a}%5B%5D`:a;for(const p of y)o.push(`${u}=${p===null?"":L(I(p))}`)}continue}if(W(h)){s(h,a,c+1);continue}o.push(`${a}=${L(I(h))}`)}}};s(e,"",0);const l=o.join("&");return n.prefix===!0&&l?`?${l}`:l}function w(e){const n=e.includes("+")?e.replaceAll("+"," "):e;if(!n.includes("%"))return n;try{return decodeURIComponent(n)}catch{return n}}function V(e){const n=e.indexOf("[");if(n<=0||!e.endsWith("]"))return[e];const t=[e.slice(0,n)];let r=n;for(;r<e.length;){if(e.charCodeAt(r)!==91)return[e];const i=e.indexOf("]",r+1);if(i<0)return[e];const o=e.slice(r+1,i);if(o.includes("["))return[e];t.push(o),r=i+1}return t}const D=()=>Object.create(null);function G(e,n={}){const{arrayFormat:t="repeat",maxParams:r=1e3,maxDepth:i=5,maxLength:o=65536}=n;if(e.length>o)throw new A("HLP_URL_QUERY_TOO_LONG","The query string exceeds the length limit.");const s=D();let l=e.startsWith("?")?e.slice(1):e;const d=l.indexOf("#");if(d>=0&&(l=l.slice(0,d)),l==="")return s;let g=0;for(const c of l.split("&")){if(c==="")continue;if(++g>r)throw new A("HLP_URL_TOO_MANY_PARAMS","The query string has too many parameters.");const f=c.indexOf("="),x=w(f<0?c:c.slice(0,f)),h=f<0?"":w(c.slice(f+1));if(x==="")continue;const a=V(x);if(a.length-1>i)throw new A("HLP_URL_TOO_DEEP","Query nesting exceeds the limit.");if(a.some($)||a.slice(1,-1).includes(""))continue;const y=a.length>1&&a[a.length-1]==="",u=y?a.slice(0,-1):a,p=t==="comma"&&f>=0?c.slice(f+1).split(",").map(w):[h];let m=s,U=!0;for(let _=0;_<u.length-1;_++){const S=u[_]??"",R=T(m,S)?m[S]:void 0;if(R===void 0){const v=D();m[S]=v,m=v}else if(typeof R=="object"&&!Array.isArray(R))m=R;else{U=!1;break}}if(!U)continue;const b=u[u.length-1]??"",Q=T(m,b)?m[b]:void 0,F=y||p.length>1;Q===void 0?m[b]=F?p:p[0]??"":typeof Q=="string"?m[b]=[Q,...p]:Array.isArray(Q)&&Q.push(...p)}return s}function B(e){const n=e.search(/[?#]/);return n<0?[e,""]:[e.slice(0,n),e.slice(n)]}function K(e){const n=/^(?:[a-z][\d+.a-z-]*:)?\/\/[^/]*/i.exec(e);if(n)return[n[0],e.slice(n[0].length)];const t=/^[a-z][\d+.a-z-]*:/i.exec(e);return t?[t[0],e.slice(t[0].length)]:["",e]}function X(e,...n){const t=n[n.length-1],r=typeof t=="object"?t:{},i=n.filter(u=>typeof u!="object"),[o,s]=B(e),[l,d]=K(o),g=r.confine===!0,c=d.split("/").filter(u=>u!==""),f=[];let x=d.endsWith("/");for(const u of i){let p=String(u);g&&(p=p.replaceAll("\\","/"));const m=p.split("/");for(const U of m)if(U!==""){if(g){const b=U.toLowerCase().replaceAll("%2e",".");if(b===".")continue;if(b===".."){if(f.length===0)throw new E("HLP_URL_PATH_TRAVERSAL","The path escapes the base URL.");f.pop();continue}}f.push(U)}p!==""&&(x=p.endsWith("/"))}const h=[...c,...f].join("/"),a=l!==""||d.startsWith("/")?"/":"";let y=l+(h===""?a&&l===""?"/":"":a+h);return x&&y!==""&&!y.endsWith("/")&&(y+="/"),y+s}function Z(e){const n=String(e);return n==="."||n===".."?n.replaceAll(".","%2E"):encodeURIComponent(n)}function j(e){const n=e.indexOf("#"),t=n<0?"":e.slice(n),r=n<0?e:e.slice(0,n),i=r.indexOf("?");return i<0?{head:r,query:"",hash:t}:{head:r.slice(0,i),query:r.slice(i+1),hash:t}}function k(e){const n=e.indexOf("=");return w(n<0?e:e.slice(0,n))}const q=(e,n)=>e===n||e.startsWith(`${n}[`);function ee(e,n,t={}){const{head:r,query:i,hash:o}=j(e),s=Object.keys(n),l=i.split("&").filter(c=>c!==""&&!s.some(f=>q(k(c),f))),d=z(n,{...t,prefix:!1}),g=[...l,...d?[d]:[]].join("&");return r+(g?`?${g}`:"")+o}function ne(e,n){const{head:t,query:r,hash:i}=j(e);if(n===void 0)return t+i;const o=r.split("&").filter(s=>s!==""&&!n.some(l=>q(k(s),l)));return t+(o.length?`?${o.join("&")}`:"")+i}function te(e,n){const{query:t}=j(e);for(const r of t.split("&")){if(r==="")continue;const i=r.indexOf("=");if(w(i<0?r:r.slice(0,i))===n)return i<0?"":w(r.slice(i+1))}}const C=/[\u0000-\u001f\u007f-\u009f\u2028\u2029\ufeff]/,N=/^([a-z][\d+.a-z-]*):/i,P="https://probe.invalid/";function re(e,n={}){const{allowedSchemes:t=["http","https","mailto","tel"],allowRelative:r=!0,maxLength:i=8192}=n;if(e.length>i||C.test(e))return!1;const o=e.trim();if(o==="")return!1;const s=t.map(c=>c.toLowerCase()),l=N.exec(o);let d;try{d=new URL(o,P)}catch{return!1}const g=d.protocol.slice(0,-1).toLowerCase();return l?s.includes((l[1]??"").toLowerCase())&&s.includes(g):r?s.includes(g):!1}function ie(e){return N.test(e.trim())}function O(e,n){try{return n===void 0?new URL(e):new URL(e,n)}catch{return}}function oe(e,n){const t=O(e),r=O(n);return!t||!r||t.origin==="null"||r.origin==="null"?!1:t.origin===r.origin}function se(e,n={}){const t=n.fallback??"/";if(typeof e!="string"||e.length>8192||C.test(e))return t;const r=e.trim();if(r===""||r.includes("\\"))return t;if(r.startsWith("/"))return r.startsWith("//")||O(r,P)?.origin!==new URL(P).origin?t:r;const i=O(r);return!i||i.protocol!=="https:"&&i.protocol!=="http:"||i.username!==""||i.password!==""?t:(n.allowedOrigins??[]).map(s=>O(s)?.origin).filter(s=>s!==void 0&&s!=="null").includes(i.origin)?i.href:t}function le(e,n={}){const t=O(e.trim());if(!t)return;if(n.removeFragment===!0&&(t.hash=""),n.removeTrailingSlash===!0){let i=t.pathname;for(;i.length>1&&i.endsWith("/");)i=i.slice(0,-1);t.pathname=i}let r=t.search.slice(1);return n.sortQuery===!0&&r&&(r=r.split("&").filter(o=>o!=="").map((o,s)=>({p:o,i:s,k:k(o)})).sort((o,s)=>o.k<s.k?-1:o.k>s.k?1:o.i-s.i).map(o=>o.p).join("&")),t.search=r?`?${r}`:"",t.href}function ae(e){const n=O(e.trim());return n&&n.hostname!==""?n.hostname:void 0}function M(e){const n=O(e.trim(),P);if(!n)return;const t=n.pathname.slice(n.pathname.lastIndexOf("/")+1);if(t!=="")try{return decodeURIComponent(t)}catch{return t}}function ue(e){const n=M(e.replaceAll("\\","/"));if(n===void 0)return;const t=n.lastIndexOf(".");if(!(t<=0||t===n.length-1))return n.slice(t+1).toLowerCase()}export{z as buildQuery,Z as encodePathSegment,ae as getDomain,ue as getExtension,M as getFileNameFromUrl,te as getQueryParam,ie as isAbsoluteUrl,re as isSafeUrl,oe as isSameOrigin,X as joinUrl,le as normalizeUrl,G as parseQuery,O as parseUrl,ne as removeQuery,se as safeRedirectTarget,ee as withQuery};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema builders, re-exported as the `v` namespace from `@absoluteui/helpers/validate`
|
|
3
|
+
* (`v.string()`, `v.object()`, ...). Each builder is a standalone function, so bundlers drop
|
|
4
|
+
* the ones an app does not use.
|
|
5
|
+
*/
|
|
6
|
+
export { string, number, boolean, date, literal, enumOf, array, object, optional, nullable, union, refine, transform } from './schema.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{string as r,number as o,boolean as a,date as l,literal as t,enumOf as i,array as b,object as f,optional as m,nullable as u,union as p,refine as s,transform as c}from"./schema.js";export{b as array,a as boolean,l as date,i as enumOf,t as literal,u as nullable,o as number,f as object,m as optional,s as refine,r as string,c as transform,p as union};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
export interface EmailOptions {
|
|
2
|
+
/** Allow non-ASCII (internationalized) local parts and domain labels. Default false. */
|
|
3
|
+
readonly allowIdn?: boolean;
|
|
4
|
+
/** Require a dot in the domain (reject `user@localhost`). Default true. */
|
|
5
|
+
readonly requireTld?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Practical RFC 5322 `addr-spec` subset: dot-atom local part (no quoted strings, comments or
|
|
9
|
+
* IP literals), host-name domain; at most 254 characters overall and 64 bytes before the `@`.
|
|
10
|
+
* @example isEmail('ada@example.com') // => true
|
|
11
|
+
* @example isEmail('a..b@example.com') // => false
|
|
12
|
+
*/
|
|
13
|
+
export declare function isEmail(value: unknown, options?: EmailOptions): value is string;
|
|
14
|
+
export interface UrlOptions {
|
|
15
|
+
/** Allowed schemes without the colon. Default `['http', 'https']`. */
|
|
16
|
+
readonly schemes?: readonly string[];
|
|
17
|
+
/** Require a host (rejects `mailto:` etc. unless false). Default true. */
|
|
18
|
+
readonly requireHost?: boolean;
|
|
19
|
+
/** Allow `user:password@` credentials (a phishing vector). Default false. */
|
|
20
|
+
readonly allowCredentials?: boolean;
|
|
21
|
+
/** Maximum length. Default 2048. */
|
|
22
|
+
readonly maxLength?: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Absolute URL check via the platform URL parser plus a scheme allow-list. Rejects raw
|
|
26
|
+
* whitespace/control characters (which the parser would silently strip) and, by default,
|
|
27
|
+
* embedded credentials.
|
|
28
|
+
* @example isUrl('https://example.com/a?b=1') // => true
|
|
29
|
+
* @example isUrl('javascript:alert(1)') // => false
|
|
30
|
+
*/
|
|
31
|
+
export declare function isUrl(value: unknown, options?: UrlOptions): value is string;
|
|
32
|
+
/**
|
|
33
|
+
* `http:` or `https:` URL with a host and no credentials.
|
|
34
|
+
* @example isHttpUrl('https://example.com') // => true
|
|
35
|
+
*/
|
|
36
|
+
export declare function isHttpUrl(value: unknown): value is string;
|
|
37
|
+
/**
|
|
38
|
+
* E.164: `+`, a non-zero country code digit, 7-15 digits in total, nothing else.
|
|
39
|
+
* @example isPhoneE164('+442079460958') // => true
|
|
40
|
+
*/
|
|
41
|
+
export declare function isPhoneE164(value: unknown): value is string;
|
|
42
|
+
/**
|
|
43
|
+
* Loose phone check for user input: digits, spaces, `()`, `-`, `.`, an optional leading `+`,
|
|
44
|
+
* and 7-15 digits.
|
|
45
|
+
* @example isPhone('+1 (555) 010-9999') // => true
|
|
46
|
+
*/
|
|
47
|
+
export declare function isPhone(value: unknown): value is string;
|
|
48
|
+
/** Countries with a known IBAN length. @example IBAN_COUNTRIES.includes('DE') // => true */
|
|
49
|
+
export declare const IBAN_COUNTRIES: readonly string[];
|
|
50
|
+
/**
|
|
51
|
+
* ISO 13616 IBAN: country length table and ISO 7064 mod-97 checksum. Spaces are ignored;
|
|
52
|
+
* letters are case-insensitive.
|
|
53
|
+
* @example isIban('GB82 WEST 1234 5698 7654 32') // => true
|
|
54
|
+
*/
|
|
55
|
+
export declare function isIban(value: unknown): value is string;
|
|
56
|
+
/**
|
|
57
|
+
* ISO 9362 BIC/SWIFT code: 4-letter institution, 2-letter country, 2 location characters,
|
|
58
|
+
* optional 3-character branch. Case-insensitive.
|
|
59
|
+
* @example isBic('DEUTDEFF500') // => true
|
|
60
|
+
*/
|
|
61
|
+
export declare function isBic(value: unknown): value is string;
|
|
62
|
+
/**
|
|
63
|
+
* Luhn (mod 10) checksum over a digit string. Non-digits make it false.
|
|
64
|
+
* @example luhnCheck('79927398713') // => true
|
|
65
|
+
*/
|
|
66
|
+
export declare function luhnCheck(digits: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Payment card number: 12-19 digits (spaces and dashes allowed) with a valid Luhn checksum.
|
|
69
|
+
* @example isCreditCard('4111 1111 1111 1111') // => true
|
|
70
|
+
*/
|
|
71
|
+
export declare function isCreditCard(value: unknown): value is string;
|
|
72
|
+
/** Card networks recognized by {@link cardBrand}. */
|
|
73
|
+
export type CardBrand = 'visa' | 'mastercard' | 'amex' | 'discover' | 'diners' | 'jcb' | 'unionpay' | 'maestro';
|
|
74
|
+
/**
|
|
75
|
+
* Card network by IIN range and length (no Luhn check; combine with {@link isCreditCard}).
|
|
76
|
+
* Returns `undefined` when no network matches.
|
|
77
|
+
* @example cardBrand('4111111111111111') // => 'visa'
|
|
78
|
+
* @example cardBrand('378282246310005') // => 'amex'
|
|
79
|
+
*/
|
|
80
|
+
export declare function cardBrand(value: unknown): CardBrand | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* RFC 9562 UUID (versions 1-8, variant 10xx). Without `version`, the nil and max UUIDs are
|
|
83
|
+
* accepted too.
|
|
84
|
+
* @example isUuid('0190f2a8-1b2c-7d3e-8f40-123456789abc', 7) // => true
|
|
85
|
+
*/
|
|
86
|
+
export declare function isUuid(value: unknown, version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8): value is string;
|
|
87
|
+
/**
|
|
88
|
+
* ULID: 26 Crockford base32 characters, first character 0-7 (48-bit timestamp).
|
|
89
|
+
* @example isUlid('01ARZ3NDEKTSV4RRFFQ69G5FAV') // => true
|
|
90
|
+
*/
|
|
91
|
+
export declare function isUlid(value: unknown): value is string;
|
|
92
|
+
/**
|
|
93
|
+
* Dotted-quad IPv4 with no leading zeros (`01.2.3.4` is rejected as ambiguous octal).
|
|
94
|
+
* @example isIpv4('192.168.0.1') // => true
|
|
95
|
+
*/
|
|
96
|
+
export declare function isIpv4(value: unknown): value is string;
|
|
97
|
+
/**
|
|
98
|
+
* IPv6 in any RFC 4291 text form, including `::` compression and an embedded IPv4 tail.
|
|
99
|
+
* Zone identifiers (`%eth0`) are rejected.
|
|
100
|
+
* @example isIpv6('2001:db8::ff00:42:8329') // => true
|
|
101
|
+
*/
|
|
102
|
+
export declare function isIpv6(value: unknown): value is string;
|
|
103
|
+
/**
|
|
104
|
+
* CIDR block: IPv4 with `/0`-`/32` or IPv6 with `/0`-`/128`.
|
|
105
|
+
* @example isCidr('10.0.0.0/8') // => true
|
|
106
|
+
*/
|
|
107
|
+
export declare function isCidr(value: unknown, version?: 4 | 6): value is string;
|
|
108
|
+
/**
|
|
109
|
+
* MAC-48 address as `01:23:45:67:89:ab`, `01-23-45-67-89-ab` or `0123.4567.89ab`.
|
|
110
|
+
* @example isMacAddress('01:23:45:67:89:AB') // => true
|
|
111
|
+
*/
|
|
112
|
+
export declare function isMacAddress(value: unknown): value is string;
|
|
113
|
+
/**
|
|
114
|
+
* CSS hex colour `#rgb`, `#rrggbb`, and (unless `alpha: false`) `#rgba`, `#rrggbbaa`.
|
|
115
|
+
* @example isHexColor('#1a2b3c') // => true
|
|
116
|
+
*/
|
|
117
|
+
export declare function isHexColor(value: unknown, options?: {
|
|
118
|
+
readonly alpha?: boolean;
|
|
119
|
+
readonly requireHash?: boolean;
|
|
120
|
+
}): value is string;
|
|
121
|
+
/**
|
|
122
|
+
* Lowercase URL slug: ASCII letters and digits in hyphen-separated groups (max 200 chars).
|
|
123
|
+
* @example isSlug('hello-world-2') // => true
|
|
124
|
+
*/
|
|
125
|
+
export declare function isSlug(value: unknown): value is string;
|
|
126
|
+
export interface PasswordPolicy {
|
|
127
|
+
/** Minimum length in code points. Default 12. */
|
|
128
|
+
readonly minLength?: number;
|
|
129
|
+
/** Maximum length in code points (bounds hashing cost). Default 128. */
|
|
130
|
+
readonly maxLength?: number;
|
|
131
|
+
readonly requireLowercase?: boolean;
|
|
132
|
+
readonly requireUppercase?: boolean;
|
|
133
|
+
readonly requireDigit?: boolean;
|
|
134
|
+
readonly requireSymbol?: boolean;
|
|
135
|
+
/** Minimum number of distinct character classes (of the four) regardless of the flags. Default 0. */
|
|
136
|
+
readonly minClasses?: number;
|
|
137
|
+
/** Allow spaces (passphrases). Default false. */
|
|
138
|
+
readonly allowSpaces?: boolean;
|
|
139
|
+
/** Reject passwords from the built-in common list (and `extraCommon`). Default true. */
|
|
140
|
+
readonly rejectCommon?: boolean;
|
|
141
|
+
/** Additional forbidden passwords, such as the product name or the user's e-mail. */
|
|
142
|
+
readonly extraCommon?: readonly string[];
|
|
143
|
+
}
|
|
144
|
+
/** Failure codes returned by {@link isStrongPassword}. */
|
|
145
|
+
export type PasswordFailure = 'too-short' | 'too-long' | 'missing-lowercase' | 'missing-uppercase' | 'missing-digit' | 'missing-symbol' | 'too-few-classes' | 'contains-space' | 'common';
|
|
146
|
+
export interface PasswordCheck {
|
|
147
|
+
readonly valid: boolean;
|
|
148
|
+
readonly failures: readonly PasswordFailure[];
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks a password against a policy and returns every failed rule as a code the UI can
|
|
152
|
+
* translate. Defaults: 12-128 characters, all four classes, no spaces, not common. NIST SP
|
|
153
|
+
* 800-63B favours length over composition; relax the class flags for passphrase policies.
|
|
154
|
+
* @example isStrongPassword('Tr1cky-Horse-42') // => { valid: true, failures: [] }
|
|
155
|
+
* @example isStrongPassword('Password123!').failures // => ['common']
|
|
156
|
+
*/
|
|
157
|
+
export declare function isStrongPassword(value: string, policy?: PasswordPolicy): PasswordCheck;
|
|
158
|
+
/** ISO 3166-1 alpha-2 codes supported by {@link isPostalCode}. @example POSTAL_CODE_COUNTRIES.includes('GB') // => true */
|
|
159
|
+
export declare const POSTAL_CODE_COUNTRIES: readonly string[];
|
|
160
|
+
/**
|
|
161
|
+
* Postal code format for a country in {@link POSTAL_CODE_COUNTRIES} (format only; not an
|
|
162
|
+
* address lookup). Unsupported countries return false.
|
|
163
|
+
* @example isPostalCode('SW1A 1AA', 'GB') // => true
|
|
164
|
+
* @example isPostalCode('90210-1234', 'US') // => true
|
|
165
|
+
*/
|
|
166
|
+
export declare function isPostalCode(value: unknown, country: string): value is string;
|
|
167
|
+
/**
|
|
168
|
+
* Strict calendar date `YYYY-MM-DD` (4-digit year, real day of month).
|
|
169
|
+
* @example isIsoDate('2024-02-29') // => true
|
|
170
|
+
* @example isIsoDate('2023-02-29') // => false
|
|
171
|
+
*/
|
|
172
|
+
export declare function isIsoDate(value: unknown): value is string;
|
|
173
|
+
/**
|
|
174
|
+
* Strict RFC 3339 date-time: `YYYY-MM-DDTHH:mm[:ss[.fraction]]` plus `Z` or `+/-HH:MM`
|
|
175
|
+
* (required unless `requireOffset: false`). Uppercase `T`/`Z` only; no leap seconds.
|
|
176
|
+
* @example isIsoDateTime('2026-09-29T14:30:00.123Z') // => true
|
|
177
|
+
*/
|
|
178
|
+
export declare function isIsoDateTime(value: unknown, options?: {
|
|
179
|
+
readonly requireOffset?: boolean;
|
|
180
|
+
readonly requireSeconds?: boolean;
|
|
181
|
+
}): value is string;
|
|
182
|
+
/**
|
|
183
|
+
* JWS compact serialization shape: three base64url segments whose header is a JSON object with
|
|
184
|
+
* a string `alg` and whose payload is a JSON object. Structure only: this never means the token
|
|
185
|
+
* is valid, trusted or unexpired; verify signatures on the server.
|
|
186
|
+
* @example isJwtShape('eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIn0.c2ln') // => true
|
|
187
|
+
*/
|
|
188
|
+
export declare function isJwtShape(value: unknown, options?: {
|
|
189
|
+
readonly maxLength?: number;
|
|
190
|
+
}): value is string;
|
|
191
|
+
/** Parsed Semantic Versioning 2.0.0 value. */
|
|
192
|
+
export interface SemVer {
|
|
193
|
+
readonly major: number;
|
|
194
|
+
readonly minor: number;
|
|
195
|
+
readonly patch: number;
|
|
196
|
+
readonly prerelease: readonly string[];
|
|
197
|
+
readonly build: readonly string[];
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Parses a strict SemVer 2.0.0 string (no `v` prefix, no leading zeros, safe-integer parts).
|
|
201
|
+
* @example parseSemver('1.2.3-rc.1+build.5') // => { major: 1, minor: 2, patch: 3, prerelease: ['rc', '1'], build: ['build', '5'] }
|
|
202
|
+
*/
|
|
203
|
+
export declare function parseSemver(value: unknown): SemVer | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* Strict SemVer 2.0.0 check.
|
|
206
|
+
* @example isSemver('1.0.0-alpha.1') // => true
|
|
207
|
+
* @example isSemver('01.0.0') // => false
|
|
208
|
+
*/
|
|
209
|
+
export declare function isSemver(value: unknown): value is string;
|
|
210
|
+
/**
|
|
211
|
+
* SemVer 2.0.0 precedence (`-1`, `0`, `1`); build metadata is ignored. Throws a
|
|
212
|
+
* `ValidationError` with code `HLP_VALIDATE_SEMVER` for invalid input.
|
|
213
|
+
* @example compareSemver('1.0.0-alpha', '1.0.0') // => -1
|
|
214
|
+
*/
|
|
215
|
+
export declare function compareSemver(a: string, b: string): -1 | 0 | 1;
|
|
216
|
+
/**
|
|
217
|
+
* Latitude in decimal degrees, -90...90 (number or plain decimal string).
|
|
218
|
+
* @example isLatitude(51.5074) // => true
|
|
219
|
+
*/
|
|
220
|
+
export declare function isLatitude(value: unknown): boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Longitude in decimal degrees, -180...180 (number or plain decimal string).
|
|
223
|
+
* @example isLongitude('-0.1278') // => true
|
|
224
|
+
*/
|
|
225
|
+
export declare function isLongitude(value: unknown): boolean;
|
|
226
|
+
/**
|
|
227
|
+
* EAN-13 / GTIN-13 barcode with a valid check digit.
|
|
228
|
+
* @example isEan13('4006381333931') // => true
|
|
229
|
+
*/
|
|
230
|
+
export declare function isEan13(value: unknown): value is string;
|
|
231
|
+
/**
|
|
232
|
+
* ISBN-10 or ISBN-13 (hyphens and spaces ignored) with a valid check digit. Pass `10` or `13`
|
|
233
|
+
* to require one form.
|
|
234
|
+
* @example isIsbn('978-0-306-40615-7') // => true
|
|
235
|
+
* @example isIsbn('0-306-40615-2', 10) // => true
|
|
236
|
+
*/
|
|
237
|
+
export declare function isIsbn(value: unknown, version?: 10 | 13): value is string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as Z}from"../error/index.js";const f=(e,n)=>typeof e=="string"&&e.length>0&&e.length<=n,E=e=>e>=48&&e<=57,k=e=>e>=65&&e<=90||e>=97&&e<=122,I=(e,n)=>{for(let t=0;t<e.length;t++)if(n(e.charCodeAt(t)))return!0;return!1},G="!#$%&'*+/=?^_`{|}~-",V=new TextEncoder;function _(e,n){return k(e)||E(e)?!0:e<128?G.includes(String.fromCharCode(e)):n&&e>159&&e!==160&&e!==173&&!(e>=8192&&e<=8303)&&e!==65279&&e!==12288}function j(e,n,t){let s=e;if(n&&I(e,o=>o>126)){try{s=new URL(`http://${e}/`).hostname}catch{return!1}if(s.startsWith("["))return!1}if(s.length>253||s.length===0)return!1;const r=s.split(".");if(t&&r.length<2)return!1;for(const o of r){if(o.length===0||o.length>63||o.startsWith("-")||o.endsWith("-"))return!1;for(let u=0;u<o.length;u++){const a=o.charCodeAt(u);if(!k(a)&&!E(a)&&a!==45)return!1}}const i=r[r.length-1]??"";return!(t&&/^\d+$/.test(i))}function te(e,n={}){const{allowIdn:t=!1,requireTld:s=!0}=n;if(!f(e,254))return!1;const r=e.lastIndexOf("@");if(r<1||r===e.length-1)return!1;const i=e.slice(0,r),o=e.slice(r+1);if(V.encode(i).length>64||i.startsWith(".")||i.endsWith(".")||i.includes(".."))return!1;for(let u=0;u<i.length;u++){const a=i.charCodeAt(u);if(a!==46&&!_(a,t))return!1}return j(o,t,s)}function K(e,n={}){const{schemes:t=["http","https"],requireHost:s=!0,allowCredentials:r=!1,maxLength:i=2048}=n;if(!f(e,i)||I(e,a=>a<=32||a===127)||/\s/.test(e))return!1;let o;try{o=new URL(e)}catch{return!1}const u=o.protocol.slice(0,-1).toLowerCase();return!(!t.some(a=>a.toLowerCase()===u)||s&&o.hostname===""||!r&&(o.username!==""||o.password!==""))}function re(e){return K(e)}function se(e){return f(e,16)&&/^\+[1-9]\d{6,14}$/.test(e)}function oe(e){if(!f(e,32)||!/^\+?[\d\s().-]+$/.test(e))return!1;const n=e.replace(/\D/g,"").length;return n>=7&&n<=15}const O={AD:24,AE:23,AL:28,AT:20,AZ:28,BA:20,BE:16,BG:22,BH:22,BI:27,BR:29,BY:28,CH:21,CR:22,CY:28,CZ:24,DE:22,DJ:27,DK:18,DO:28,EE:20,EG:29,ES:24,FI:18,FK:18,FO:18,FR:27,GB:22,GE:22,GI:23,GL:18,GR:27,GT:28,HR:21,HU:28,IE:22,IL:23,IQ:23,IS:26,IT:27,JO:30,KW:30,KZ:20,LB:28,LC:32,LI:21,LT:20,LU:20,LV:21,LY:25,MC:27,MD:24,ME:22,MK:19,MN:20,MR:27,MT:31,MU:30,NI:28,NL:18,NO:15,OM:23,PK:24,PL:28,PS:29,PT:25,QA:29,RO:24,RS:22,RU:33,SA:24,SC:31,SD:18,SE:24,SI:19,SK:24,SM:27,SO:23,ST:25,SV:28,TL:23,TN:24,TR:26,UA:29,VA:22,VG:24,XK:20,YE:30},ie=Object.freeze(Object.keys(O));function J(e){let n=0;for(let t=0;t<e.length;t++){const s=e.charCodeAt(t),r=s>=65?s-55:s-48;n=r>9?(n*100+r)%97:(n*10+r)%97}return n}function ue(e){if(!f(e,50))return!1;const n=e.replaceAll(" ","").toUpperCase();if(!/^[A-Z]{2}\d{2}[A-Z\d]{11,30}$/.test(n))return!1;const t=O[n.slice(0,2)];return t===void 0||t!==n.length?!1:J(n.slice(4)+n.slice(0,4))===1}function ae(e){return f(e,11)&&/^[A-Z]{6}[A-Z\d]{2}(?:[A-Z\d]{3})?$/i.test(e)}function F(e){if(e.length===0||e.length>64)return!1;let n=0,t=!1;for(let s=e.length-1;s>=0;s--){let r=e.charCodeAt(s)-48;if(r<0||r>9)return!1;t&&(r*=2,r>9&&(r-=9)),n+=r,t=!t}return n%10===0}const R=e=>{if(!(!f(e,30)||!/^\d[\d -]*$/.test(e)))return e.replace(/[ -]/g,"")};function fe(e){const n=R(e);return n!==void 0&&n.length>=12&&n.length<=19&&F(n)}const p=(e,n,t,s)=>{if(e.length<n)return!1;const r=Number(e.slice(0,n));return r>=t&&r<=s};function le(e){const n=R(e);if(n===void 0)return;const t=n.length;if(p(n,2,34,34)||p(n,2,37,37))return t===15?"amex":void 0;if(n.startsWith("4"))return t===13||t===16||t===19?"visa":void 0;if(p(n,2,51,55)||p(n,4,2221,2720))return t===16?"mastercard":void 0;if(p(n,3,300,305)||p(n,2,36,36)||p(n,2,38,39))return t>=14&&t<=19?"diners":void 0;if(p(n,4,3528,3589))return t>=16&&t<=19?"jcb":void 0;if(n.startsWith("6011")||p(n,3,644,649)||n.startsWith("65")||p(n,6,622126,622925))return t>=16&&t<=19?"discover":void 0;if(n.startsWith("62")||n.startsWith("81"))return t>=16&&t<=19?"unionpay":void 0;if(["5018","5020","5038","5893","6304","6759","6761","6762","6763"].some(s=>n.startsWith(s))||p(n,2,56,58)||n.startsWith("50")||n.startsWith("6"))return t>=12&&t<=19?"maestro":void 0}const Y=/^[\da-f]{8}-[\da-f]{4}-([1-8])[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;function de(e,n){if(!f(e,36)||e.length!==36)return!1;if(n===void 0&&(e==="00000000-0000-0000-0000-000000000000"||e.toLowerCase()==="ffffffff-ffff-ffff-ffff-ffffffffffff"))return!0;const t=Y.exec(e);return t!==null&&(n===void 0||Number(t[1])===n)}function ce(e){return f(e,26)&&/^[0-7][\dA-HJKMNP-TV-Z]{25}$/i.test(e)}function P(e){if(!f(e,15))return!1;const n=e.split(".");return n.length!==4?!1:n.every(t=>/^(?:0|[1-9]\d{0,2})$/.test(t)&&Number(t)<=255)}function X(e){if(!f(e,45))return!1;const n=e.split("::");if(n.length>2)return!1;const t=i=>{if(i==="")return 0;const o=i.split(":");let u=0;for(let a=0;a<o.length;a++){const c=o[a]??"";if(a===o.length-1&&c.includes(".")){if(!P(c))return;u+=2}else if(/^[\da-f]{1,4}$/i.test(c))u+=1;else return}return u},s=t(n[0]??"");if(s===void 0)return!1;if(n.length===1)return s===8;const r=t(n[1]??"");return r===void 0||(n[0]??"").includes(".")?!1:s+r<=7}function pe(e,n){if(!f(e,49))return!1;const t=e.lastIndexOf("/");if(t<0)return!1;const s=e.slice(0,t),r=e.slice(t+1);if(!/^(?:0|[1-9]\d{0,2})$/.test(r))return!1;const i=Number(r);return n!==6&&P(s)?i<=32:n!==4&&X(s)?i<=128:!1}function ge(e){return f(e,17)?/^[\da-f]{2}(?::[\da-f]{2}){5}$/i.test(e)||/^[\da-f]{2}(?:-[\da-f]{2}){5}$/i.test(e)||/^[\da-f]{4}(?:\.[\da-f]{4}){2}$/i.test(e):!1}function he(e,n={}){const{alpha:t=!0,requireHash:s=!0}=n;if(!f(e,9))return!1;const r=e.startsWith("#")?e.slice(1):s?"":e;return/^[\da-f]+$/i.test(r)?r.length===3||r.length===6||t&&(r.length===4||r.length===8):!1}function me(e){return f(e,200)&&/^[a-z\d]+(?:-[a-z\d]+)*$/.test(e)}const T=new Set(["password","passw0rd","p@ssw0rd","p@ssword","123456","12345678","123456789","1234567890","qwerty","qwertyuiop","abc123","letmein","welcome","admin","administrator","iloveyou","monkey","dragon","football","baseball","sunshine","princess","master","login","trustno1","changeme","secret","qazwsx","111111","000000","default","root","test","guest","summer","winter","spring","autumn"]);function be(e,n={}){const{minLength:t=12,maxLength:s=128,requireLowercase:r=!0,requireUppercase:i=!0,requireDigit:o=!0,requireSymbol:u=!0,minClasses:a=0,allowSpaces:c=!1,rejectCommon:g=!0}=n,l=[],h=typeof e=="string"?e:"";let d=0;for(let b=0;b<h.length&&d<=s;b++){const x=h.charCodeAt(b);(x<56320||x>57343)&&d++}d<t&&l.push("too-short"),d>s&&l.push("too-long");const m=d>s?h.slice(0,s*2):h,$=/\p{Ll}/u.test(m),C=/\p{Lu}/u.test(m),S=/\p{Nd}/u.test(m),L=/[^\p{L}\p{Nd}\s]/u.test(m);if(r&&!$&&l.push("missing-lowercase"),i&&!C&&l.push("missing-uppercase"),o&&!S&&l.push("missing-digit"),u&&!L&&l.push("missing-symbol"),[$,C,S,L].filter(Boolean).length<a&&l.push("too-few-classes"),!c&&/\s/.test(m)&&l.push("contains-space"),g&&m.length<=256){const b=m.toLowerCase(),x=b.replace(/^[\d\W_]{1,8}/,"").replace(/[\d\W_]{1,8}$/,""),N=new Set((n.extraCommon??[]).map(M=>M.toLowerCase()));(T.has(b)||T.has(x)||N.has(b)||N.has(x))&&l.push("common")}return{valid:l.length===0,failures:l}}const y={US:/^\d{5}(?:-\d{4})?$/,CA:/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z] ?\d[ABCEGHJ-NPRSTV-Z]\d$/i,GB:/^(?:GIR ?0AA|[A-PR-UWYZ](?:\d[\dA-HJKPSTUW]?|[A-HK-Y]\d[\dABEHMNPRV-Y]?) ?\d[ABD-HJLNP-UW-Z]{2})$/i,IE:/^(?:[AC-FHKNPRTV-Y]\d{2}|D6W) ?[\dAC-FHKNPRTV-Y]{4}$/i,IN:/^[1-9]\d{2} ?\d{3}$/,DE:/^\d{5}$/,FR:/^\d{5}$/,IT:/^\d{5}$/,ES:/^(?:0[1-9]|[1-4]\d|5[0-2])\d{3}$/,NL:/^[1-9]\d{3} ?(?!SA|SD|SS)[A-Z]{2}$/i,BE:/^[1-9]\d{3}$/,CH:/^[1-9]\d{3}$/,AT:/^[1-9]\d{3}$/,DK:/^\d{4}$/,NO:/^\d{4}$/,SE:/^[1-9]\d{2} ?\d{2}$/,FI:/^\d{5}$/,PL:/^\d{2}-\d{3}$/,PT:/^\d{4}-\d{3}$/,CZ:/^\d{3} ?\d{2}$/,AU:/^\d{4}$/,NZ:/^\d{4}$/,JP:/^\d{3}-?\d{4}$/,CN:/^\d{6}$/,SG:/^\d{6}$/,KR:/^\d{5}$/,BR:/^\d{5}-?\d{3}$/,MX:/^\d{5}$/,ZA:/^\d{4}$/,AE:/^\d{5,6}$/},we=Object.freeze(Object.keys(y));function xe(e,n){const t=Object.prototype.hasOwnProperty.call(y,n.toUpperCase())?y[n.toUpperCase()]:void 0;return t!==void 0&&f(e,10)&&t.test(e.trim())&&e.trim()===e}const z=(e,n)=>n===2?e%4===0&&e%100!==0||e%400===0?29:28:[31,28,31,30,31,30,31,31,30,31,30,31][n-1]??0;function Q(e){if(!f(e,10))return!1;const n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!n)return!1;const t=Number(n[2]),s=Number(n[3]);return t>=1&&t<=12&&s>=1&&s<=z(Number(n[1]),t)}function ye(e,n={}){const{requireOffset:t=!0,requireSeconds:s=!1}=n;if(!f(e,35))return!1;const r=/^(\d{4}-\d{2}-\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,9})?)?(Z|[+-](\d{2}):(\d{2}))?$/.exec(e);return!r?.[1]||!Q(r[1])||Number(r[2])>23||Number(r[3])>59||(r[4]===void 0?s:Number(r[4])>59)?!1:r[5]===void 0?!t:r[5]==="Z"||Number(r[6])<=23&&Number(r[7])<=59}function U(e){const n=e.replaceAll("-","+").replaceAll("_","/"),t=atob(n+"=".repeat((4-n.length%4)%4)),s=Uint8Array.from(t,r=>r.charCodeAt(0));return JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(s))}const D=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function Ae(e,n={}){if(!f(e,n.maxLength??16384))return!1;const t=e.split(".");if(t.length!==3)return!1;const[s="",r="",i=""]=t,o=/^[\w-]+$/;if(!o.test(s)||!o.test(r)||i!==""&&!o.test(i)||s.length%4===1||r.length%4===1||i.length%4===1)return!1;try{const u=U(s);return!D(u)||typeof u.alg!="string"?!1:D(U(r))}catch{return!1}}const B=/^(?:0|[1-9]\d*)$/,W=/^[\da-z-]+$/i;function A(e){if(!f(e,256))return;const n=e.indexOf("+"),t=n<0?e:e.slice(0,n),s=n<0?void 0:e.slice(n+1),r=t.indexOf("-"),i=r<0?t:t.slice(0,r),o=r<0?void 0:t.slice(r+1),u=i.split(".");if(u.length!==3||!u.every(d=>B.test(d)&&d.length<=16))return;const[a=0,c=0,g=0]=u.map(Number);if(![a,c,g].every(Number.isSafeInteger))return;const l=o===void 0?[]:o.split(".");if(o!==void 0&&!l.every(d=>W.test(d)&&(!/^\d+$/.test(d)||B.test(d))))return;const h=s===void 0?[]:s.split(".");if(!(s!==void 0&&!h.every(d=>W.test(d))))return{major:a,minor:c,patch:g,prerelease:l,build:h}}function $e(e){return A(e)!==void 0}const w=(e,n)=>e<n?-1:e>n?1:0;function Ce(e,n){const t=A(e),s=A(n);if(!t||!s)throw new v;const r=w(t.major,s.major)||w(t.minor,s.minor)||w(t.patch,s.patch);if(r!==0)return r;if(t.prerelease.length===0||s.prerelease.length===0)return w(s.prerelease.length,t.prerelease.length);const i=Math.min(t.prerelease.length,s.prerelease.length);for(let o=0;o<i;o++){const u=t.prerelease[o]??"",a=s.prerelease[o]??"";if(u===a)continue;const c=/^\d+$/.test(u),g=/^\d+$/.test(a);return c&&g?u.length!==a.length?w(u.length,a.length):u<a?-1:1:c?-1:g?1:u<a?-1:1}return w(t.prerelease.length,s.prerelease.length)}class v extends Z{constructor(){super("HLP_VALIDATE_SEMVER","Expected a Semantic Versioning 2.0.0 string.")}}const ee=/^[+-]?\d{1,3}(?:\.\d{1,15})?$/,H=e=>{if(typeof e=="number")return Number.isFinite(e)?e:void 0;if(typeof e=="string"&&e.length<=20&&ee.test(e))return Number(e)};function Se(e){const n=H(e);return n!==void 0&&n>=-90&&n<=90}function Le(e){const n=H(e);return n!==void 0&&n>=-180&&n<=180}function q(e){let n=0;for(let t=0;t<12;t++)n+=(e.charCodeAt(t)-48)*(t%2===0?1:3);return(10-n%10)%10===e.charCodeAt(12)-48}function Ne(e){return f(e,13)&&/^\d{13}$/.test(e)&&q(e)}function Ee(e,n){if(!f(e,20)||!/^[\d -]+X?$/i.test(e))return!1;const t=e.replace(/[ -]/g,"").toUpperCase();if(t.length===13&&n!==10)return(t.startsWith("978")||t.startsWith("979"))&&/^\d{13}$/.test(t)&&q(t);if(t.length===10&&n!==13){if(!/^\d{9}[\dX]$/.test(t))return!1;let s=0;for(let r=0;r<10;r++){const i=t.charAt(r);s+=(i==="X"?10:Number(i))*(10-r)}return s%11===0}return!1}export{ie as IBAN_COUNTRIES,we as POSTAL_CODE_COUNTRIES,le as cardBrand,Ce as compareSemver,ae as isBic,pe as isCidr,fe as isCreditCard,Ne as isEan13,te as isEmail,he as isHexColor,re as isHttpUrl,ue as isIban,P as isIpv4,X as isIpv6,Ee as isIsbn,Q as isIsoDate,ye as isIsoDateTime,Ae as isJwtShape,Se as isLatitude,Le as isLongitude,ge as isMacAddress,oe as isPhone,se as isPhoneE164,xe as isPostalCode,$e as isSemver,me as isSlug,be as isStrongPassword,ce as isUlid,K as isUrl,de as isUuid,F as luhnCheck,A as parseSemver};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation: boolean format checks (e-mail, URL, phone, IBAN, cards, identifiers, network
|
|
3
|
+
* addresses, postal codes, dates, versions) and a small composable schema validator with
|
|
4
|
+
* localizable, actionable field messages (docs/PLAN-HELPERS.md section 2, section 5, section 6).
|
|
5
|
+
* @example
|
|
6
|
+
* import { v, validate, type Infer } from '@absoluteui/helpers/validate';
|
|
7
|
+
* const user = v.object({ email: v.string({ email: true }), age: v.optional(v.number({ min: 18 })) });
|
|
8
|
+
* type User = Infer<typeof user>;
|
|
9
|
+
* const r = validate(user, input);
|
|
10
|
+
*/
|
|
11
|
+
export * as v from './builders.js';
|
|
12
|
+
export { validate, createValidator, defaultMessages, type Schema, type OptionalSchema, type Infer, type InferShape, type Issue, type MessageCatalog, type ValidateOptions, type StringOptions, type NumberOptions, type DateOptions, type ObjectOptions, type ParseContext, type Outcome, } from './schema.js';
|
|
13
|
+
export { isEmail, isUrl, isHttpUrl, isPhoneE164, isPhone, isIban, IBAN_COUNTRIES, isBic, luhnCheck, isCreditCard, cardBrand, isUuid, isUlid, isIpv4, isIpv6, isCidr, isMacAddress, isHexColor, isSlug, isStrongPassword, isPostalCode, POSTAL_CODE_COUNTRIES, isIsoDate, isIsoDateTime, isJwtShape, parseSemver, isSemver, compareSemver, isLatitude, isLongitude, isEan13, isIsbn, type EmailOptions, type UrlOptions, type CardBrand, type PasswordPolicy, type PasswordFailure, type PasswordCheck, type SemVer, } from './formats.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import*as s from"./builders.js";import{validate as i,createValidator as a,defaultMessages as p}from"./schema.js";import{isEmail as o,isUrl as d,isHttpUrl as n,isPhoneE164 as y,isPhone as l,isIban as m,IBAN_COUNTRIES as O,isBic as S,luhnCheck as C,isCreditCard as c,cardBrand as I,isUuid as u,isUlid as P,isIpv4 as h,isIpv6 as g,isCidr as v,isMacAddress as E,isHexColor as U,isSlug as f,isStrongPassword as w,isPostalCode as x,POSTAL_CODE_COUNTRIES as b,isIsoDate as B,isIsoDateTime as D,isJwtShape as N,parseSemver as T,isSemver as A,compareSemver as L,isLatitude as M,isLongitude as V,isEan13 as _,isIsbn as k}from"./formats.js";export{O as IBAN_COUNTRIES,b as POSTAL_CODE_COUNTRIES,I as cardBrand,L as compareSemver,a as createValidator,p as defaultMessages,S as isBic,v as isCidr,c as isCreditCard,_ as isEan13,o as isEmail,U as isHexColor,n as isHttpUrl,m as isIban,h as isIpv4,g as isIpv6,k as isIsbn,B as isIsoDate,D as isIsoDateTime,N as isJwtShape,M as isLatitude,V as isLongitude,E as isMacAddress,l as isPhone,y as isPhoneE164,x as isPostalCode,A as isSemver,f as isSlug,w as isStrongPassword,P as isUlid,d as isUrl,u as isUuid,C as luhnCheck,T as parseSemver,s as v,i as validate};
|