@webority/mobile-core 0.0.29 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/lib/commonjs/api/baseUrl.js +1 -34
  2. package/lib/commonjs/api/curl.js +1 -109
  3. package/lib/commonjs/api/multipart.js +1 -21
  4. package/lib/commonjs/api/publicClient.js +1 -79
  5. package/lib/commonjs/api/responseBodyText.js +1 -0
  6. package/lib/commonjs/api/retry.js +1 -91
  7. package/lib/commonjs/api/tokenRefresh.js +1 -205
  8. package/lib/commonjs/api/userClient.js +1 -265
  9. package/lib/commonjs/auth/authStore.js +1 -265
  10. package/lib/commonjs/auth/index.js +1 -44
  11. package/lib/commonjs/auth/jwt.js +1 -112
  12. package/lib/commonjs/config/index.js +1 -72
  13. package/lib/commonjs/deepLink/index.js +1 -286
  14. package/lib/commonjs/download/adapters/expoFs.js +1 -69
  15. package/lib/commonjs/download/adapters/shared.js +1 -13
  16. package/lib/commonjs/download/index.js +1 -250
  17. package/lib/commonjs/formatters/currency.js +1 -70
  18. package/lib/commonjs/formatters/date.js +1 -167
  19. package/lib/commonjs/formatters/dateMath.js +1 -311
  20. package/lib/commonjs/formatters/index.js +1 -246
  21. package/lib/commonjs/formatters/initials.js +1 -32
  22. package/lib/commonjs/formatters/intlCache.js +1 -37
  23. package/lib/commonjs/formatters/number.js +1 -89
  24. package/lib/commonjs/formatters/phone.js +1 -369
  25. package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
  26. package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
  27. package/lib/commonjs/geolocation/index.js +1 -355
  28. package/lib/commonjs/index.js +1 -644
  29. package/lib/commonjs/initSDK.js +1 -66
  30. package/lib/commonjs/initUserAuth.js +1 -37
  31. package/lib/commonjs/logger/crashlytics.js +1 -0
  32. package/lib/commonjs/logger/index.js +1 -301
  33. package/lib/commonjs/logger/redact.js +1 -50
  34. package/lib/commonjs/network/index.js +1 -31
  35. package/lib/commonjs/network/networkStatus.js +1 -171
  36. package/lib/commonjs/permissions/calendar.js +1 -14
  37. package/lib/commonjs/permissions/camera.js +1 -14
  38. package/lib/commonjs/permissions/contacts.js +1 -10
  39. package/lib/commonjs/permissions/index.js +1 -133
  40. package/lib/commonjs/permissions/location.js +1 -14
  41. package/lib/commonjs/permissions/mediaLibrary.js +1 -10
  42. package/lib/commonjs/permissions/notifications.js +1 -10
  43. package/lib/commonjs/permissions/photos.js +1 -14
  44. package/lib/commonjs/phone/countries.js +1 -265
  45. package/lib/commonjs/push/index.js +1 -61
  46. package/lib/commonjs/push/push.js +1 -468
  47. package/lib/commonjs/push/status.js +1 -0
  48. package/lib/commonjs/push/task.js +1 -43
  49. package/lib/commonjs/secureScreen/index.js +1 -0
  50. package/lib/commonjs/share/index.js +1 -70
  51. package/lib/commonjs/smsRetriever/index.js +1 -91
  52. package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
  53. package/lib/commonjs/sqlite/adapters/expo.js +1 -53
  54. package/lib/commonjs/sqlite/index.js +1 -604
  55. package/lib/commonjs/storage/index.js +1 -214
  56. package/lib/commonjs/types/axios.js +1 -4
  57. package/lib/commonjs/types/globals.d.js +1 -6
  58. package/lib/commonjs/utils/base64.js +1 -24
  59. package/lib/commonjs/utils/imageCompression.js +1 -389
  60. package/lib/commonjs/utils/index.js +1 -19
  61. package/lib/commonjs/validators/index.js +1 -227
  62. package/lib/commonjs/versionCheck/index.js +1 -419
  63. package/lib/module/api/baseUrl.js +1 -30
  64. package/lib/module/api/curl.js +1 -104
  65. package/lib/module/api/multipart.js +1 -16
  66. package/lib/module/api/publicClient.js +1 -75
  67. package/lib/module/api/responseBodyText.js +1 -0
  68. package/lib/module/api/retry.js +1 -85
  69. package/lib/module/api/tokenRefresh.js +1 -192
  70. package/lib/module/api/userClient.js +1 -243
  71. package/lib/module/auth/authStore.js +1 -257
  72. package/lib/module/auth/index.js +1 -5
  73. package/lib/module/auth/jwt.js +1 -106
  74. package/lib/module/config/index.js +1 -64
  75. package/lib/module/deepLink/index.js +1 -280
  76. package/lib/module/download/adapters/expoFs.js +1 -64
  77. package/lib/module/download/adapters/shared.js +1 -8
  78. package/lib/module/download/index.js +1 -242
  79. package/lib/module/formatters/currency.js +1 -65
  80. package/lib/module/formatters/date.js +1 -159
  81. package/lib/module/formatters/dateMath.js +1 -295
  82. package/lib/module/formatters/index.js +1 -9
  83. package/lib/module/formatters/initials.js +1 -27
  84. package/lib/module/formatters/intlCache.js +1 -30
  85. package/lib/module/formatters/number.js +1 -82
  86. package/lib/module/formatters/phone.js +1 -302
  87. package/lib/module/formatters/windowsToIanaTable.js +1 -160
  88. package/lib/module/geolocation/adapters/expoLocation.js +1 -121
  89. package/lib/module/geolocation/index.js +1 -347
  90. package/lib/module/index.js +1 -57
  91. package/lib/module/initSDK.js +1 -61
  92. package/lib/module/initUserAuth.js +1 -33
  93. package/lib/module/logger/crashlytics.js +1 -0
  94. package/lib/module/logger/index.js +1 -295
  95. package/lib/module/logger/redact.js +1 -44
  96. package/lib/module/network/index.js +1 -4
  97. package/lib/module/network/networkStatus.js +1 -161
  98. package/lib/module/permissions/calendar.js +1 -15
  99. package/lib/module/permissions/camera.js +1 -15
  100. package/lib/module/permissions/contacts.js +1 -11
  101. package/lib/module/permissions/index.js +1 -128
  102. package/lib/module/permissions/location.js +1 -15
  103. package/lib/module/permissions/mediaLibrary.js +1 -11
  104. package/lib/module/permissions/notifications.js +1 -11
  105. package/lib/module/permissions/photos.js +1 -15
  106. package/lib/module/phone/countries.js +1 -261
  107. package/lib/module/push/index.js +1 -4
  108. package/lib/module/push/push.js +1 -452
  109. package/lib/module/push/status.js +1 -0
  110. package/lib/module/push/task.js +1 -38
  111. package/lib/module/secureScreen/index.js +1 -0
  112. package/lib/module/share/index.js +1 -64
  113. package/lib/module/smsRetriever/index.js +1 -86
  114. package/lib/module/specs/NativeSmsRetriever.js +1 -13
  115. package/lib/module/sqlite/adapters/expo.js +1 -48
  116. package/lib/module/sqlite/index.js +1 -594
  117. package/lib/module/storage/index.js +1 -208
  118. package/lib/module/types/axios.js +1 -4
  119. package/lib/module/types/globals.d.js +1 -10
  120. package/lib/module/utils/base64.js +1 -19
  121. package/lib/module/utils/imageCompression.js +1 -383
  122. package/lib/module/utils/index.js +1 -4
  123. package/lib/module/validators/index.js +1 -205
  124. package/lib/module/versionCheck/index.js +1 -413
  125. package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
  126. package/lib/typescript/commonjs/index.d.ts +5 -0
  127. package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
  128. package/lib/typescript/commonjs/push/index.d.ts +3 -1
  129. package/lib/typescript/commonjs/push/push.d.ts +1 -1
  130. package/lib/typescript/commonjs/push/status.d.ts +9 -0
  131. package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
  132. package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
  133. package/lib/typescript/module/index.d.ts +5 -0
  134. package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
  135. package/lib/typescript/module/push/index.d.ts +3 -1
  136. package/lib/typescript/module/push/push.d.ts +1 -1
  137. package/lib/typescript/module/push/status.d.ts +9 -0
  138. package/lib/typescript/module/secureScreen/index.d.ts +25 -0
  139. package/package.json +23 -4
