@webority/mobile-core 0.0.23

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 (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/android/build.gradle +65 -0
  4. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/AppSignatureHelper.kt +57 -0
  5. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModule.kt +20 -0
  6. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt +146 -0
  7. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverPackage.kt +33 -0
  8. package/lib/commonjs/api/baseUrl.js +34 -0
  9. package/lib/commonjs/api/curl.js +109 -0
  10. package/lib/commonjs/api/publicClient.js +73 -0
  11. package/lib/commonjs/api/retry.js +75 -0
  12. package/lib/commonjs/api/tokenRefresh.js +205 -0
  13. package/lib/commonjs/api/userClient.js +255 -0
  14. package/lib/commonjs/auth/authStore.js +232 -0
  15. package/lib/commonjs/auth/index.js +44 -0
  16. package/lib/commonjs/auth/jwt.js +112 -0
  17. package/lib/commonjs/config/index.js +66 -0
  18. package/lib/commonjs/deepLink/index.js +286 -0
  19. package/lib/commonjs/download/adapters/expoFs.js +69 -0
  20. package/lib/commonjs/download/adapters/shared.js +13 -0
  21. package/lib/commonjs/download/index.js +250 -0
  22. package/lib/commonjs/formatters/currency.js +69 -0
  23. package/lib/commonjs/formatters/date.js +168 -0
  24. package/lib/commonjs/formatters/dateMath.js +310 -0
  25. package/lib/commonjs/formatters/index.js +246 -0
  26. package/lib/commonjs/formatters/initials.js +32 -0
  27. package/lib/commonjs/formatters/number.js +88 -0
  28. package/lib/commonjs/formatters/phone.js +369 -0
  29. package/lib/commonjs/formatters/windowsToIanaTable.js +164 -0
  30. package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
  31. package/lib/commonjs/geolocation/index.js +355 -0
  32. package/lib/commonjs/index.js +630 -0
  33. package/lib/commonjs/initSDK.js +66 -0
  34. package/lib/commonjs/initUserAuth.js +37 -0
  35. package/lib/commonjs/logger/index.js +291 -0
  36. package/lib/commonjs/network/index.js +31 -0
  37. package/lib/commonjs/network/networkStatus.js +133 -0
  38. package/lib/commonjs/package.json +1 -0
  39. package/lib/commonjs/permissions/calendar.js +14 -0
  40. package/lib/commonjs/permissions/camera.js +14 -0
  41. package/lib/commonjs/permissions/contacts.js +10 -0
  42. package/lib/commonjs/permissions/index.js +133 -0
  43. package/lib/commonjs/permissions/location.js +14 -0
  44. package/lib/commonjs/permissions/mediaLibrary.js +10 -0
  45. package/lib/commonjs/permissions/notifications.js +10 -0
  46. package/lib/commonjs/permissions/photos.js +14 -0
  47. package/lib/commonjs/phone/countries.js +265 -0
  48. package/lib/commonjs/share/index.js +70 -0
  49. package/lib/commonjs/smsRetriever/index.js +91 -0
  50. package/lib/commonjs/specs/NativeSmsRetriever.js +15 -0
  51. package/lib/commonjs/sqlite/adapters/expo.js +53 -0
  52. package/lib/commonjs/sqlite/index.js +604 -0
  53. package/lib/commonjs/storage/index.js +214 -0
  54. package/lib/commonjs/types/globals.d.js +6 -0
  55. package/lib/commonjs/utils/imageCompression.js +389 -0
  56. package/lib/commonjs/utils/index.js +19 -0
  57. package/lib/commonjs/validators/index.js +227 -0
  58. package/lib/commonjs/versionCheck/index.js +419 -0
  59. package/lib/module/api/baseUrl.js +30 -0
  60. package/lib/module/api/curl.js +104 -0
  61. package/lib/module/api/publicClient.js +69 -0
  62. package/lib/module/api/retry.js +69 -0
  63. package/lib/module/api/tokenRefresh.js +192 -0
  64. package/lib/module/api/userClient.js +233 -0
  65. package/lib/module/auth/authStore.js +224 -0
  66. package/lib/module/auth/index.js +5 -0
  67. package/lib/module/auth/jwt.js +106 -0
  68. package/lib/module/config/index.js +58 -0
  69. package/lib/module/deepLink/index.js +280 -0
  70. package/lib/module/download/adapters/expoFs.js +64 -0
  71. package/lib/module/download/adapters/shared.js +8 -0
  72. package/lib/module/download/index.js +242 -0
  73. package/lib/module/formatters/currency.js +64 -0
  74. package/lib/module/formatters/date.js +160 -0
  75. package/lib/module/formatters/dateMath.js +294 -0
  76. package/lib/module/formatters/index.js +9 -0
  77. package/lib/module/formatters/initials.js +27 -0
  78. package/lib/module/formatters/number.js +81 -0
  79. package/lib/module/formatters/phone.js +302 -0
  80. package/lib/module/formatters/windowsToIanaTable.js +160 -0
  81. package/lib/module/geolocation/adapters/expoLocation.js +121 -0
  82. package/lib/module/geolocation/index.js +347 -0
  83. package/lib/module/index.js +54 -0
  84. package/lib/module/initSDK.js +61 -0
  85. package/lib/module/initUserAuth.js +33 -0
  86. package/lib/module/logger/index.js +285 -0
  87. package/lib/module/network/index.js +4 -0
  88. package/lib/module/network/networkStatus.js +124 -0
  89. package/lib/module/package.json +1 -0
  90. package/lib/module/permissions/calendar.js +15 -0
  91. package/lib/module/permissions/camera.js +15 -0
  92. package/lib/module/permissions/contacts.js +11 -0
  93. package/lib/module/permissions/index.js +128 -0
  94. package/lib/module/permissions/location.js +15 -0
  95. package/lib/module/permissions/mediaLibrary.js +11 -0
  96. package/lib/module/permissions/notifications.js +11 -0
  97. package/lib/module/permissions/photos.js +15 -0
  98. package/lib/module/phone/countries.js +261 -0
  99. package/lib/module/share/index.js +64 -0
  100. package/lib/module/smsRetriever/index.js +86 -0
  101. package/lib/module/specs/NativeSmsRetriever.js +13 -0
  102. package/lib/module/sqlite/adapters/expo.js +48 -0
  103. package/lib/module/sqlite/index.js +594 -0
  104. package/lib/module/storage/index.js +208 -0
  105. package/lib/module/types/globals.d.js +10 -0
  106. package/lib/module/utils/imageCompression.js +383 -0
  107. package/lib/module/utils/index.js +4 -0
  108. package/lib/module/validators/index.js +205 -0
  109. package/lib/module/versionCheck/index.js +413 -0
  110. package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
  111. package/lib/typescript/commonjs/api/curl.d.ts +18 -0
  112. package/lib/typescript/commonjs/api/publicClient.d.ts +11 -0
  113. package/lib/typescript/commonjs/api/retry.d.ts +27 -0
  114. package/lib/typescript/commonjs/api/tokenRefresh.d.ts +43 -0
  115. package/lib/typescript/commonjs/api/userClient.d.ts +37 -0
  116. package/lib/typescript/commonjs/auth/authStore.d.ts +79 -0
  117. package/lib/typescript/commonjs/auth/index.d.ts +5 -0
  118. package/lib/typescript/commonjs/auth/jwt.d.ts +31 -0
  119. package/lib/typescript/commonjs/config/index.d.ts +55 -0
  120. package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
  121. package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +38 -0
  122. package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
  123. package/lib/typescript/commonjs/download/index.d.ts +86 -0
  124. package/lib/typescript/commonjs/formatters/currency.d.ts +24 -0
  125. package/lib/typescript/commonjs/formatters/date.d.ts +22 -0
  126. package/lib/typescript/commonjs/formatters/dateMath.d.ts +88 -0
  127. package/lib/typescript/commonjs/formatters/index.d.ts +10 -0
  128. package/lib/typescript/commonjs/formatters/initials.d.ts +11 -0
  129. package/lib/typescript/commonjs/formatters/number.d.ts +15 -0
  130. package/lib/typescript/commonjs/formatters/phone.d.ts +133 -0
  131. package/lib/typescript/commonjs/formatters/windowsToIanaTable.d.ts +18 -0
  132. package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
  133. package/lib/typescript/commonjs/geolocation/index.d.ts +90 -0
  134. package/lib/typescript/commonjs/index.d.ts +54 -0
  135. package/lib/typescript/commonjs/initSDK.d.ts +72 -0
  136. package/lib/typescript/commonjs/initUserAuth.d.ts +41 -0
  137. package/lib/typescript/commonjs/logger/index.d.ts +81 -0
  138. package/lib/typescript/commonjs/network/index.d.ts +3 -0
  139. package/lib/typescript/commonjs/network/networkStatus.d.ts +43 -0
  140. package/lib/typescript/commonjs/package.json +1 -0
  141. package/lib/typescript/commonjs/permissions/calendar.d.ts +2 -0
  142. package/lib/typescript/commonjs/permissions/camera.d.ts +2 -0
  143. package/lib/typescript/commonjs/permissions/contacts.d.ts +2 -0
  144. package/lib/typescript/commonjs/permissions/index.d.ts +48 -0
  145. package/lib/typescript/commonjs/permissions/location.d.ts +2 -0
  146. package/lib/typescript/commonjs/permissions/mediaLibrary.d.ts +2 -0
  147. package/lib/typescript/commonjs/permissions/notifications.d.ts +2 -0
  148. package/lib/typescript/commonjs/permissions/photos.d.ts +2 -0
  149. package/lib/typescript/commonjs/phone/countries.d.ts +13 -0
  150. package/lib/typescript/commonjs/share/index.d.ts +29 -0
  151. package/lib/typescript/commonjs/smsRetriever/index.d.ts +30 -0
  152. package/lib/typescript/commonjs/specs/NativeSmsRetriever.d.ts +15 -0
  153. package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
  154. package/lib/typescript/commonjs/sqlite/index.d.ts +113 -0
  155. package/lib/typescript/commonjs/storage/index.d.ts +64 -0
  156. package/lib/typescript/commonjs/utils/imageCompression.d.ts +152 -0
  157. package/lib/typescript/commonjs/utils/index.d.ts +3 -0
  158. package/lib/typescript/commonjs/validators/index.d.ts +51 -0
  159. package/lib/typescript/commonjs/versionCheck/index.d.ts +80 -0
  160. package/lib/typescript/module/api/baseUrl.d.ts +20 -0
  161. package/lib/typescript/module/api/curl.d.ts +18 -0
  162. package/lib/typescript/module/api/publicClient.d.ts +11 -0
  163. package/lib/typescript/module/api/retry.d.ts +27 -0
  164. package/lib/typescript/module/api/tokenRefresh.d.ts +43 -0
  165. package/lib/typescript/module/api/userClient.d.ts +37 -0
  166. package/lib/typescript/module/auth/authStore.d.ts +79 -0
  167. package/lib/typescript/module/auth/index.d.ts +5 -0
  168. package/lib/typescript/module/auth/jwt.d.ts +31 -0
  169. package/lib/typescript/module/config/index.d.ts +55 -0
  170. package/lib/typescript/module/deepLink/index.d.ts +54 -0
  171. package/lib/typescript/module/download/adapters/expoFs.d.ts +38 -0
  172. package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
  173. package/lib/typescript/module/download/index.d.ts +86 -0
  174. package/lib/typescript/module/formatters/currency.d.ts +24 -0
  175. package/lib/typescript/module/formatters/date.d.ts +22 -0
  176. package/lib/typescript/module/formatters/dateMath.d.ts +88 -0
  177. package/lib/typescript/module/formatters/index.d.ts +10 -0
  178. package/lib/typescript/module/formatters/initials.d.ts +11 -0
  179. package/lib/typescript/module/formatters/number.d.ts +15 -0
  180. package/lib/typescript/module/formatters/phone.d.ts +133 -0
  181. package/lib/typescript/module/formatters/windowsToIanaTable.d.ts +18 -0
  182. package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
  183. package/lib/typescript/module/geolocation/index.d.ts +90 -0
  184. package/lib/typescript/module/index.d.ts +54 -0
  185. package/lib/typescript/module/initSDK.d.ts +72 -0
  186. package/lib/typescript/module/initUserAuth.d.ts +41 -0
  187. package/lib/typescript/module/logger/index.d.ts +81 -0
  188. package/lib/typescript/module/network/index.d.ts +3 -0
  189. package/lib/typescript/module/network/networkStatus.d.ts +43 -0
  190. package/lib/typescript/module/package.json +1 -0
  191. package/lib/typescript/module/permissions/calendar.d.ts +2 -0
  192. package/lib/typescript/module/permissions/camera.d.ts +2 -0
  193. package/lib/typescript/module/permissions/contacts.d.ts +2 -0
  194. package/lib/typescript/module/permissions/index.d.ts +48 -0
  195. package/lib/typescript/module/permissions/location.d.ts +2 -0
  196. package/lib/typescript/module/permissions/mediaLibrary.d.ts +2 -0
  197. package/lib/typescript/module/permissions/notifications.d.ts +2 -0
  198. package/lib/typescript/module/permissions/photos.d.ts +2 -0
  199. package/lib/typescript/module/phone/countries.d.ts +13 -0
  200. package/lib/typescript/module/share/index.d.ts +29 -0
  201. package/lib/typescript/module/smsRetriever/index.d.ts +30 -0
  202. package/lib/typescript/module/specs/NativeSmsRetriever.d.ts +15 -0
  203. package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
  204. package/lib/typescript/module/sqlite/index.d.ts +113 -0
  205. package/lib/typescript/module/storage/index.d.ts +64 -0
  206. package/lib/typescript/module/utils/imageCompression.d.ts +152 -0
  207. package/lib/typescript/module/utils/index.d.ts +3 -0
  208. package/lib/typescript/module/validators/index.d.ts +51 -0
  209. package/lib/typescript/module/versionCheck/index.d.ts +80 -0
  210. package/package.json +298 -0
  211. package/src/specs/NativeSmsRetriever.ts +16 -0
@@ -0,0 +1,294 @@
1
+ "use strict";
2
+
3
+ import { WINDOWS_TO_IANA } from "./windowsToIanaTable.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 PAD = n => n < 10 ? `0${n}` : `${n}`;
12
+
13
+ /**
14
+ * Whether two values fall on the same calendar day in the device's local
15
+ * timezone. Invalid input on either side returns false rather than throwing.
16
+ */
17
+ export const isSameDay = (a, b) => {
18
+ const da = toDate(a);
19
+ const db = toDate(b);
20
+ if (!da || !db) {
21
+ return false;
22
+ }
23
+ return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
24
+ };
25
+
26
+ /** `a` is strictly before `b`. Invalid input on either side returns false. */
27
+ export const isDateBefore = (a, b) => {
28
+ const da = toDate(a);
29
+ const db = toDate(b);
30
+ return da !== null && db !== null && da.getTime() < db.getTime();
31
+ };
32
+
33
+ /** `a` is strictly after `b`. Invalid input on either side returns false. */
34
+ export const isDateAfter = (a, b) => {
35
+ const da = toDate(a);
36
+ const db = toDate(b);
37
+ return da !== null && db !== null && da.getTime() > db.getTime();
38
+ };
39
+
40
+ /**
41
+ * `a - b` in milliseconds, matching dayjs's `a.diff(b)` sign convention
42
+ * (positive when `a` is later than `b`). Returns `NaN` if either side fails
43
+ * to parse, the same way subtracting two invalid dayjs objects would.
44
+ */
45
+ export const diffMs = (a, b) => {
46
+ const da = toDate(a);
47
+ const db = toDate(b);
48
+ if (!da || !db) {
49
+ return Number.NaN;
50
+ }
51
+ return da.getTime() - db.getTime();
52
+ };
53
+
54
+ /**
55
+ * Midnight of the given date, in the device's local timezone. Returns null
56
+ * for unparseable input.
57
+ */
58
+ export const startOfDay = value => {
59
+ const d = toDate(value);
60
+ if (!d) {
61
+ return null;
62
+ }
63
+ const start = new Date(d);
64
+ start.setHours(0, 0, 0, 0);
65
+ return start;
66
+ };
67
+
68
+ /**
69
+ * Adds (or, with a negative count, subtracts) whole calendar days in the
70
+ * device's local timezone. Returns null for unparseable input.
71
+ */
72
+ export const addDays = (value, count) => {
73
+ const d = toDate(value);
74
+ if (!d) {
75
+ return null;
76
+ }
77
+ const next = new Date(d);
78
+ next.setDate(next.getDate() + count);
79
+ return next;
80
+ };
81
+ const WEEKDAY_SHORT = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
82
+ const WEEKDAY_LONG = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
83
+ const MONTH_LONG = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
84
+
85
+ // Longest-first so 'YYYY' is tried before 'YY', 'DD' before 'D', etc. — a
86
+ // greedy single pass over the pattern, not a regex, so a literal character
87
+ // (a comma, a colon, a digit) can never accidentally match a token.
88
+ const TOKENS = ['YYYY', 'YY', 'MMMM', 'MMM', 'MM', 'M', 'DD', 'D', 'dddd', 'ddd', 'HH', 'H', 'hh', 'h', 'mm', 'm', 'ss', 's', 'A', 'a'];
89
+ const tokenizePattern = pattern => {
90
+ const result = [];
91
+ let i = 0;
92
+ outer: while (i < pattern.length) {
93
+ for (const token of TOKENS) {
94
+ if (pattern.startsWith(token, i)) {
95
+ result.push(token);
96
+ i += token.length;
97
+ continue outer;
98
+ }
99
+ }
100
+ result.push(pattern[i]);
101
+ i += 1;
102
+ }
103
+ return result;
104
+ };
105
+
106
+ /**
107
+ * Small dayjs/moment-style token formatter — YYYY/YY, MMMM/MMM/MM/M,
108
+ * DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
109
+ * Everything else in the pattern (spaces, commas, colons) passes through
110
+ * literally. Hand-rolled rather than a dependency because this fleet's date
111
+ * formatting needs are a small, closed token set, not general i18n — for
112
+ * genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
113
+ * `./date`) are the ones to reach for; this is for matching an exact
114
+ * existing pattern (a legacy display string, an API's expected shape).
115
+ *
116
+ * `utc: true` reads every field from the UTC calendar/clock instead of the
117
+ * device's local one — see `formatDateDDMMMYYYY`'s note on why this isn't
118
+ * cosmetic.
119
+ */
120
+ export const formatDatePattern = (value, pattern, options) => {
121
+ const d = toDate(value);
122
+ if (!d) {
123
+ return '';
124
+ }
125
+ const utc = options?.utc ?? false;
126
+ const year = utc ? d.getUTCFullYear() : d.getFullYear();
127
+ const month = utc ? d.getUTCMonth() : d.getMonth();
128
+ const day = utc ? d.getUTCDate() : d.getDate();
129
+ const weekday = utc ? d.getUTCDay() : d.getDay();
130
+ const hours24 = utc ? d.getUTCHours() : d.getHours();
131
+ const minutes = utc ? d.getUTCMinutes() : d.getMinutes();
132
+ const seconds = utc ? d.getUTCSeconds() : d.getSeconds();
133
+ const {
134
+ hour12,
135
+ period
136
+ } = to12Hour(hours24);
137
+ return tokenizePattern(pattern).map(t => {
138
+ switch (t) {
139
+ case 'YYYY':
140
+ return String(year);
141
+ case 'YY':
142
+ return String(year).slice(-2);
143
+ case 'MMMM':
144
+ return MONTH_LONG[month];
145
+ case 'MMM':
146
+ return MONTH_SHORT[month];
147
+ case 'MM':
148
+ return PAD(month + 1);
149
+ case 'M':
150
+ return String(month + 1);
151
+ case 'DD':
152
+ return PAD(day);
153
+ case 'D':
154
+ return String(day);
155
+ case 'dddd':
156
+ return WEEKDAY_LONG[weekday];
157
+ case 'ddd':
158
+ return WEEKDAY_SHORT[weekday];
159
+ case 'HH':
160
+ return PAD(hours24);
161
+ case 'H':
162
+ return String(hours24);
163
+ case 'hh':
164
+ return PAD(hour12);
165
+ case 'h':
166
+ return String(hour12);
167
+ case 'mm':
168
+ return PAD(minutes);
169
+ case 'm':
170
+ return String(minutes);
171
+ case 'ss':
172
+ return PAD(seconds);
173
+ case 's':
174
+ return String(seconds);
175
+ case 'A':
176
+ return period;
177
+ case 'a':
178
+ return period.toLowerCase();
179
+ default:
180
+ return t;
181
+ }
182
+ }).join('');
183
+ };
184
+ const MONTH_SHORT = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
185
+
186
+ /**
187
+ * `DD MMM, YYYY` — zero-padded day, short month, comma, year (e.g.
188
+ * `05 Sep, 2025`). A specific legacy pattern some apps already display,
189
+ * not the fleet's own product convention: `formatDate` (the Intl `style`-based
190
+ * formatter in `./date`) is the one to reach for in new code. This exists so
191
+ * an app already showing this exact pattern can move off a date library
192
+ * without a visible change.
193
+ *
194
+ * `utc: true` reads the calendar day from the UTC fields instead of the
195
+ * device's local ones — matching `dayjs.utc(x).format(...)`, not
196
+ * `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
197
+ * day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
198
+ * option; pass it only to match a call site that was genuinely UTC-explicit.
199
+ */
200
+ export const formatDateDDMMMYYYY = (value, options) => {
201
+ const d = toDate(value);
202
+ if (!d) {
203
+ return '';
204
+ }
205
+ if (options?.utc) {
206
+ return `${PAD(d.getUTCDate())} ${MONTH_SHORT[d.getUTCMonth()]}, ${d.getUTCFullYear()}`;
207
+ }
208
+ return `${PAD(d.getDate())} ${MONTH_SHORT[d.getMonth()]}, ${d.getFullYear()}`;
209
+ };
210
+
211
+ /** `YYYY-MM-DD`, in the device's local timezone. */
212
+ export const formatDateISO = value => {
213
+ const d = toDate(value);
214
+ if (!d) {
215
+ return '';
216
+ }
217
+ return `${d.getFullYear()}-${PAD(d.getMonth() + 1)}-${PAD(d.getDate())}`;
218
+ };
219
+ const to12Hour = hours => {
220
+ const period = hours >= 12 ? 'PM' : 'AM';
221
+ const hour12 = hours % 12 || 12;
222
+ return {
223
+ hour12,
224
+ period
225
+ };
226
+ };
227
+
228
+ /**
229
+ * `hh:mm A` in the device's local timezone — zero-padded 12-hour clock,
230
+ * uppercase AM/PM (e.g. `09:30 PM`).
231
+ */
232
+ export const formatTime12h = value => {
233
+ const d = toDate(value);
234
+ if (!d) {
235
+ return '';
236
+ }
237
+ const {
238
+ hour12,
239
+ period
240
+ } = to12Hour(d.getHours());
241
+ return `${PAD(hour12)}:${PAD(d.getMinutes())} ${period}`;
242
+ };
243
+ const hasIntl = () => typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function';
244
+
245
+ /**
246
+ * `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
247
+ * seen in `ianaTimeZone` (e.g. `Asia/Kolkata`) — not the device's own
248
+ * timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
249
+ * `formatToParts` rather than its assembled string, because the assembled
250
+ * string's spacing before AM/PM varies by JS engine (some insert a narrow
251
+ * no-break space, U+202F, instead of a plain space) and isn't reliably
252
+ * zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
253
+ * recognises — the same failure mode as handing dayjs.tz() a bad zone name.
254
+ */
255
+ export const formatTimeInZone = (value, ianaTimeZone) => {
256
+ const d = toDate(value);
257
+ if (!d) {
258
+ return '';
259
+ }
260
+ if (!hasIntl()) {
261
+ // No Intl.DateTimeFormat means no reliable IANA timezone database to
262
+ // convert against; the device-local fallback below is the least-wrong
263
+ // answer available, not a genuine timezone conversion.
264
+ return formatTime12h(d);
265
+ }
266
+ const parts = new Intl.DateTimeFormat('en-US', {
267
+ timeZone: ianaTimeZone,
268
+ hour: 'numeric',
269
+ minute: '2-digit',
270
+ hour12: true
271
+ }).formatToParts(d);
272
+ const get = type => parts.find(p => p.type === type)?.value ?? '';
273
+ const hour = Number.parseInt(get('hour'), 10);
274
+ const minute = get('minute');
275
+ const period = get('dayPeriod').toLowerCase();
276
+ return `${PAD(hour)}:${minute} ${period}`;
277
+ };
278
+
279
+ /**
280
+ * Same as {@link formatTimeInZone}, but for a .NET-style Windows timezone ID
281
+ * (e.g. `"India Standard Time"`) rather than an IANA one. .NET's own
282
+ * `TimeZoneInfo` API only knows Windows IDs, so a backend built on it hands
283
+ * these to clients directly — `Intl`, by contrast, only recognises IANA
284
+ * names, so the ID has to be translated before it can be used here. Throws
285
+ * if `windowsTimeZoneId` has no known IANA mapping.
286
+ */
287
+ export const formatTimeInWindowsZone = (value, windowsTimeZoneId) => {
288
+ const ianaTimeZone = WINDOWS_TO_IANA[windowsTimeZoneId];
289
+ if (!ianaTimeZone) {
290
+ throw new Error(`Mapping for Windows time zone '${windowsTimeZoneId}' not found.`);
291
+ }
292
+ return formatTimeInZone(value, ianaTimeZone);
293
+ };
294
+ //# sourceMappingURL=dateMath.js.map
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
4
+
5
+ /**
6
+ * Locale-aware number formatter. Defaults to `'en-IN'` (Indian grouping).
7
+ */
8
+ export const formatNumber = (value, fractionDigits, locale = 'en-IN') => {
9
+ if (value == null || Number.isNaN(value)) {
10
+ return '';
11
+ }
12
+ if (hasIntlNumber()) {
13
+ try {
14
+ const opts = {};
15
+ if (fractionDigits != null) {
16
+ opts.minimumFractionDigits = fractionDigits;
17
+ opts.maximumFractionDigits = fractionDigits;
18
+ }
19
+ return new Intl.NumberFormat(locale, opts).format(value);
20
+ } catch {
21
+ /* fall through */
22
+ }
23
+ }
24
+ return fractionDigits != null ? value.toFixed(fractionDigits) : String(value);
25
+ };
26
+
27
+ /**
28
+ * Format a 0–1 ratio (or 0–100 percent) as a percent string.
29
+ * Pass `asRatio: false` if your input is already on the 0–100 scale.
30
+ */
31
+ export const formatPercent = (value, fractionDigits = 0, asRatio = true, locale = 'en-IN') => {
32
+ if (value == null || Number.isNaN(value)) {
33
+ return '';
34
+ }
35
+ const ratio = asRatio ? value : value / 100;
36
+ if (hasIntlNumber()) {
37
+ try {
38
+ return new Intl.NumberFormat(locale, {
39
+ style: 'percent',
40
+ minimumFractionDigits: fractionDigits,
41
+ maximumFractionDigits: fractionDigits
42
+ }).format(ratio);
43
+ } catch {
44
+ /* fall through */
45
+ }
46
+ }
47
+ return `${(ratio * 100).toFixed(fractionDigits)}%`;
48
+ };
49
+
50
+ /**
51
+ * Format a number compactly (1.2K, 3.4M, 1.5L, 2.3Cr).
52
+ * Defaults to Indian compact notation via `'en-IN'` locale (lakh / crore).
53
+ */
54
+ export const formatCompactNumber = (value, locale = 'en-IN') => {
55
+ if (value == null || Number.isNaN(value)) {
56
+ return '';
57
+ }
58
+ if (hasIntlNumber()) {
59
+ try {
60
+ return new Intl.NumberFormat(locale, {
61
+ notation: 'compact',
62
+ maximumFractionDigits: 1
63
+ }).format(value);
64
+ } catch {
65
+ /* fall through */
66
+ }
67
+ }
68
+ const abs = Math.abs(value);
69
+ const sign = value < 0 ? '-' : '';
70
+ if (abs >= 1e7) {
71
+ return `${sign}${(abs / 1e7).toFixed(1)}Cr`;
72
+ }
73
+ if (abs >= 1e5) {
74
+ return `${sign}${(abs / 1e5).toFixed(1)}L`;
75
+ }
76
+ if (abs >= 1e3) {
77
+ return `${sign}${(abs / 1e3).toFixed(1)}K`;
78
+ }
79
+ return `${value}`;
80
+ };
81
+ //# sourceMappingURL=number.js.map