@webority/mobile-core 0.0.28 → 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 -443
  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 -427
  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 +9 -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 +9 -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,82 +1 @@
1
- "use strict";
2
-
3
- import { numberFormat } from "./intlCache.js";
4
- const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
5
-
6
- /**
7
- * Locale-aware number formatter. Defaults to `'en-IN'` (Indian grouping).
8
- */
9
- export const formatNumber = (value, fractionDigits, locale = 'en-IN') => {
10
- if (value == null || Number.isNaN(value)) {
11
- return '';
12
- }
13
- if (hasIntlNumber()) {
14
- try {
15
- const opts = {};
16
- if (fractionDigits != null) {
17
- opts.minimumFractionDigits = fractionDigits;
18
- opts.maximumFractionDigits = fractionDigits;
19
- }
20
- return numberFormat(locale, opts).format(value);
21
- } catch {
22
- /* fall through */
23
- }
24
- }
25
- return fractionDigits != null ? value.toFixed(fractionDigits) : String(value);
26
- };
27
-
28
- /**
29
- * Format a 0–1 ratio (or 0–100 percent) as a percent string.
30
- * Pass `asRatio: false` if your input is already on the 0–100 scale.
31
- */
32
- export const formatPercent = (value, fractionDigits = 0, asRatio = true, locale = 'en-IN') => {
33
- if (value == null || Number.isNaN(value)) {
34
- return '';
35
- }
36
- const ratio = asRatio ? value : value / 100;
37
- if (hasIntlNumber()) {
38
- try {
39
- return numberFormat(locale, {
40
- style: 'percent',
41
- minimumFractionDigits: fractionDigits,
42
- maximumFractionDigits: fractionDigits
43
- }).format(ratio);
44
- } catch {
45
- /* fall through */
46
- }
47
- }
48
- return `${(ratio * 100).toFixed(fractionDigits)}%`;
49
- };
50
-
51
- /**
52
- * Format a number compactly (1.2K, 3.4M, 1.5L, 2.3Cr).
53
- * Defaults to Indian compact notation via `'en-IN'` locale (lakh / crore).
54
- */
55
- export const formatCompactNumber = (value, locale = 'en-IN') => {
56
- if (value == null || Number.isNaN(value)) {
57
- return '';
58
- }
59
- if (hasIntlNumber()) {
60
- try {
61
- return numberFormat(locale, {
62
- notation: 'compact',
63
- maximumFractionDigits: 1
64
- }).format(value);
65
- } catch {
66
- /* fall through */
67
- }
68
- }
69
- const abs = Math.abs(value);
70
- const sign = value < 0 ? '-' : '';
71
- if (abs >= 1e7) {
72
- return `${sign}${(abs / 1e7).toFixed(1)}Cr`;
73
- }
74
- if (abs >= 1e5) {
75
- return `${sign}${(abs / 1e5).toFixed(1)}L`;
76
- }
77
- if (abs >= 1e3) {
78
- return `${sign}${(abs / 1e3).toFixed(1)}K`;
79
- }
80
- return `${value}`;
81
- };
82
- //# sourceMappingURL=number.js.map
1
+ import{numberFormat as t}from"./intlCache.js";const hasIntlNumber=()=>"undefined"!=typeof Intl&&"function"==typeof Intl.NumberFormat;export const formatNumber=(r,n,e="en-IN")=>{if(null==r||Number.isNaN(r))return"";if(hasIntlNumber())try{const i={};return null!=n&&(i.minimumFractionDigits=n,i.maximumFractionDigits=n),t(e,i).format(r)}catch{}return null!=n?r.toFixed(n):String(r)};export const formatPercent=(r,n=0,e=!0,i="en-IN")=>{if(null==r||Number.isNaN(r))return"";const o=e?r:r/100;if(hasIntlNumber())try{return t(i,{style:"percent",minimumFractionDigits:n,maximumFractionDigits:n}).format(o)}catch{}return`${(100*o).toFixed(n)}%`};export const formatCompactNumber=(r,n="en-IN")=>{if(null==r||Number.isNaN(r))return"";if(hasIntlNumber())try{return t(n,{notation:"compact",maximumFractionDigits:1}).format(r)}catch{}const e=Math.abs(r),i=r<0?"-":"";return e>=1e7?`${i}${(e/1e7).toFixed(1)}Cr`:e>=1e5?`${i}${(e/1e5).toFixed(1)}L`:e>=1e3?`${i}${(e/1e3).toFixed(1)}K`:`${r}`};
@@ -1,302 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * The bare 'libphonenumber-js' entry point actually resolves to the library's
5
- * OWN slimmed-down min/ metadata internally, not its full data - './max' is
6
- * the variant with complete per-country metadata. Since the reason this
7
- * module exists is validation and formatting accuracy, the more accurate
8
- * variant wins throughout this file, not just for validation.
9
- */
10
- import { Metadata } from 'libphonenumber-js/core';
11
- import { AsYouType, getCountries, getCountryCallingCode, parsePhoneNumberFromString, validatePhoneNumberLength } from 'libphonenumber-js/max';
12
- // `Metadata` comes from the core entry with the max data passed in by hand:
13
- // the max entry exports it in its ESM build only, and the CommonJS build jest
14
- // and node resolve has no `Metadata` at all (libphonenumber-js 1.13.12).
15
- import phoneMetadata from 'libphonenumber-js/metadata.max.json';
16
- export { AsYouType, getCountries, getCountryCallingCode, isSupportedCountry, isValidPhoneNumber, parsePhoneNumber, parsePhoneNumberFromString, validatePhoneNumberLength } from 'libphonenumber-js/max';
17
-
18
- /**
19
- * Re-exported under our own name rather than importing CountryCode directly
20
- * everywhere, so a future need to diverge (or re-narrow) has one place to do
21
- * it. Every ISO 3166-1 alpha-2 code libphonenumber-js recognises - formatPhone
22
- * and detectPhoneCountry below are genuinely correct for all of them, not a
23
- * curated subset.
24
- */
25
-
26
- /**
27
- * Strip everything except digits and a leading `+` (preserved if present).
28
- */
29
- export const normalizePhone = input => {
30
- if (!input) {
31
- return '';
32
- }
33
- const trimmed = input.trim();
34
- const hasPlus = trimmed.startsWith('+');
35
- const digits = trimmed.replace(/\D/g, '');
36
- return hasPlus ? `+${digits}` : digits;
37
- };
38
-
39
- /**
40
- * Detect the country of a phone number: from its own `+` country code when
41
- * present, otherwise from `defaultCountryCode`. Returns null when neither
42
- * parses to a recognised country.
43
- */
44
- export const detectPhoneCountry = (input, defaultCountryCode = '+91') => {
45
- const normalized = normalizePhone(input);
46
- if (!normalized) {
47
- return null;
48
- }
49
- if (normalized.startsWith('+')) {
50
- return parsePhoneNumberFromString(normalized)?.country ?? null;
51
- }
52
- const normalizedDefault = normalizePhone(defaultCountryCode);
53
- if (!normalizedDefault.startsWith('+')) {
54
- return null;
55
- }
56
- return parsePhoneNumberFromString(normalizedDefault + normalized)?.country ?? null;
57
- };
58
- const bestEffortGroup = rest => {
59
- // Not a parseable number at all (garbage input, or a real number that's an
60
- // unsupported length for its country): split the country code (first 1-3
61
- // digits) and group the rest in 4s, rather than returning nothing.
62
- const ccLen = rest.length > 11 ? 3 : rest.length > 10 ? 2 : 1;
63
- const cc = rest.slice(0, ccLen);
64
- const number = rest.slice(ccLen);
65
- const grouped = number.replace(/(.{4})(?=.)/g, '$1 ').trim();
66
- return `+${cc} ${grouped}`.trim();
67
- };
68
-
69
- /**
70
- * Format a phone number for human display, via libphonenumber-js's own
71
- * per-country formatting rather than a hand-rolled grouping table - correct
72
- * for every country it recognises, not a curated subset.
73
- *
74
- * - A number that already carries a `+` country code formats for that country.
75
- * - A bare national number formats for `options.country` when given, else for
76
- * the country implied by `defaultCountryCode` (default `+91`).
77
- * - `includeCountryCode` controls international vs national format; defaults
78
- * to international whenever the country was detected rather than passed in
79
- * explicitly as `options.country`, and to national when it was.
80
- * - Input libphonenumber-js can't parse into a valid number for the resolved
81
- * country falls back to a best-effort `+CC NNNN NNNN…` digit grouping.
82
- */
83
-
84
- export function formatPhone(input, arg) {
85
- if (!input) {
86
- return '';
87
- }
88
- const normalized = normalizePhone(input);
89
- if (!normalized) {
90
- return '';
91
- }
92
- const options = typeof arg === 'string' ? {} : arg ?? {};
93
- const defaultCountryCode = typeof arg === 'string' ? arg : options.defaultCountryCode ?? '+91';
94
- const hasOwnCountryCode = normalized.startsWith('+');
95
- let parsed;
96
- // What to best-effort group if parsing fails to produce a valid number.
97
- // Defaults to the plain input; the defaultCountryCode branch below points
98
- // it at the combined digits instead, so a bare number that turns out
99
- // invalid for its detected country still shows that country's code rather
100
- // than silently discarding it.
101
- let fallbackRest = normalized;
102
- if (options.country) {
103
- // parsePhoneNumberFromString ignores this hint when normalized already
104
- // carries its own +, so a real E.164 number is never overridden by a
105
- // wrong or stale options.country.
106
- parsed = parsePhoneNumberFromString(normalized, options.country);
107
- } else if (hasOwnCountryCode) {
108
- parsed = parsePhoneNumberFromString(normalized);
109
- } else {
110
- const normalizedDefault = normalizePhone(defaultCountryCode);
111
- if (normalizedDefault.startsWith('+')) {
112
- const combined = normalizedDefault + normalized;
113
- parsed = parsePhoneNumberFromString(combined);
114
- fallbackRest = combined;
115
- } else {
116
- parsed = undefined;
117
- }
118
- }
119
-
120
- // International by default whenever the country came from the number
121
- // itself (or from defaultCountryCode); national by default only when a
122
- // bare number relied on an explicit options.country to resolve at all.
123
- const includeCcDefault = hasOwnCountryCode || !options.country;
124
- if (parsed?.isValid()) {
125
- const includeCc = options.includeCountryCode ?? includeCcDefault;
126
- return includeCc ? parsed.formatInternational() : parsed.formatNational();
127
- }
128
- return fallbackRest.startsWith('+') ? bestEffortGroup(fallbackRest.slice(1)) : fallbackRest.replace(/(.{4})(?=.)/g, '$1 ').trim();
129
- }
130
-
131
- // ---------------------------------------------------------------------------
132
- // Structured-value helpers. These back PhoneNumberInput in mobile-ui, and are
133
- // exported so an app's own form and API code validates with the same rules
134
- // the field shows on screen, rather than a second regex table.
135
- // ---------------------------------------------------------------------------
136
-
137
- /** Country calling code + national digits, the way a phone field stores them. */
138
-
139
- /**
140
- * Which kinds of number count as valid. `'any'` is libphonenumber's own
141
- * answer (a fixed line passes). `'mobile'` narrows to MOBILE and
142
- * FIXED_LINE_OR_MOBILE, which is what an OTP or WhatsApp field wants: in India
143
- * a 10-digit number starting with 1 to 5 is a real fixed line and passes
144
- * `'any'`, but no SMS will ever reach it.
145
- */
146
-
147
- const onlyDigits = input => input.replace(/\D/g, '');
148
-
149
- /**
150
- * Split a typed or pasted number into calling code + national digits.
151
- * `'+919876543210'` resolves to IN / 91 / 9876543210 from its own prefix; a
152
- * bare `'9876543210'` needs `defaultCountry` to resolve at all. Returns null
153
- * when the input has no digits or no country can be told. A shared calling
154
- * code (`+1` for US and CA) resolves to the country whose area code matches,
155
- * which is why the country comes back as part of the answer rather than being
156
- * looked up again from the code.
157
- */
158
- export const splitPhoneNumber = (input, defaultCountry) => {
159
- const normalized = normalizePhone(input);
160
- if (!normalized || onlyDigits(normalized).length === 0) {
161
- return null;
162
- }
163
- const parsed = normalized.startsWith('+') ? parsePhoneNumberFromString(normalized) : defaultCountry ? parsePhoneNumberFromString(normalized, defaultCountry) : undefined;
164
- if (!parsed) {
165
- return null;
166
- }
167
- return {
168
- country: parsed.country ?? null,
169
- callingCode: parsed.countryCallingCode,
170
- nationalNumber: parsed.nationalNumber
171
- };
172
- };
173
-
174
- /**
175
- * Cut national digits that run past the longest number the country's plan
176
- * allows, so a field stops accepting the impossible without a per-country
177
- * length table. This is the PLAN's ceiling, not a mobile number's: India runs
178
- * to 13 digits (toll-free 1800 numbers), the US to 10, Germany to 15. A field
179
- * that should stop where a subscriber's number ends asks
180
- * `maxNationalNumberLength` instead. Digits within range, including a number
181
- * still too short, pass through untouched.
182
- */
183
- export const clampNationalNumber = (nationalDigits, country) => {
184
- let digits = onlyDigits(nationalDigits);
185
- while (digits.length > 0 && validatePhoneNumberLength(digits, country) === 'TOO_LONG') {
186
- digits = digits.slice(0, -1);
187
- }
188
- return digits;
189
- };
190
-
191
- // The number types a person types into a phone field. Toll-free, premium,
192
- // shared-cost and pager ranges are what push a plan's ceiling past them.
193
- const SUBSCRIBER_TYPES = {
194
- any: ['MOBILE', 'FIXED_LINE'],
195
- mobile: ['MOBILE']
196
- };
197
-
198
- // libphonenumber-js types `numberingPlan` without its per-type accessor; the
199
- // runtime object has it, and a type with no lengths of its own answers with the
200
- // plan's.
201
-
202
- /**
203
- * The most national digits a subscriber's number can have in a country, so a
204
- * field can refuse the next digit as it is typed rather than trimming after.
205
- * `'any'` (default) covers mobile and fixed lines, `'mobile'` mobiles only: India
206
- * is 10 either way (its plan's 13 belongs to toll-free numbers), Germany is 15
207
- * for `'any'` and 11 for `'mobile'`, the UAE 9. A country whose metadata lists
208
- * no lengths by type falls back to the plan's longest number.
209
- */
210
- export const maxNationalNumberLength = (country, kind = 'any') => {
211
- const metadata = new Metadata(phoneMetadata);
212
- metadata.selectNumberingPlan(country);
213
- const plan = metadata.numberingPlan;
214
- if (!plan) {
215
- return E164_MAX_NATIONAL_DIGITS;
216
- }
217
- const byType = SUBSCRIBER_TYPES[kind].flatMap(type => plan.type(type)?.possibleLengths() ?? []);
218
- return Math.max(...(byType.length > 0 ? byType : plan.possibleLengths()));
219
- };
220
-
221
- // E.164 allows 15 digits in total; a national number can never exceed it.
222
- const E164_MAX_NATIONAL_DIGITS = 15;
223
-
224
- /**
225
- * National digits grouped the way the country writes them, updated on every
226
- * keystroke: `'98765'` for IN is `'98765'`, `'9876543210'` is `'98765 43210'`,
227
- * `'2025550123'` for US is `'(202) 555-0123'`. Output is for display only; the
228
- * digits are what a value stores. Digits past the plan's longest possible
229
- * number are dropped first, so an overflowing paste never formats as a longer
230
- * number; digits that fit no pattern come back ungrouped rather than forced
231
- * into a shape.
232
- *
233
- * Countries that write a leading 0 (the UAE, the UK, Australia, Saudi Arabia)
234
- * only group in national mode when that 0 is typed, and a value never holds
235
- * it. When national mode hands the digits back untouched, the grouping comes
236
- * from the international form with the calling code removed: `'501234567'`
237
- * for AE is `'50 123 4567'`. Countries that group nationally are unaffected.
238
- */
239
- export const formatPhoneAsTyped = (nationalDigits, country) => {
240
- const digits = clampNationalNumber(nationalDigits, country);
241
- if (!digits) {
242
- return '';
243
- }
244
- const national = new AsYouType(country).input(digits);
245
- if (national !== digits) {
246
- return national;
247
- }
248
- const prefix = `+${getCountryCallingCode(country)}`;
249
- const international = new AsYouType().input(`${prefix}${digits}`);
250
- return international.startsWith(prefix) ? international.slice(prefix.length).trimStart() || digits : digits;
251
- };
252
-
253
- /**
254
- * Whether national digits form a real number for the country, by the
255
- * country's own numbering plan rather than a length check. `kind: 'mobile'`
256
- * additionally rejects fixed lines; a number whose type the metadata cannot
257
- * tell is accepted, since the metadata, not the number, is what is missing.
258
- */
259
- export const isValidNationalNumber = (nationalDigits, country, kind = 'any') => {
260
- const digits = onlyDigits(nationalDigits);
261
- if (!digits) {
262
- return false;
263
- }
264
- const parsed = parsePhoneNumberFromString(digits, country);
265
- if (!parsed?.isValid()) {
266
- return false;
267
- }
268
- if (kind === 'any') {
269
- return true;
270
- }
271
- const type = parsed.getType();
272
- return type === undefined || type === 'MOBILE' || type === 'FIXED_LINE_OR_MOBILE';
273
- };
274
-
275
- /**
276
- * The flag as an emoji built from the ISO code's two regional-indicator
277
- * letters, so no font asset ships with the library: iOS and Android both draw
278
- * these from the system font. An unknown or malformed code returns ''. (Windows
279
- * browsers render the two letters instead of a flag; that is the platform, not
280
- * the code.)
281
- */
282
- export const countryFlagEmoji = iso => {
283
- const code = iso.trim().toUpperCase();
284
- if (!/^[A-Z]{2}$/.test(code)) {
285
- return '';
286
- }
287
- return String.fromCodePoint(0x1f1e6 + code.charCodeAt(0) - 65, 0x1f1e6 + code.charCodeAt(1) - 65);
288
- };
289
-
290
- /** Calling code + ISO for one country, the shape a country picker lists. */
291
-
292
- /**
293
- * Every country libphonenumber-js knows, with its calling code, in metadata
294
- * order. Names are deliberately not here: they are display data, in one
295
- * language, and live on their own import path (`mobile-core/phone/countries`)
296
- * so an app that never opens a full country list does not carry them.
297
- */
298
- export const getPhoneCountries = () => getCountries().map(iso => ({
299
- iso,
300
- callingCode: getCountryCallingCode(iso)
301
- }));
302
- //# sourceMappingURL=phone.js.map
1
+ import{Metadata as t}from"libphonenumber-js/core";import{AsYouType as n,getCountries as e,getCountryCallingCode as r,parsePhoneNumberFromString as o,validatePhoneNumberLength as i}from"libphonenumber-js/max";import s from"libphonenumber-js/metadata.max.json";export{AsYouType,getCountries,getCountryCallingCode,isSupportedCountry,isValidPhoneNumber,parsePhoneNumber,parsePhoneNumberFromString,validatePhoneNumberLength}from"libphonenumber-js/max";export const normalizePhone=t=>{if(!t)return"";const n=t.trim(),e=n.startsWith("+"),r=n.replace(/\D/g,"");return e?`+${r}`:r};export const detectPhoneCountry=(t,n="+91")=>{const e=normalizePhone(t);if(!e)return null;if(e.startsWith("+"))return o(e)?.country??null;const r=normalizePhone(n);return r.startsWith("+")?o(r+e)?.country??null:null};export function formatPhone(t,n){if(!t)return"";const e=normalizePhone(t);if(!e)return"";const r="string"==typeof n?{}:n??{},i="string"==typeof n?n:r.defaultCountryCode??"+91",s=e.startsWith("+");let l,a=e;if(r.country)l=o(e,r.country);else if(s)l=o(e);else{const t=normalizePhone(i);if(t.startsWith("+")){const n=t+e;l=o(n),a=n}else l=void 0}const u=s||!r.country;if(l?.isValid()){return r.includeCountryCode??u?l.formatInternational():l.formatNational()}return a.startsWith("+")?(t=>{const n=t.length>11?3:t.length>10?2:1;return`+${t.slice(0,n)} ${t.slice(n).replace(/(.{4})(?=.)/g,"$1 ").trim()}`.trim()})(a.slice(1)):a.replace(/(.{4})(?=.)/g,"$1 ").trim()}const onlyDigits=t=>t.replace(/\D/g,"");export const splitPhoneNumber=(t,n)=>{const e=normalizePhone(t);if(!e||0===onlyDigits(e).length)return null;const r=e.startsWith("+")?o(e):n?o(e,n):void 0;return r?{country:r.country??null,callingCode:r.countryCallingCode,nationalNumber:r.nationalNumber}:null};export const clampNationalNumber=(t,n)=>{let e=onlyDigits(t);for(;e.length>0&&"TOO_LONG"===i(e,n);)e=e.slice(0,-1);return e};const l={any:["MOBILE","FIXED_LINE"],mobile:["MOBILE"]};export const maxNationalNumberLength=(n,e="any")=>{const r=new t(s);r.selectNumberingPlan(n);const o=r.numberingPlan;if(!o)return a;const i=l[e].flatMap(t=>o.type(t)?.possibleLengths()??[]);return Math.max(...i.length>0?i:o.possibleLengths())};const a=15;export const formatPhoneAsTyped=(t,e)=>{const o=clampNationalNumber(t,e);if(!o)return"";const i=new n(e).input(o);if(i!==o)return i;const s=`+${r(e)}`,l=(new n).input(`${s}${o}`);return l.startsWith(s)&&l.slice(s.length).trimStart()||o};export const isValidNationalNumber=(t,n,e="any")=>{const r=onlyDigits(t);if(!r)return!1;const i=o(r,n);if(!i?.isValid())return!1;if("any"===e)return!0;const s=i.getType();return void 0===s||"MOBILE"===s||"FIXED_LINE_OR_MOBILE"===s};export const countryFlagEmoji=t=>{const n=t.trim().toUpperCase();return/^[A-Z]{2}$/.test(n)?String.fromCodePoint(127462+n.charCodeAt(0)-65,127462+n.charCodeAt(1)-65):""};export const getPhoneCountries=()=>e().map(t=>({iso:t,callingCode:r(t)}));
@@ -1,160 +1 @@
1
- "use strict";
2
-
3
- /**
4
- * .NET-style Windows time zone ID → IANA time zone name, one entry per
5
- * Windows zone, generated from CLDR's `windowsZones.xml` (the same
6
- * upstream source the retired `windows-iana` npm package derived its own
7
- * table from). Only the `territory="001"` (world-default) row is kept per
8
- * Windows zone — `formatTimeInWindowsZone` only ever reads the first IANA
9
- * candidate, and CLDR's `001` row is exactly that default candidate, so
10
- * per-country territory variants (`US`, `CA`, `ZZ`, …) carry no information
11
- * this table's one caller uses.
12
- *
13
- * Regenerate with `node packages/core/scripts/generate-windows-to-iana-table.mjs
14
- * <path-to-windowsZones.xml>` (CLDR: `common/supplemental/windowsZones.xml` in
15
- * https://github.com/unicode-org/cldr) whenever CLDR adds/renames a zone —
16
- * this is a committed, static table; nothing fetches CLDR at build or test
17
- * time.
18
- */
19
- export const WINDOWS_TO_IANA = {
20
- 'AUS Central Standard Time': 'Australia/Darwin',
21
- 'AUS Eastern Standard Time': 'Australia/Sydney',
22
- 'Afghanistan Standard Time': 'Asia/Kabul',
23
- 'Alaskan Standard Time': 'America/Anchorage',
24
- 'Aleutian Standard Time': 'America/Adak',
25
- 'Altai Standard Time': 'Asia/Barnaul',
26
- 'Arab Standard Time': 'Asia/Riyadh',
27
- 'Arabian Standard Time': 'Asia/Dubai',
28
- 'Arabic Standard Time': 'Asia/Baghdad',
29
- 'Argentina Standard Time': 'America/Buenos_Aires',
30
- 'Astrakhan Standard Time': 'Europe/Astrakhan',
31
- 'Atlantic Standard Time': 'America/Halifax',
32
- 'Aus Central W. Standard Time': 'Australia/Eucla',
33
- 'Azerbaijan Standard Time': 'Asia/Baku',
34
- 'Azores Standard Time': 'Atlantic/Azores',
35
- 'Bahia Standard Time': 'America/Bahia',
36
- 'Bangladesh Standard Time': 'Asia/Dhaka',
37
- 'Belarus Standard Time': 'Europe/Minsk',
38
- 'Bougainville Standard Time': 'Pacific/Bougainville',
39
- 'Canada Central Standard Time': 'America/Regina',
40
- 'Cape Verde Standard Time': 'Atlantic/Cape_Verde',
41
- 'Caucasus Standard Time': 'Asia/Yerevan',
42
- 'Cen. Australia Standard Time': 'Australia/Adelaide',
43
- 'Central America Standard Time': 'America/Guatemala',
44
- 'Central Asia Standard Time': 'Asia/Almaty',
45
- 'Central Brazilian Standard Time': 'America/Cuiaba',
46
- 'Central Europe Standard Time': 'Europe/Budapest',
47
- 'Central European Standard Time': 'Europe/Warsaw',
48
- 'Central Pacific Standard Time': 'Pacific/Guadalcanal',
49
- 'Central Standard Time': 'America/Chicago',
50
- 'Central Standard Time (Mexico)': 'America/Mexico_City',
51
- 'Chatham Islands Standard Time': 'Pacific/Chatham',
52
- 'China Standard Time': 'Asia/Shanghai',
53
- 'Cuba Standard Time': 'America/Havana',
54
- 'Dateline Standard Time': 'Etc/GMT+12',
55
- 'E. Africa Standard Time': 'Africa/Nairobi',
56
- 'E. Australia Standard Time': 'Australia/Brisbane',
57
- 'E. Europe Standard Time': 'Europe/Chisinau',
58
- 'E. South America Standard Time': 'America/Sao_Paulo',
59
- 'Easter Island Standard Time': 'Pacific/Easter',
60
- 'Eastern Standard Time': 'America/New_York',
61
- 'Eastern Standard Time (Mexico)': 'America/Cancun',
62
- 'Egypt Standard Time': 'Africa/Cairo',
63
- 'Ekaterinburg Standard Time': 'Asia/Yekaterinburg',
64
- 'FLE Standard Time': 'Europe/Kiev',
65
- 'Fiji Standard Time': 'Pacific/Fiji',
66
- 'GMT Standard Time': 'Europe/London',
67
- 'GTB Standard Time': 'Europe/Bucharest',
68
- 'Georgian Standard Time': 'Asia/Tbilisi',
69
- 'Greenland Standard Time': 'America/Godthab',
70
- 'Greenwich Standard Time': 'Atlantic/Reykjavik',
71
- 'Haiti Standard Time': 'America/Port-au-Prince',
72
- 'Hawaiian Standard Time': 'Pacific/Honolulu',
73
- 'India Standard Time': 'Asia/Calcutta',
74
- 'Iran Standard Time': 'Asia/Tehran',
75
- 'Israel Standard Time': 'Asia/Jerusalem',
76
- 'Jordan Standard Time': 'Asia/Amman',
77
- 'Kaliningrad Standard Time': 'Europe/Kaliningrad',
78
- 'Korea Standard Time': 'Asia/Seoul',
79
- 'Libya Standard Time': 'Africa/Tripoli',
80
- 'Line Islands Standard Time': 'Pacific/Kiritimati',
81
- 'Lord Howe Standard Time': 'Australia/Lord_Howe',
82
- 'Magadan Standard Time': 'Asia/Magadan',
83
- 'Magallanes Standard Time': 'America/Punta_Arenas',
84
- 'Marquesas Standard Time': 'Pacific/Marquesas',
85
- 'Mauritius Standard Time': 'Indian/Mauritius',
86
- 'Middle East Standard Time': 'Asia/Beirut',
87
- 'Montevideo Standard Time': 'America/Montevideo',
88
- 'Morocco Standard Time': 'Africa/Casablanca',
89
- 'Mountain Standard Time': 'America/Denver',
90
- 'Mountain Standard Time (Mexico)': 'America/Chihuahua',
91
- 'Myanmar Standard Time': 'Asia/Rangoon',
92
- 'N. Central Asia Standard Time': 'Asia/Novosibirsk',
93
- 'Namibia Standard Time': 'Africa/Windhoek',
94
- 'Nepal Standard Time': 'Asia/Katmandu',
95
- 'New Zealand Standard Time': 'Pacific/Auckland',
96
- 'Newfoundland Standard Time': 'America/St_Johns',
97
- 'Norfolk Standard Time': 'Pacific/Norfolk',
98
- 'North Asia East Standard Time': 'Asia/Irkutsk',
99
- 'North Asia Standard Time': 'Asia/Krasnoyarsk',
100
- 'North Korea Standard Time': 'Asia/Pyongyang',
101
- 'Omsk Standard Time': 'Asia/Omsk',
102
- 'Pacific SA Standard Time': 'America/Santiago',
103
- 'Pacific Standard Time': 'America/Los_Angeles',
104
- 'Pacific Standard Time (Mexico)': 'America/Tijuana',
105
- 'Pakistan Standard Time': 'Asia/Karachi',
106
- 'Paraguay Standard Time': 'America/Asuncion',
107
- 'Qyzylorda Standard Time': 'Asia/Qyzylorda',
108
- 'Romance Standard Time': 'Europe/Paris',
109
- 'Russia Time Zone 10': 'Asia/Srednekolymsk',
110
- 'Russia Time Zone 11': 'Asia/Kamchatka',
111
- 'Russia Time Zone 3': 'Europe/Samara',
112
- 'Russian Standard Time': 'Europe/Moscow',
113
- 'SA Eastern Standard Time': 'America/Cayenne',
114
- 'SA Pacific Standard Time': 'America/Bogota',
115
- 'SA Western Standard Time': 'America/La_Paz',
116
- 'SE Asia Standard Time': 'Asia/Bangkok',
117
- 'Saint Pierre Standard Time': 'America/Miquelon',
118
- 'Sakhalin Standard Time': 'Asia/Sakhalin',
119
- 'Samoa Standard Time': 'Pacific/Apia',
120
- 'Sao Tome Standard Time': 'Africa/Sao_Tome',
121
- 'Saratov Standard Time': 'Europe/Saratov',
122
- 'Singapore Standard Time': 'Asia/Singapore',
123
- 'South Africa Standard Time': 'Africa/Johannesburg',
124
- 'South Sudan Standard Time': 'Africa/Juba',
125
- 'Sri Lanka Standard Time': 'Asia/Colombo',
126
- 'Sudan Standard Time': 'Africa/Khartoum',
127
- 'Syria Standard Time': 'Asia/Damascus',
128
- 'Taipei Standard Time': 'Asia/Taipei',
129
- 'Tasmania Standard Time': 'Australia/Hobart',
130
- 'Tocantins Standard Time': 'America/Araguaina',
131
- 'Tokyo Standard Time': 'Asia/Tokyo',
132
- 'Tomsk Standard Time': 'Asia/Tomsk',
133
- 'Tonga Standard Time': 'Pacific/Tongatapu',
134
- 'Transbaikal Standard Time': 'Asia/Chita',
135
- 'Turkey Standard Time': 'Europe/Istanbul',
136
- 'Turks And Caicos Standard Time': 'America/Grand_Turk',
137
- 'US Eastern Standard Time': 'America/Indianapolis',
138
- 'US Mountain Standard Time': 'America/Phoenix',
139
- UTC: 'Etc/UTC',
140
- 'UTC+12': 'Etc/GMT-12',
141
- 'UTC+13': 'Etc/GMT-13',
142
- 'UTC-02': 'Etc/GMT+2',
143
- 'UTC-08': 'Etc/GMT+8',
144
- 'UTC-09': 'Etc/GMT+9',
145
- 'UTC-11': 'Etc/GMT+11',
146
- 'Ulaanbaatar Standard Time': 'Asia/Ulaanbaatar',
147
- 'Venezuela Standard Time': 'America/Caracas',
148
- 'Vladivostok Standard Time': 'Asia/Vladivostok',
149
- 'Volgograd Standard Time': 'Europe/Volgograd',
150
- 'W. Australia Standard Time': 'Australia/Perth',
151
- 'W. Central Africa Standard Time': 'Africa/Lagos',
152
- 'W. Europe Standard Time': 'Europe/Berlin',
153
- 'W. Mongolia Standard Time': 'Asia/Hovd',
154
- 'West Asia Standard Time': 'Asia/Tashkent',
155
- 'West Bank Standard Time': 'Asia/Hebron',
156
- 'West Pacific Standard Time': 'Pacific/Port_Moresby',
157
- 'Yakutsk Standard Time': 'Asia/Yakutsk',
158
- 'Yukon Standard Time': 'America/Whitehorse'
159
- };
160
- //# sourceMappingURL=windowsToIanaTable.js.map
1
+ export const WINDOWS_TO_IANA={"AUS Central Standard Time":"Australia/Darwin","AUS Eastern Standard Time":"Australia/Sydney","Afghanistan Standard Time":"Asia/Kabul","Alaskan Standard Time":"America/Anchorage","Aleutian Standard Time":"America/Adak","Altai Standard Time":"Asia/Barnaul","Arab Standard Time":"Asia/Riyadh","Arabian Standard Time":"Asia/Dubai","Arabic Standard Time":"Asia/Baghdad","Argentina Standard Time":"America/Buenos_Aires","Astrakhan Standard Time":"Europe/Astrakhan","Atlantic Standard Time":"America/Halifax","Aus Central W. Standard Time":"Australia/Eucla","Azerbaijan Standard Time":"Asia/Baku","Azores Standard Time":"Atlantic/Azores","Bahia Standard Time":"America/Bahia","Bangladesh Standard Time":"Asia/Dhaka","Belarus Standard Time":"Europe/Minsk","Bougainville Standard Time":"Pacific/Bougainville","Canada Central Standard Time":"America/Regina","Cape Verde Standard Time":"Atlantic/Cape_Verde","Caucasus Standard Time":"Asia/Yerevan","Cen. Australia Standard Time":"Australia/Adelaide","Central America Standard Time":"America/Guatemala","Central Asia Standard Time":"Asia/Almaty","Central Brazilian Standard Time":"America/Cuiaba","Central Europe Standard Time":"Europe/Budapest","Central European Standard Time":"Europe/Warsaw","Central Pacific Standard Time":"Pacific/Guadalcanal","Central Standard Time":"America/Chicago","Central Standard Time (Mexico)":"America/Mexico_City","Chatham Islands Standard Time":"Pacific/Chatham","China Standard Time":"Asia/Shanghai","Cuba Standard Time":"America/Havana","Dateline Standard Time":"Etc/GMT+12","E. Africa Standard Time":"Africa/Nairobi","E. Australia Standard Time":"Australia/Brisbane","E. Europe Standard Time":"Europe/Chisinau","E. South America Standard Time":"America/Sao_Paulo","Easter Island Standard Time":"Pacific/Easter","Eastern Standard Time":"America/New_York","Eastern Standard Time (Mexico)":"America/Cancun","Egypt Standard Time":"Africa/Cairo","Ekaterinburg Standard Time":"Asia/Yekaterinburg","FLE Standard Time":"Europe/Kiev","Fiji Standard Time":"Pacific/Fiji","GMT Standard Time":"Europe/London","GTB Standard Time":"Europe/Bucharest","Georgian Standard Time":"Asia/Tbilisi","Greenland Standard Time":"America/Godthab","Greenwich Standard Time":"Atlantic/Reykjavik","Haiti Standard Time":"America/Port-au-Prince","Hawaiian Standard Time":"Pacific/Honolulu","India Standard Time":"Asia/Calcutta","Iran Standard Time":"Asia/Tehran","Israel Standard Time":"Asia/Jerusalem","Jordan Standard Time":"Asia/Amman","Kaliningrad Standard Time":"Europe/Kaliningrad","Korea Standard Time":"Asia/Seoul","Libya Standard Time":"Africa/Tripoli","Line Islands Standard Time":"Pacific/Kiritimati","Lord Howe Standard Time":"Australia/Lord_Howe","Magadan Standard Time":"Asia/Magadan","Magallanes Standard Time":"America/Punta_Arenas","Marquesas Standard Time":"Pacific/Marquesas","Mauritius Standard Time":"Indian/Mauritius","Middle East Standard Time":"Asia/Beirut","Montevideo Standard Time":"America/Montevideo","Morocco Standard Time":"Africa/Casablanca","Mountain Standard Time":"America/Denver","Mountain Standard Time (Mexico)":"America/Chihuahua","Myanmar Standard Time":"Asia/Rangoon","N. Central Asia Standard Time":"Asia/Novosibirsk","Namibia Standard Time":"Africa/Windhoek","Nepal Standard Time":"Asia/Katmandu","New Zealand Standard Time":"Pacific/Auckland","Newfoundland Standard Time":"America/St_Johns","Norfolk Standard Time":"Pacific/Norfolk","North Asia East Standard Time":"Asia/Irkutsk","North Asia Standard Time":"Asia/Krasnoyarsk","North Korea Standard Time":"Asia/Pyongyang","Omsk Standard Time":"Asia/Omsk","Pacific SA Standard Time":"America/Santiago","Pacific Standard Time":"America/Los_Angeles","Pacific Standard Time (Mexico)":"America/Tijuana","Pakistan Standard Time":"Asia/Karachi","Paraguay Standard Time":"America/Asuncion","Qyzylorda Standard Time":"Asia/Qyzylorda","Romance Standard Time":"Europe/Paris","Russia Time Zone 10":"Asia/Srednekolymsk","Russia Time Zone 11":"Asia/Kamchatka","Russia Time Zone 3":"Europe/Samara","Russian Standard Time":"Europe/Moscow","SA Eastern Standard Time":"America/Cayenne","SA Pacific Standard Time":"America/Bogota","SA Western Standard Time":"America/La_Paz","SE Asia Standard Time":"Asia/Bangkok","Saint Pierre Standard Time":"America/Miquelon","Sakhalin Standard Time":"Asia/Sakhalin","Samoa Standard Time":"Pacific/Apia","Sao Tome Standard Time":"Africa/Sao_Tome","Saratov Standard Time":"Europe/Saratov","Singapore Standard Time":"Asia/Singapore","South Africa Standard Time":"Africa/Johannesburg","South Sudan Standard Time":"Africa/Juba","Sri Lanka Standard Time":"Asia/Colombo","Sudan Standard Time":"Africa/Khartoum","Syria Standard Time":"Asia/Damascus","Taipei Standard Time":"Asia/Taipei","Tasmania Standard Time":"Australia/Hobart","Tocantins Standard Time":"America/Araguaina","Tokyo Standard Time":"Asia/Tokyo","Tomsk Standard Time":"Asia/Tomsk","Tonga Standard Time":"Pacific/Tongatapu","Transbaikal Standard Time":"Asia/Chita","Turkey Standard Time":"Europe/Istanbul","Turks And Caicos Standard Time":"America/Grand_Turk","US Eastern Standard Time":"America/Indianapolis","US Mountain Standard Time":"America/Phoenix",UTC:"Etc/UTC","UTC+12":"Etc/GMT-12","UTC+13":"Etc/GMT-13","UTC-02":"Etc/GMT+2","UTC-08":"Etc/GMT+8","UTC-09":"Etc/GMT+9","UTC-11":"Etc/GMT+11","Ulaanbaatar Standard Time":"Asia/Ulaanbaatar","Venezuela Standard Time":"America/Caracas","Vladivostok Standard Time":"Asia/Vladivostok","Volgograd Standard Time":"Europe/Volgograd","W. Australia Standard Time":"Australia/Perth","W. Central Africa Standard Time":"Africa/Lagos","W. Europe Standard Time":"Europe/Berlin","W. Mongolia Standard Time":"Asia/Hovd","West Asia Standard Time":"Asia/Tashkent","West Bank Standard Time":"Asia/Hebron","West Pacific Standard Time":"Pacific/Port_Moresby","Yakutsk Standard Time":"Asia/Yakutsk","Yukon Standard Time":"America/Whitehorse"};