@@ -1,65 +1 @@
1
- "use strict";
2
-
3
- import { numberFormat } from "./intlCache.js";
4
- const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
5
- const indianGroupingFallback = (n, fractionDigits) => {
6
- // Indian numbering: 1,23,45,678.90 (last 3 digits, then groups of 2).
7
- const sign = n < 0 ? '-' : '';
8
- const abs = Math.abs(n);
9
- const fixed = abs.toFixed(fractionDigits);
10
- const [intPart, decPart] = fixed.split('.');
11
- const last3 = intPart.length > 3 ? intPart.slice(-3) : intPart;
12
- const rest = intPart.length > 3 ? intPart.slice(0, -3) : '';
13
- const grouped = rest ? rest.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + ',' + last3 : last3;
14
- return sign + grouped + (decPart ? `.${decPart}` : '');
15
- };
16
-
17
- /**
18
- * Format an amount as currency. Defaults to **INR** with Indian numbering (`en-IN`),
19
- * which matches the standard convention across Webority projects.
20
- *
21
- * @example
22
- * formatCurrency(150000) // ₹1,50,000
23
- * formatCurrency(1234.5) // ₹1,234.50
24
- * formatCurrency(99, { currency: 'USD', locale: 'en-US' }) // $99.00
25
- * formatCurrency(150000, { stripSymbol: true }) // 1,50,000
26
- */
27
- export const formatCurrency = (amount, options = {}) => {
28
- if (amount == null || Number.isNaN(amount)) {
29
- return '';
30
- }
31
- const {
32
- currency = 'INR',
33
- locale = 'en-IN',
34
- minimumFractionDigits,
35
- maximumFractionDigits = 2,
36
- stripSymbol = false
37
- } = options;
38
- const minFrac = minimumFractionDigits ?? (Number.isInteger(amount) ? 0 : 2);
39
- if (hasIntlNumber()) {
40
- try {
41
- const formatted = numberFormat(locale, {
42
- style: 'currency',
43
- currency,
44
- minimumFractionDigits: minFrac,
45
- maximumFractionDigits
46
- }).format(amount);
47
- if (!stripSymbol) {
48
- return formatted;
49
- }
50
- // Strip currency code/symbol while keeping digits, separators and sign.
51
- return formatted.replace(/[^\d,.\s\-+]/g, '').trim();
52
- } catch {
53
- /* fall through to fallback */
54
- }
55
- }
56
- const numeric = indianGroupingFallback(amount, minFrac);
57
- if (stripSymbol) {
58
- return numeric;
59
- }
60
- if (currency === 'INR') {
61
- return `₹${numeric}`;
62
- }
63
- return `${currency} ${numeric}`;
64
- };
65
- //# sourceMappingURL=currency.js.map
1
+ import{numberFormat as t}from"./intlCache.js";export const formatCurrency=(r,i={})=>{if(null==r||Number.isNaN(r))return"";const{currency:e="INR",locale:n="en-IN",minimumFractionDigits:c,maximumFractionDigits:m=2,stripSymbol:o=!1}=i,s=c??(Number.isInteger(r)?0:2);if("undefined"!=typeof Intl&&"function"==typeof Intl.NumberFormat)try{const i=t(n,{style:"currency",currency:e,minimumFractionDigits:s,maximumFractionDigits:m}).format(r);return o?i.replace(/[^\d,.\s\-+]/g,"").trim():i}catch{}const u=((t,r)=>{const i=t<0?"-":"",e=Math.abs(t).toFixed(r),[n,c]=e.split("."),m=n.length>3?n.slice(-3):n,o=n.length>3?n.slice(0,-3):"";return i+(o?o.replace(/\B(?=(\d{2})+(?!\d))/g,",")+","+m:m)+(c?`.${c}`:"")})(r,s);return o?u:"INR"===e?`₹${u}`:`${e} ${u}`};
@@ -1,159 +1 @@
1
- "use strict";
2
-
3
- import { dateTimeFormat, relativeTimeFormat } from "./intlCache.js";
4
- const toDate = value => {
5
- if (value instanceof Date) {
6
- return Number.isNaN(value.getTime()) ? null : value;
7
- }
8
- const d = new Date(value);
9
- return Number.isNaN(d.getTime()) ? null : d;
10
- };
11
- const hasIntl = () => typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function';
12
- const PAD = n => n < 10 ? `0${n}` : `${n}`;
13
- const fallbackDate = (d, style) => {
14
- const day = PAD(d.getDate());
15
- const monthShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
16
- const monthLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
17
- const year = d.getFullYear();
18
- const weekdayLong = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
19
- switch (style) {
20
- case 'short':
21
- return `${day}/${PAD(d.getMonth() + 1)}/${year}`;
22
- case 'long':
23
- return `${day} ${monthLong} ${year}`;
24
- case 'full':
25
- return `${weekdayLong}, ${day} ${monthLong} ${year}`;
26
- case 'medium':
27
- default:
28
- return `${day} ${monthShort} ${year}`;
29
- }
30
- };
31
- const fallbackTime = (d, style) => {
32
- const hh = PAD(d.getHours());
33
- const mm = PAD(d.getMinutes());
34
- if (style === 'short') {
35
- return `${hh}:${mm}`;
36
- }
37
- const ss = PAD(d.getSeconds());
38
- return `${hh}:${mm}:${ss}`;
39
- };
40
-
41
- /**
42
- * Locale-aware date formatter. Defaults to `'medium'` style and `'en-IN'` locale,
43
- * matching the Indian-locale convention used across Webority apps.
44
- */
45
- export const formatDate = (value, style = 'medium', locale = 'en-IN') => {
46
- const d = toDate(value);
47
- if (!d) {
48
- return '';
49
- }
50
- if (hasIntl()) {
51
- try {
52
- return dateTimeFormat(locale, {
53
- dateStyle: style
54
- }).format(d);
55
- } catch {
56
- /* fall through to fallback */
57
- }
58
- }
59
- return fallbackDate(d, style);
60
- };
61
-
62
- /**
63
- * Locale-aware time formatter (24-hour fallback when Intl is unavailable).
64
- */
65
- export const formatTime = (value, style = 'short', locale = 'en-IN') => {
66
- const d = toDate(value);
67
- if (!d) {
68
- return '';
69
- }
70
- if (hasIntl()) {
71
- try {
72
- return dateTimeFormat(locale, {
73
- timeStyle: style
74
- }).format(d);
75
- } catch {
76
- /* fall through */
77
- }
78
- }
79
- return fallbackTime(d, style);
80
- };
81
-
82
- /**
83
- * Combined date + time formatter.
84
- */
85
- export const formatDateTime = (value, dateStyle = 'medium', timeStyle = 'short', locale = 'en-IN') => {
86
- const d = toDate(value);
87
- if (!d) {
88
- return '';
89
- }
90
- if (hasIntl()) {
91
- try {
92
- return dateTimeFormat(locale, {
93
- dateStyle,
94
- timeStyle
95
- }).format(d);
96
- } catch {
97
- /* fall through */
98
- }
99
- }
100
- return `${fallbackDate(d, dateStyle)}, ${fallbackTime(d, timeStyle)}`;
101
- };
102
- const SECOND = 1000;
103
- const MINUTE = 60 * SECOND;
104
- const HOUR = 60 * MINUTE;
105
- const DAY = 24 * HOUR;
106
- const WEEK = 7 * DAY;
107
- const MONTH = 30 * DAY;
108
- const YEAR = 365 * DAY;
109
-
110
- /**
111
- * Returns a humanized relative-time string (e.g. "5 minutes ago", "in 3 days").
112
- * Uses `Intl.RelativeTimeFormat` when available; otherwise a sensible English fallback.
113
- */
114
- export const formatRelativeTime = (value, base = new Date(), locale = 'en-IN') => {
115
- const target = toDate(value);
116
- const now = toDate(base);
117
- if (!target || !now) {
118
- return '';
119
- }
120
- const diffMs = target.getTime() - now.getTime();
121
- const abs = Math.abs(diffMs);
122
- let unit;
123
- let amount;
124
- if (abs < MINUTE) {
125
- unit = 'second';
126
- amount = Math.round(diffMs / SECOND);
127
- } else if (abs < HOUR) {
128
- unit = 'minute';
129
- amount = Math.round(diffMs / MINUTE);
130
- } else if (abs < DAY) {
131
- unit = 'hour';
132
- amount = Math.round(diffMs / HOUR);
133
- } else if (abs < WEEK) {
134
- unit = 'day';
135
- amount = Math.round(diffMs / DAY);
136
- } else if (abs < MONTH) {
137
- unit = 'week';
138
- amount = Math.round(diffMs / WEEK);
139
- } else if (abs < YEAR) {
140
- unit = 'month';
141
- amount = Math.round(diffMs / MONTH);
142
- } else {
143
- unit = 'year';
144
- amount = Math.round(diffMs / YEAR);
145
- }
146
- const Rtf = hasIntl() ? Intl.RelativeTimeFormat : undefined;
147
- if (typeof Rtf === 'function') {
148
- try {
149
- return relativeTimeFormat(Rtf, locale).format(amount, unit);
150
- } catch {
151
- /* fall through */
152
- }
153
- }
154
- const past = amount < 0;
155
- const n = Math.abs(amount);
156
- const u = n === 1 ? unit : `${unit}s`;
157
- return past ? `${n} ${u} ago` : `in ${n} ${u}`;
158
- };
159
- //# sourceMappingURL=date.js.map
1
+ import{dateTimeFormat as t,relativeTimeFormat as e}from"./intlCache.js";const toDate=t=>{if(t instanceof Date)return Number.isNaN(t.getTime())?null:t;const e=new Date(t);return Number.isNaN(e.getTime())?null:e},hasIntl=()=>"undefined"!=typeof Intl&&"function"==typeof Intl.DateTimeFormat,PAD=t=>t<10?`0${t}`:`${t}`,fallbackDate=(t,e)=>{const r=PAD(t.getDate()),n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()],a=["January","February","March","April","May","June","July","August","September","October","November","December"][t.getMonth()],o=t.getFullYear(),u=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][t.getDay()];switch(e){case"short":return`${r}/${PAD(t.getMonth()+1)}/${o}`;case"long":return`${r} ${a} ${o}`;case"full":return`${u}, ${r} ${a} ${o}`;default:return`${r} ${n} ${o}`}},fallbackTime=(t,e)=>{const r=PAD(t.getHours()),n=PAD(t.getMinutes());if("short"===e)return`${r}:${n}`;return`${r}:${n}:${PAD(t.getSeconds())}`};export const formatDate=(e,r="medium",n="en-IN")=>{const a=toDate(e);if(!a)return"";if(hasIntl())try{return t(n,{dateStyle:r}).format(a)}catch{}return fallbackDate(a,r)};export const formatTime=(e,r="short",n="en-IN")=>{const a=toDate(e);if(!a)return"";if(hasIntl())try{return t(n,{timeStyle:r}).format(a)}catch{}return fallbackTime(a,r)};export const formatDateTime=(e,r="medium",n="short",a="en-IN")=>{const o=toDate(e);if(!o)return"";if(hasIntl())try{return t(a,{dateStyle:r,timeStyle:n}).format(o)}catch{}return`${fallbackDate(o,r)}, ${fallbackTime(o,n)}`};const r=6e4,n=36e5,a=24*n,o=7*a,u=30*a,i=365*a;export const formatRelativeTime=(t,c=new Date,s="en-IN")=>{const m=toDate(t),f=toDate(c);if(!m||!f)return"";const $=m.getTime()-f.getTime(),d=Math.abs($);let h,y;d<r?(h="second",y=Math.round($/1e3)):d<n?(h="minute",y=Math.round($/r)):d<a?(h="hour",y=Math.round($/n)):d<o?(h="day",y=Math.round($/a)):d<u?(h="week",y=Math.round($/o)):d<i?(h="month",y=Math.round($/u)):(h="year",y=Math.round($/i));const l=hasIntl()?Intl.RelativeTimeFormat:void 0;if("function"==typeof l)try{return e(l,s).format(y,h)}catch{}const M=y<0,g=Math.abs(y),p=1===g?h:`${h}s`;return M?`${g} ${p} ago`:`in ${g} ${p}`};
@@ -1,295 +1 @@
1
- "use strict";
2
-
3
- import { dateTimeFormat } from "./intlCache.js";
4
- import { WINDOWS_TO_IANA } from "./windowsToIanaTable.js";
5
- const toDate = value => {
6
- if (value instanceof Date) {
7
- return Number.isNaN(value.getTime()) ? null : value;
8
- }
9
- const d = new Date(value);
10
- return Number.isNaN(d.getTime()) ? null : d;
11
- };
12
- const PAD = n => n < 10 ? `0${n}` : `${n}`;
13
-
14
- /**
15
- * Whether two values fall on the same calendar day in the device's local
16
- * timezone. Invalid input on either side returns false rather than throwing.
17
- */
18
- export const isSameDay = (a, b) => {
19
- const da = toDate(a);
20
- const db = toDate(b);
21
- if (!da || !db) {
22
- return false;
23
- }
24
- return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
25
- };
26
-
27
- /** `a` is strictly before `b`. Invalid input on either side returns false. */
28
- export const isDateBefore = (a, b) => {
29
- const da = toDate(a);
30
- const db = toDate(b);
31
- return da !== null && db !== null && da.getTime() < db.getTime();
32
- };
33
-
34
- /** `a` is strictly after `b`. Invalid input on either side returns false. */
35
- export const isDateAfter = (a, b) => {
36
- const da = toDate(a);
37
- const db = toDate(b);
38
- return da !== null && db !== null && da.getTime() > db.getTime();
39
- };
40
-
41
- /**
42
- * `a - b` in milliseconds, matching dayjs's `a.diff(b)` sign convention
43
- * (positive when `a` is later than `b`). Returns `NaN` if either side fails
44
- * to parse, the same way subtracting two invalid dayjs objects would.
45
- */
46
- export const diffMs = (a, b) => {
47
- const da = toDate(a);
48
- const db = toDate(b);
49
- if (!da || !db) {
50
- return Number.NaN;
51
- }
52
- return da.getTime() - db.getTime();
53
- };
54
-
55
- /**
56
- * Midnight of the given date, in the device's local timezone. Returns null
57
- * for unparseable input.
58
- */
59
- export const startOfDay = value => {
60
- const d = toDate(value);
61
- if (!d) {
62
- return null;
63
- }
64
- const start = new Date(d);
65
- start.setHours(0, 0, 0, 0);
66
- return start;
67
- };
68
-
69
- /**
70
- * Adds (or, with a negative count, subtracts) whole calendar days in the
71
- * device's local timezone. Returns null for unparseable input.
72
- */
73
- export const addDays = (value, count) => {
74
- const d = toDate(value);
75
- if (!d) {
76
- return null;
77
- }
78
- const next = new Date(d);
79
- next.setDate(next.getDate() + count);
80
- return next;
81
- };
82
- const WEEKDAY_SHORT = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
83
- const WEEKDAY_LONG = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
84
- const MONTH_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
85
-
86
- // Longest-first so 'YYYY' is tried before 'YY', 'DD' before 'D', etc. — a
87
- // greedy single pass over the pattern, not a regex, so a literal character
88
- // (a comma, a colon, a digit) can never accidentally match a token.
89
- const TOKENS = ['YYYY', 'YY', 'MMMM', 'MMM', 'MM', 'M', 'DD', 'D', 'dddd', 'ddd', 'HH', 'H', 'hh', 'h', 'mm', 'm', 'ss', 's', 'A', 'a'];
90
- const tokenizePattern = pattern => {
91
- const result = [];
92
- let i = 0;
93
- outer: while (i < pattern.length) {
94
- for (const token of TOKENS) {
95
- if (pattern.startsWith(token, i)) {
96
- result.push(token);
97
- i += token.length;
98
- continue outer;
99
- }
100
- }
101
- result.push(pattern[i]);
102
- i += 1;
103
- }
104
- return result;
105
- };
106
-
107
- /**
108
- * Small dayjs/moment-style token formatter — YYYY/YY, MMMM/MMM/MM/M,
109
- * DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
110
- * Everything else in the pattern (spaces, commas, colons) passes through
111
- * literally. Hand-rolled rather than a dependency because this fleet's date
112
- * formatting needs are a small, closed token set, not general i18n — for
113
- * genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
114
- * `./date`) are the ones to reach for; this is for matching an exact
115
- * existing pattern (a legacy display string, an API's expected shape).
116
- *
117
- * `utc: true` reads every field from the UTC calendar/clock instead of the
118
- * device's local one — see `formatDateDDMMMYYYY`'s note on why this isn't
119
- * cosmetic.
120
- */
121
- export const formatDatePattern = (value, pattern, options) => {
122
- const d = toDate(value);
123
- if (!d) {
124
- return '';
125
- }
126
- const utc = options?.utc ?? false;
127
- const year = utc ? d.getUTCFullYear() : d.getFullYear();
128
- const month = utc ? d.getUTCMonth() : d.getMonth();
129
- const day = utc ? d.getUTCDate() : d.getDate();
130
- const weekday = utc ? d.getUTCDay() : d.getDay();
131
- const hours24 = utc ? d.getUTCHours() : d.getHours();
132
- const minutes = utc ? d.getUTCMinutes() : d.getMinutes();
133
- const seconds = utc ? d.getUTCSeconds() : d.getSeconds();
134
- const {
135
- hour12,
136
- period
137
- } = to12Hour(hours24);
138
- return tokenizePattern(pattern).map(t => {
139
- switch (t) {
140
- case 'YYYY':
141
- return String(year);
142
- case 'YY':
143
- return String(year).slice(-2);
144
- case 'MMMM':
145
- return MONTH_LONG[month];
146
- case 'MMM':
147
- return MONTH_SHORT[month];
148
- case 'MM':
149
- return PAD(month + 1);
150
- case 'M':
151
- return String(month + 1);
152
- case 'DD':
153
- return PAD(day);
154
- case 'D':
155
- return String(day);
156
- case 'dddd':
157
- return WEEKDAY_LONG[weekday];
158
- case 'ddd':
159
- return WEEKDAY_SHORT[weekday];
160
- case 'HH':
161
- return PAD(hours24);
162
- case 'H':
163
- return String(hours24);
164
- case 'hh':
165
- return PAD(hour12);
166
- case 'h':
167
- return String(hour12);
168
- case 'mm':
169
- return PAD(minutes);
170
- case 'm':
171
- return String(minutes);
172
- case 'ss':
173
- return PAD(seconds);
174
- case 's':
175
- return String(seconds);
176
- case 'A':
177
- return period;
178
- case 'a':
179
- return period.toLowerCase();
180
- default:
181
- return t;
182
- }
183
- }).join('');
184
- };
185
- const MONTH_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
186
-
187
- /**
188
- * `DD MMM, YYYY` — zero-padded day, short month, comma, year (e.g.
189
- * `05 Sep, 2025`). A specific legacy pattern some apps already display,
190
- * not the fleet's own product convention: `formatDate` (the Intl `style`-based
191
- * formatter in `./date`) is the one to reach for in new code. This exists so
192
- * an app already showing this exact pattern can move off a date library
193
- * without a visible change.
194
- *
195
- * `utc: true` reads the calendar day from the UTC fields instead of the
196
- * device's local ones — matching `dayjs.utc(x).format(...)`, not
197
- * `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
198
- * day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
199
- * option; pass it only to match a call site that was genuinely UTC-explicit.
200
- */
201
- export const formatDateDDMMMYYYY = (value, options) => {
202
- const d = toDate(value);
203
- if (!d) {
204
- return '';
205
- }
206
- if (options?.utc) {
207
- return `${PAD(d.getUTCDate())} ${MONTH_SHORT[d.getUTCMonth()]}, ${d.getUTCFullYear()}`;
208
- }
209
- return `${PAD(d.getDate())} ${MONTH_SHORT[d.getMonth()]}, ${d.getFullYear()}`;
210
- };
211
-
212
- /** `YYYY-MM-DD`, in the device's local timezone. */
213
- export const formatDateISO = value => {
214
- const d = toDate(value);
215
- if (!d) {
216
- return '';
217
- }
218
- return `${d.getFullYear()}-${PAD(d.getMonth() + 1)}-${PAD(d.getDate())}`;
219
- };
220
- const to12Hour = hours => {
221
- const period = hours >= 12 ? 'PM' : 'AM';
222
- const hour12 = hours % 12 || 12;
223
- return {
224
- hour12,
225
- period
226
- };
227
- };
228
-
229
- /**
230
- * `hh:mm A` in the device's local timezone — zero-padded 12-hour clock,
231
- * uppercase AM/PM (e.g. `09:30 PM`).
232
- */
233
- export const formatTime12h = value => {
234
- const d = toDate(value);
235
- if (!d) {
236
- return '';
237
- }
238
- const {
239
- hour12,
240
- period
241
- } = to12Hour(d.getHours());
242
- return `${PAD(hour12)}:${PAD(d.getMinutes())} ${period}`;
243
- };
244
- const hasIntl = () => typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function';
245
-
246
- /**
247
- * `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
248
- * seen in `ianaTimeZone` (e.g. `Asia/Kolkata`) — not the device's own
249
- * timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
250
- * `formatToParts` rather than its assembled string, because the assembled
251
- * string's spacing before AM/PM varies by JS engine (some insert a narrow
252
- * no-break space, U+202F, instead of a plain space) and isn't reliably
253
- * zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
254
- * recognises — the same failure mode as handing dayjs.tz() a bad zone name.
255
- */
256
- export const formatTimeInZone = (value, ianaTimeZone) => {
257
- const d = toDate(value);
258
- if (!d) {
259
- return '';
260
- }
261
- if (!hasIntl()) {
262
- // No Intl.DateTimeFormat means no reliable IANA timezone database to
263
- // convert against; the device-local fallback below is the least-wrong
264
- // answer available, not a genuine timezone conversion.
265
- return formatTime12h(d);
266
- }
267
- const parts = dateTimeFormat('en-US', {
268
- timeZone: ianaTimeZone,
269
- hour: 'numeric',
270
- minute: '2-digit',
271
- hour12: true
272
- }).formatToParts(d);
273
- const get = type => parts.find(p => p.type === type)?.value ?? '';
274
- const hour = Number.parseInt(get('hour'), 10);
275
- const minute = get('minute');
276
- const period = get('dayPeriod').toLowerCase();
277
- return `${PAD(hour)}:${minute} ${period}`;
278
- };
279
-
280
- /**
281
- * Same as {@link formatTimeInZone}, but for a .NET-style Windows timezone ID
282
- * (e.g. `"India Standard Time"`) rather than an IANA one. .NET's own
283
- * `TimeZoneInfo` API only knows Windows IDs, so a backend built on it hands
284
- * these to clients directly — `Intl`, by contrast, only recognises IANA
285
- * names, so the ID has to be translated before it can be used here. Throws
286
- * if `windowsTimeZoneId` has no known IANA mapping.
287
- */
288
- export const formatTimeInWindowsZone = (value, windowsTimeZoneId) => {
289
- const ianaTimeZone = WINDOWS_TO_IANA[windowsTimeZoneId];
290
- if (!ianaTimeZone) {
291
- throw new Error(`Mapping for Windows time zone '${windowsTimeZoneId}' not found.`);
292
- }
293
- return formatTimeInZone(value, ianaTimeZone);
294
- };
295
- //# sourceMappingURL=dateMath.js.map
1
+ import{dateTimeFormat as e}from"./intlCache.js";import{WINDOWS_TO_IANA as t}from"./windowsToIanaTable.js";const toDate=e=>{if(e instanceof Date)return Number.isNaN(e.getTime())?null:e;const t=new Date(e);return Number.isNaN(t.getTime())?null:t},PAD=e=>e<10?`0${e}`:`${e}`;export const isSameDay=(e,t)=>{const r=toDate(e),n=toDate(t);return!(!r||!n)&&(r.getFullYear()===n.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate())};export const isDateBefore=(e,t)=>{const r=toDate(e),n=toDate(t);return null!==r&&null!==n&&r.getTime()<n.getTime()};export const isDateAfter=(e,t)=>{const r=toDate(e),n=toDate(t);return null!==r&&null!==n&&r.getTime()>n.getTime()};export const diffMs=(e,t)=>{const r=toDate(e),n=toDate(t);return r&&n?r.getTime()-n.getTime():Number.NaN};export const startOfDay=e=>{const t=toDate(e);if(!t)return null;const r=new Date(t);return r.setHours(0,0,0,0),r};export const addDays=(e,t)=>{const r=toDate(e);if(!r)return null;const n=new Date(r);return n.setDate(n.getDate()+t),n};const r=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],o=["January","February","March","April","May","June","July","August","September","October","November","December"],u=["YYYY","YY","MMMM","MMM","MM","M","DD","D","dddd","ddd","HH","H","hh","h","mm","m","ss","s","A","a"];export const formatDatePattern=(e,t,s)=>{const c=toDate(e);if(!c)return"";const i=s?.utc??!1,g=i?c.getUTCFullYear():c.getFullYear(),m=i?c.getUTCMonth():c.getMonth(),l=i?c.getUTCDate():c.getDate(),M=i?c.getUTCDay():c.getDay(),d=i?c.getUTCHours():c.getHours(),f=i?c.getUTCMinutes():c.getMinutes(),D=i?c.getUTCSeconds():c.getSeconds(),{hour12:h,period:T}=to12Hour(d);return(e=>{const t=[];let r=0;e:for(;r<e.length;){for(const n of u)if(e.startsWith(n,r)){t.push(n),r+=n.length;continue e}t.push(e[r]),r+=1}return t})(t).map(e=>{switch(e){case"YYYY":return String(g);case"YY":return String(g).slice(-2);case"MMMM":return o[m];case"MMM":return a[m];case"MM":return PAD(m+1);case"M":return String(m+1);case"DD":return PAD(l);case"D":return String(l);case"dddd":return n[M];case"ddd":return r[M];case"HH":return PAD(d);case"H":return String(d);case"hh":return PAD(h);case"h":return String(h);case"mm":return PAD(f);case"m":return String(f);case"ss":return PAD(D);case"s":return String(D);case"A":return T;case"a":return T.toLowerCase();default:return e}}).join("")};const a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];export const formatDateDDMMMYYYY=(e,t)=>{const r=toDate(e);return r?t?.utc?`${PAD(r.getUTCDate())} ${a[r.getUTCMonth()]}, ${r.getUTCFullYear()}`:`${PAD(r.getDate())} ${a[r.getMonth()]}, ${r.getFullYear()}`:""};export const formatDateISO=e=>{const t=toDate(e);return t?`${t.getFullYear()}-${PAD(t.getMonth()+1)}-${PAD(t.getDate())}`:""};const to12Hour=e=>({hour12:e%12||12,period:e>=12?"PM":"AM"});export const formatTime12h=e=>{const t=toDate(e);if(!t)return"";const{hour12:r,period:n}=to12Hour(t.getHours());return`${PAD(r)}:${PAD(t.getMinutes())} ${n}`};export const formatTimeInZone=(t,r)=>{const n=toDate(t);if(!n)return"";if("undefined"==typeof Intl||"function"!=typeof Intl.DateTimeFormat)return formatTime12h(n);const o=e("en-US",{timeZone:r,hour:"numeric",minute:"2-digit",hour12:!0}).formatToParts(n),get=e=>o.find(t=>t.type===e)?.value??"",u=Number.parseInt(get("hour"),10),a=get("minute"),s=get("dayPeriod").toLowerCase();return`${PAD(u)}:${a} ${s}`};export const formatTimeInWindowsZone=(e,r)=>{const n=t[r];if(!n)throw new Error(`Mapping for Windows time zone '${r}' not found.`);return formatTimeInZone(e,n)};
@@ -1,9 +1 @@
1
- "use strict";
2
-
3
- export { formatCurrency } from "./currency.js";
4
- export { formatDate, formatDateTime, formatRelativeTime, formatTime } from "./date.js";
5
- export { addDays, diffMs, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatTime12h, formatTimeInWindowsZone, formatTimeInZone, isDateAfter, isDateBefore, isSameDay, startOfDay } from "./dateMath.js";
6
- export { getInitials } from "./initials.js";
7
- export { formatCompactNumber, formatNumber, formatPercent } from "./number.js";
8
- export { AsYouType, clampNationalNumber, countryFlagEmoji, detectPhoneCountry, formatPhone, formatPhoneAsTyped, getCountries, getCountryCallingCode, getPhoneCountries, isSupportedCountry, isValidNationalNumber, isValidPhoneNumber, maxNationalNumberLength, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString, splitPhoneNumber, validatePhoneNumberLength } from "./phone.js";
9
- //# sourceMappingURL=index.js.map
1
+ export{formatCurrency}from"./currency.js";export{formatDate,formatDateTime,formatRelativeTime,formatTime}from"./date.js";export{addDays,diffMs,formatDateDDMMMYYYY,formatDateISO,formatDatePattern,formatTime12h,formatTimeInWindowsZone,formatTimeInZone,isDateAfter,isDateBefore,isSameDay,startOfDay}from"./dateMath.js";export{getInitials}from"./initials.js";export{formatCompactNumber,formatNumber,formatPercent}from"./number.js";export{AsYouType,clampNationalNumber,countryFlagEmoji,detectPhoneCountry,formatPhone,formatPhoneAsTyped,getCountries,getCountryCallingCode,getPhoneCountries,isSupportedCountry,isValidNationalNumber,isValidPhoneNumber,maxNationalNumberLength,normalizePhone,parsePhoneNumber,parsePhoneNumberFromString,splitPhoneNumber,validatePhoneNumberLength}from"./phone.js";
@@ -1,27 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Returns up to `maxChars` uppercase initials from a name.
5
- *
6
- * @example
7
- * getInitials('Navneet Singh') // 'NS'
8
- * getInitials('mary anne lee', 3) // 'MAL'
9
- * getInitials('navneet') // 'NA'
10
- * getInitials(' ') // ''
11
- */
12
- export const getInitials = (name, maxChars = 2) => {
13
- if (!name) {
14
- return '';
15
- }
16
- const trimmed = name.trim();
17
- if (!trimmed) {
18
- return '';
19
- }
20
- const parts = trimmed.split(/\s+/);
21
- if (parts.length === 1) {
22
- const single = parts[0] ?? '';
23
- return single.slice(0, maxChars).toUpperCase();
24
- }
25
- return parts.slice(0, maxChars).map(p => (p[0] ?? '').toUpperCase()).join('');
26
- };
27
- //# sourceMappingURL=initials.js.map
1
+ export const getInitials=(t,e=2)=>{if(!t)return"";const r=t.trim();if(!r)return"";const i=r.split(/\s+/);if(1===i.length){return(i[0]??"").slice(0,e).toUpperCase()}return i.slice(0,e).map(t=>(t[0]??"").toUpperCase()).join("")};
@@ -1,30 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * Building an Intl formatter costs far more than using one (and on Hermes for
5
- * Android it goes through ICU over JNI), while list rows and slider frames call
6
- * the formatters many times with the same arguments. Formatters are therefore
7
- * built once per locale and options. The limit only guards against unbounded
8
- * input such as arbitrary time zones; real apps use a handful of keys.
9
- */
10
- const LIMIT = 100;
11
- const cached = (cache, key, create) => {
12
- let formatter = cache.get(key);
13
- if (formatter === undefined) {
14
- formatter = create();
15
- if (cache.size >= LIMIT) {
16
- cache.clear();
17
- }
18
- cache.set(key, formatter);
19
- }
20
- return formatter;
21
- };
22
- const numberFormats = new Map();
23
- const dateTimeFormats = new Map();
24
- const relativeTimeFormats = new Map();
25
- export const numberFormat = (locale, options = {}) => cached(numberFormats, `${locale}|${JSON.stringify(options)}`, () => new Intl.NumberFormat(locale, options));
26
- export const dateTimeFormat = (locale, options) => cached(dateTimeFormats, `${locale}|${JSON.stringify(options)}`, () => new Intl.DateTimeFormat(locale, options));
27
- export const relativeTimeFormat = (RelativeTimeFormat, locale) => cached(relativeTimeFormats, locale, () => new RelativeTimeFormat(locale, {
28
- numeric: 'auto'
29
- }));
30
- //# sourceMappingURL=intlCache.js.map
1
+ const cached=(e,t,n)=>{let r=e.get(t);return void 0===r&&(r=n(),e.size>=100&&e.clear(),e.set(t,r)),r},e=new Map,t=new Map,n=new Map;export const numberFormat=(t,n={})=>cached(e,`${t}|${JSON.stringify(n)}`,()=>new Intl.NumberFormat(t,n));export const dateTimeFormat=(e,n)=>cached(t,`${e}|${JSON.stringify(n)}`,()=>new Intl.DateTimeFormat(e,n));export const relativeTimeFormat=(e,t)=>cached(n,t,()=>new e(t,{numeric:"auto"}));