@webority/mobile-core 0.0.29 → 0.2.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.
- package/README.md +32 -0
- package/lib/commonjs/api/baseUrl.js +1 -34
- package/lib/commonjs/api/clientHeaders.js +1 -0
- package/lib/commonjs/api/curl.js +1 -109
- package/lib/commonjs/api/minAppVersion.js +1 -0
- package/lib/commonjs/api/multipart.js +1 -21
- package/lib/commonjs/api/publicClient.js +1 -79
- package/lib/commonjs/api/requestDefaults.js +1 -0
- package/lib/commonjs/api/responseBodyText.js +1 -0
- package/lib/commonjs/api/retry.js +1 -91
- package/lib/commonjs/api/tokenRefresh.js +1 -205
- package/lib/commonjs/api/userClient.js +1 -265
- package/lib/commonjs/auth/authStore.js +1 -265
- package/lib/commonjs/auth/index.js +1 -44
- package/lib/commonjs/auth/jwt.js +1 -112
- package/lib/commonjs/config/index.js +1 -72
- package/lib/commonjs/deepLink/index.js +1 -286
- package/lib/commonjs/download/adapters/expoFs.js +1 -69
- package/lib/commonjs/download/adapters/shared.js +1 -13
- package/lib/commonjs/download/index.js +1 -250
- package/lib/commonjs/errors/extractApiError.js +1 -0
- package/lib/commonjs/errors/index.js +1 -0
- package/lib/commonjs/formatters/currency.js +1 -70
- package/lib/commonjs/formatters/date.js +1 -167
- package/lib/commonjs/formatters/dateMath.js +1 -311
- package/lib/commonjs/formatters/formatConfig.js +1 -0
- package/lib/commonjs/formatters/house.js +1 -0
- package/lib/commonjs/formatters/index.js +1 -246
- package/lib/commonjs/formatters/initials.js +1 -32
- package/lib/commonjs/formatters/intlCache.js +1 -37
- package/lib/commonjs/formatters/number.js +1 -89
- package/lib/commonjs/formatters/phone.js +1 -369
- package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
- package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
- package/lib/commonjs/geolocation/index.js +1 -355
- package/lib/commonjs/index.js +1 -644
- package/lib/commonjs/initSDK.js +1 -66
- package/lib/commonjs/initUserAuth.js +1 -37
- package/lib/commonjs/logger/crashlytics.js +1 -0
- package/lib/commonjs/logger/index.js +1 -301
- package/lib/commonjs/logger/redact.js +1 -50
- package/lib/commonjs/network/index.js +1 -31
- package/lib/commonjs/network/networkStatus.js +1 -171
- package/lib/commonjs/permissions/calendar.js +1 -14
- package/lib/commonjs/permissions/camera.js +1 -14
- package/lib/commonjs/permissions/contacts.js +1 -10
- package/lib/commonjs/permissions/index.js +1 -133
- package/lib/commonjs/permissions/location.js +1 -14
- package/lib/commonjs/permissions/mediaLibrary.js +1 -10
- package/lib/commonjs/permissions/notifications.js +1 -10
- package/lib/commonjs/permissions/photos.js +1 -14
- package/lib/commonjs/phone/countries.js +1 -265
- package/lib/commonjs/push/index.js +1 -61
- package/lib/commonjs/push/push.js +1 -468
- package/lib/commonjs/push/status.js +1 -0
- package/lib/commonjs/push/task.js +1 -43
- package/lib/commonjs/query/apiBaseQuery.js +1 -0
- package/lib/commonjs/query/createAppApi.js +1 -0
- package/lib/commonjs/query/index.js +1 -0
- package/lib/commonjs/query/listeners.js +1 -0
- package/lib/commonjs/query/paging.js +1 -0
- package/lib/commonjs/query/tags.js +1 -0
- package/lib/commonjs/redux/errorToastMiddleware.js +1 -0
- package/lib/commonjs/redux/index.js +1 -0
- package/lib/commonjs/redux/rootReducer.js +1 -0
- package/lib/commonjs/redux/serializableCheck.js +1 -0
- package/lib/commonjs/secureScreen/index.js +1 -0
- package/lib/commonjs/share/index.js +1 -70
- package/lib/commonjs/smsRetriever/index.js +1 -91
- package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
- package/lib/commonjs/sqlite/adapters/expo.js +1 -53
- package/lib/commonjs/sqlite/index.js +1 -604
- package/lib/commonjs/storage/index.js +1 -214
- package/lib/commonjs/types/axios.js +1 -4
- package/lib/commonjs/types/globals.d.js +1 -6
- package/lib/commonjs/utils/base64.js +1 -24
- package/lib/commonjs/utils/imageCompression.js +1 -389
- package/lib/commonjs/utils/index.js +1 -19
- package/lib/commonjs/validators/index.js +1 -227
- package/lib/commonjs/versionCheck/buildNumber.js +1 -0
- package/lib/commonjs/versionCheck/index.js +1 -419
- package/lib/module/api/baseUrl.js +1 -30
- package/lib/module/api/clientHeaders.js +1 -0
- package/lib/module/api/curl.js +1 -104
- package/lib/module/api/minAppVersion.js +1 -0
- package/lib/module/api/multipart.js +1 -16
- package/lib/module/api/publicClient.js +1 -75
- package/lib/module/api/requestDefaults.js +1 -0
- package/lib/module/api/responseBodyText.js +1 -0
- package/lib/module/api/retry.js +1 -85
- package/lib/module/api/tokenRefresh.js +1 -192
- package/lib/module/api/userClient.js +1 -243
- package/lib/module/auth/authStore.js +1 -257
- package/lib/module/auth/index.js +1 -5
- package/lib/module/auth/jwt.js +1 -106
- package/lib/module/config/index.js +1 -64
- package/lib/module/deepLink/index.js +1 -280
- package/lib/module/download/adapters/expoFs.js +1 -64
- package/lib/module/download/adapters/shared.js +1 -8
- package/lib/module/download/index.js +1 -242
- package/lib/module/errors/extractApiError.js +1 -0
- package/lib/module/errors/index.js +1 -0
- package/lib/module/formatters/currency.js +1 -65
- package/lib/module/formatters/date.js +1 -159
- package/lib/module/formatters/dateMath.js +1 -295
- package/lib/module/formatters/formatConfig.js +1 -0
- package/lib/module/formatters/house.js +1 -0
- package/lib/module/formatters/index.js +1 -9
- package/lib/module/formatters/initials.js +1 -27
- package/lib/module/formatters/intlCache.js +1 -30
- package/lib/module/formatters/number.js +1 -82
- package/lib/module/formatters/phone.js +1 -302
- package/lib/module/formatters/windowsToIanaTable.js +1 -160
- package/lib/module/geolocation/adapters/expoLocation.js +1 -121
- package/lib/module/geolocation/index.js +1 -347
- package/lib/module/index.js +1 -57
- package/lib/module/initSDK.js +1 -61
- package/lib/module/initUserAuth.js +1 -33
- package/lib/module/logger/crashlytics.js +1 -0
- package/lib/module/logger/index.js +1 -295
- package/lib/module/logger/redact.js +1 -44
- package/lib/module/network/index.js +1 -4
- package/lib/module/network/networkStatus.js +1 -161
- package/lib/module/permissions/calendar.js +1 -15
- package/lib/module/permissions/camera.js +1 -15
- package/lib/module/permissions/contacts.js +1 -11
- package/lib/module/permissions/index.js +1 -128
- package/lib/module/permissions/location.js +1 -15
- package/lib/module/permissions/mediaLibrary.js +1 -11
- package/lib/module/permissions/notifications.js +1 -11
- package/lib/module/permissions/photos.js +1 -15
- package/lib/module/phone/countries.js +1 -261
- package/lib/module/push/index.js +1 -4
- package/lib/module/push/push.js +1 -452
- package/lib/module/push/status.js +1 -0
- package/lib/module/push/task.js +1 -38
- package/lib/module/query/apiBaseQuery.js +1 -0
- package/lib/module/query/createAppApi.js +1 -0
- package/lib/module/query/index.js +1 -0
- package/lib/module/query/listeners.js +1 -0
- package/lib/module/query/paging.js +1 -0
- package/lib/module/query/tags.js +1 -0
- package/lib/module/redux/errorToastMiddleware.js +1 -0
- package/lib/module/redux/index.js +1 -0
- package/lib/module/redux/rootReducer.js +1 -0
- package/lib/module/redux/serializableCheck.js +1 -0
- package/lib/module/secureScreen/index.js +1 -0
- package/lib/module/share/index.js +1 -64
- package/lib/module/smsRetriever/index.js +1 -86
- package/lib/module/specs/NativeSmsRetriever.js +1 -13
- package/lib/module/sqlite/adapters/expo.js +1 -48
- package/lib/module/sqlite/index.js +1 -594
- package/lib/module/storage/index.js +1 -208
- package/lib/module/types/axios.js +1 -4
- package/lib/module/types/globals.d.js +1 -10
- package/lib/module/utils/base64.js +1 -19
- package/lib/module/utils/imageCompression.js +1 -383
- package/lib/module/utils/index.js +1 -4
- package/lib/module/validators/index.js +1 -205
- package/lib/module/versionCheck/buildNumber.js +1 -0
- package/lib/module/versionCheck/index.js +1 -413
- package/lib/typescript/commonjs/api/clientHeaders.d.ts +25 -0
- package/lib/typescript/commonjs/api/minAppVersion.d.ts +24 -0
- package/lib/typescript/commonjs/api/requestDefaults.d.ts +21 -0
- package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/commonjs/api/retry.d.ts +23 -9
- package/lib/typescript/commonjs/api/tokenRefresh.d.ts +14 -2
- package/lib/typescript/commonjs/api/userClient.d.ts +1 -1
- package/lib/typescript/commonjs/auth/authStore.d.ts +76 -0
- package/lib/typescript/commonjs/auth/index.d.ts +2 -2
- package/lib/typescript/commonjs/config/index.d.ts +31 -2
- package/lib/typescript/commonjs/errors/extractApiError.d.ts +69 -0
- package/lib/typescript/commonjs/errors/index.d.ts +3 -0
- package/lib/typescript/commonjs/formatters/currency.d.ts +22 -7
- package/lib/typescript/commonjs/formatters/date.d.ts +13 -13
- package/lib/typescript/commonjs/formatters/dateMath.d.ts +4 -2
- package/lib/typescript/commonjs/formatters/formatConfig.d.ts +48 -0
- package/lib/typescript/commonjs/formatters/house.d.ts +143 -0
- package/lib/typescript/commonjs/formatters/index.d.ts +4 -0
- package/lib/typescript/commonjs/formatters/number.d.ts +15 -5
- package/lib/typescript/commonjs/index.d.ts +26 -8
- package/lib/typescript/commonjs/initSDK.d.ts +18 -6
- package/lib/typescript/commonjs/initUserAuth.d.ts +29 -0
- package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/commonjs/logger/index.d.ts +17 -0
- package/lib/typescript/commonjs/push/index.d.ts +3 -1
- package/lib/typescript/commonjs/push/push.d.ts +1 -1
- package/lib/typescript/commonjs/push/status.d.ts +9 -0
- package/lib/typescript/commonjs/query/apiBaseQuery.d.ts +55 -0
- package/lib/typescript/commonjs/query/createAppApi.d.ts +21 -0
- package/lib/typescript/commonjs/query/index.d.ts +9 -0
- package/lib/typescript/commonjs/query/listeners.d.ts +11 -0
- package/lib/typescript/commonjs/query/paging.d.ts +42 -0
- package/lib/typescript/commonjs/query/tags.d.ts +31 -0
- package/lib/typescript/commonjs/redux/errorToastMiddleware.d.ts +51 -0
- package/lib/typescript/commonjs/redux/index.d.ts +6 -0
- package/lib/typescript/commonjs/redux/rootReducer.d.ts +19 -0
- package/lib/typescript/commonjs/redux/serializableCheck.d.ts +14 -0
- package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
- package/lib/typescript/commonjs/versionCheck/buildNumber.d.ts +14 -0
- package/lib/typescript/commonjs/versionCheck/index.d.ts +28 -17
- package/lib/typescript/module/api/clientHeaders.d.ts +25 -0
- package/lib/typescript/module/api/minAppVersion.d.ts +24 -0
- package/lib/typescript/module/api/requestDefaults.d.ts +21 -0
- package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/module/api/retry.d.ts +23 -9
- package/lib/typescript/module/api/tokenRefresh.d.ts +14 -2
- package/lib/typescript/module/api/userClient.d.ts +1 -1
- package/lib/typescript/module/auth/authStore.d.ts +76 -0
- package/lib/typescript/module/auth/index.d.ts +2 -2
- package/lib/typescript/module/config/index.d.ts +31 -2
- package/lib/typescript/module/errors/extractApiError.d.ts +69 -0
- package/lib/typescript/module/errors/index.d.ts +3 -0
- package/lib/typescript/module/formatters/currency.d.ts +22 -7
- package/lib/typescript/module/formatters/date.d.ts +13 -13
- package/lib/typescript/module/formatters/dateMath.d.ts +4 -2
- package/lib/typescript/module/formatters/formatConfig.d.ts +48 -0
- package/lib/typescript/module/formatters/house.d.ts +143 -0
- package/lib/typescript/module/formatters/index.d.ts +4 -0
- package/lib/typescript/module/formatters/number.d.ts +15 -5
- package/lib/typescript/module/index.d.ts +26 -8
- package/lib/typescript/module/initSDK.d.ts +18 -6
- package/lib/typescript/module/initUserAuth.d.ts +29 -0
- package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/module/logger/index.d.ts +17 -0
- package/lib/typescript/module/push/index.d.ts +3 -1
- package/lib/typescript/module/push/push.d.ts +1 -1
- package/lib/typescript/module/push/status.d.ts +9 -0
- package/lib/typescript/module/query/apiBaseQuery.d.ts +55 -0
- package/lib/typescript/module/query/createAppApi.d.ts +21 -0
- package/lib/typescript/module/query/index.d.ts +9 -0
- package/lib/typescript/module/query/listeners.d.ts +11 -0
- package/lib/typescript/module/query/paging.d.ts +42 -0
- package/lib/typescript/module/query/tags.d.ts +31 -0
- package/lib/typescript/module/redux/errorToastMiddleware.d.ts +51 -0
- package/lib/typescript/module/redux/index.d.ts +6 -0
- package/lib/typescript/module/redux/rootReducer.d.ts +19 -0
- package/lib/typescript/module/redux/serializableCheck.d.ts +14 -0
- package/lib/typescript/module/secureScreen/index.d.ts +25 -0
- package/lib/typescript/module/versionCheck/buildNumber.d.ts +14 -0
- package/lib/typescript/module/versionCheck/index.d.ts +28 -17
- package/package.json +52 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";export const SERVER_FAILURE_MESSAGE="Something went wrong on our side. Please try again in a moment.";export const OFFLINE_MESSAGE="You appear to be offline. Check your connection and try again.";export const TIMEOUT_MESSAGE="That took too long to respond. Check your connection and try again.";export const UNEXPECTED_MESSAGE="Something went wrong. Please try again.";export const REQUEST_CANCELED_CODE="request_canceled";export const CONTRACT_ERROR_CODE="contract_error";export const TIMEOUT_CODE="timeout";export const NETWORK_CODE="network";const MAX_MESSAGE_LENGTH=300,requestFailedMessage=e=>`Request failed (${e})`,isDict=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),nonEmptyString=e=>"string"==typeof e&&e.trim().length>0?e:null,looksLikeDiagnostics=e=>e.length>300||/^\s*</.test(e)||e.includes("\n at ")||/\b(Exception|StackTrace):/.test(e)||/\b(System|Microsoft)\.[A-Za-z]+\.[A-Za-z]/.test(e),userSafe=e=>{const t=nonEmptyString(e);return null===t||looksLikeDiagnostics(t)?null:t};export const toFieldPath=e=>e.replace(/^\$\.?/,"").split(".").map(e=>e.charAt(0).toLowerCase()+e.slice(1)).join(".");const firstMessage=e=>{if(Array.isArray(e)){for(const t of e){const e=nonEmptyString(t);if(null!==e)return e}return null}return nonEmptyString(e)},addError=(e,t,r)=>{const n=toFieldPath(t);""===n?e.form??=r:n in e.fields||(e.fields[n]=r)},readErrors=e=>{const t={fields:{},form:null};if(Array.isArray(e)){for(const r of e){if(!isDict(r))continue;const e=nonEmptyString(r.message);null!==e&&addError(t,"string"==typeof r.field?r.field:"",e)}return t}if(!isDict(e))return t;for(const[r,n]of Object.entries(e)){const e=firstMessage(n);null!==e&&addError(t,r,e)}return t},readLegacyError=e=>{const t=e.error;return isDict(t)?nonEmptyString(t.message):nonEmptyString(t)};export const isApiError=e=>isDict(e)&&"string"==typeof e.message&&"number"==typeof e.status&&"boolean"==typeof e.offline&&isDict(e.fieldErrors);const build=e=>({code:null,fieldErrors:{},status:0,offline:!1,traceId:null,detail:null,...e}),fromNoResponse=e=>{const t=nonEmptyString(e.code),r=nonEmptyString(e.name),n=nonEmptyString(e.message);return build("CanceledError"===r||"ERR_CANCELED"===t?{code:"request_canceled",message:UNEXPECTED_MESSAGE,detail:n}:"ECONNABORTED"===t||"ETIMEDOUT"===t?{code:"timeout",message:TIMEOUT_MESSAGE,offline:!0,detail:n}:"RequestOfflineError"===r||"ERR_NETWORK"===t||"Network Error"===n?{code:"network",message:OFFLINE_MESSAGE,offline:!0,detail:n}:{message:UNEXPECTED_MESSAGE,detail:n})};export function extractApiError(e){if(isApiError(e))return e;if("string"==typeof e)return build({message:userSafe(e)??UNEXPECTED_MESSAGE,detail:e||null});if(!isDict(e))return build({message:UNEXPECTED_MESSAGE,detail:null==e?null:String(e)});if(!0===e.isContractError)return build({code:"contract_error",message:userSafe(e.message)??UNEXPECTED_MESSAGE,detail:nonEmptyString(e.message)});const t=isDict(e.response)?e.response:null,r="number"==typeof t?.status?t.status:"number"==typeof e.status?e.status:0,n=t?t.data:e.body;if(0===r&&null==n)return fromNoResponse(e);const s=isDict(n)?n:null,{fields:o,form:i}=readErrors(s?.errors),a=nonEmptyString(s?.code),E=nonEmptyString(s?.traceId),l=nonEmptyString(s?.message)??nonEmptyString(s?.detail)??(s?readLegacyError(s):null)??nonEmptyString(s?.title)??nonEmptyString(n)??nonEmptyString(e.message);let c;return c=r>=500?SERVER_FAILURE_MESSAGE:userSafe(Object.values(o)[0])??userSafe(i)??userSafe(s?.message)??userSafe(s?.detail)??(s?userSafe(readLegacyError(s)):null)??userSafe(s?.title)??userSafe(n)??(r?requestFailedMessage(r):UNEXPECTED_MESSAGE),build({code:a,message:c,fieldErrors:o,status:r,traceId:E,detail:l})}export const isNoResponse=e=>extractApiError(e).offline;export function apiErrorMessage(e,t){const r=extractApiError(e);if(r.offline||null!==t&&!t)return r.message;return r.status>=500||"request_canceled"===r.code||r.message===UNEXPECTED_MESSAGE||r.message===requestFailedMessage(r.status)?t??null:r.message}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";export{apiErrorMessage,CONTRACT_ERROR_CODE,extractApiError,isApiError,isNoResponse,NETWORK_CODE,OFFLINE_MESSAGE,REQUEST_CANCELED_CODE,SERVER_FAILURE_MESSAGE,TIMEOUT_CODE,TIMEOUT_MESSAGE,toFieldPath,UNEXPECTED_MESSAGE}from"./extractApiError.js";
|
|
@@ -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
|
+
"use strict";import{configuredLocale,getFormatterConfig,isFormatterConfigured}from"./formatConfig.js";import{numberFormat}from"./intlCache.js";const hasIntlNumber=()=>"undefined"!=typeof Intl&&"function"==typeof Intl.NumberFormat,indianGroupingFallback=(r,t)=>{const e=r<0?"-":"",n=Math.abs(r).toFixed(t),[i,o]=n.split("."),m=i.length>3?i.slice(-3):i,u=i.length>3?i.slice(0,-3):"";return e+(u?u.replace(/\B(?=(\d{2})+(?!\d))/g,",")+","+m:m)+(o?`.${o}`:"")},toAmount=r=>{if(null==r||"string"==typeof r&&""===r.trim())return null;const t="number"==typeof r?r:Number(r);return Number.isFinite(t)?t:null},currencyDigits=(r,t)=>numberFormat(r,{style:"currency",currency:t}).resolvedOptions().maximumFractionDigits??2;export const formatCurrency=(r,t={})=>{const{currency:e="INR",locale:n=configuredLocale()??"en-IN",minimumFractionDigits:i,maximumFractionDigits:o,stripSymbol:m=!1,empty:u=(isFormatterConfigured("locale")||isFormatterConfigured("empty")?getFormatterConfig().empty:""),...c}=t,a=toAmount(r);if(null===a)return u;if(hasIntlNumber())try{const r=o??currencyDigits(n,e),t=i??(Number.isInteger(a)?0:r),u=numberFormat(n,{...c,style:"currency",currency:e,minimumFractionDigits:t,maximumFractionDigits:Math.max(t,r)}).format(a);return m?u.replace(/[^\d,.\s\-+]/g,"").trim():u}catch{}const s=indianGroupingFallback(a,i??(Number.isInteger(a)?0:2));return m?s:"INR"===e?`₹${s}`:`${e} ${s}`};
|
|
@@ -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
|
+
"use strict";import{formatDate as houseDate,formatDateTime as houseDateTime,formatTime as houseTime}from"./house.js";import{dateTimeFormat,relativeTimeFormat}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 a=PAD(t.getDate()),r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][t.getMonth()],n=["January","February","March","April","May","June","July","August","September","October","November","December"][t.getMonth()],o=t.getFullYear(),i=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][t.getDay()];switch(e){case"short":return`${a}/${PAD(t.getMonth()+1)}/${o}`;case"long":return`${a} ${n} ${o}`;case"full":return`${i}, ${a} ${n} ${o}`;default:return`${a} ${r} ${o}`}},fallbackTime=(t,e)=>{const a=PAD(t.getHours()),r=PAD(t.getMinutes());if("short"===e)return`${a}:${r}`;return`${a}:${r}:${PAD(t.getSeconds())}`},isStyle=t=>"string"==typeof t;export function formatDate(t,e,a="en-IN"){if(!isStyle(e))return houseDate(t,e);const r=e,n=toDate(t);if(!n)return"";if(hasIntl())try{return dateTimeFormat(a,{dateStyle:r}).format(n)}catch{}return fallbackDate(n,r)}export function formatTime(t,e,a="en-IN"){if(!isStyle(e))return houseTime(t,e);const r=e,n=toDate(t);if(!n)return"";if(hasIntl())try{return dateTimeFormat(a,{timeStyle:r}).format(n)}catch{}return fallbackTime(n,r)}export function formatDateTime(t,e,a="short",r="en-IN"){if(!isStyle(e))return houseDateTime(t,e);const n=e,o=toDate(t);if(!o)return"";if(hasIntl())try{return dateTimeFormat(r,{dateStyle:n,timeStyle:a}).format(o)}catch{}return`${fallbackDate(o,n)}, ${fallbackTime(o,a)}`}const SECOND=1e3,MINUTE=6e4,HOUR=36e5,DAY=24*HOUR,WEEK=7*DAY,MONTH=30*DAY,YEAR=365*DAY;export const formatRelativeTime=(t,e=new Date,a="en-IN")=>{const r=toDate(t),n=toDate(e);if(!r||!n)return"";const o=r.getTime()-n.getTime(),i=Math.abs(o);let u,s;i<6e4?(u="second",s=Math.round(o/1e3)):i<HOUR?(u="minute",s=Math.round(o/6e4)):i<DAY?(u="hour",s=Math.round(o/HOUR)):i<WEEK?(u="day",s=Math.round(o/DAY)):i<MONTH?(u="week",s=Math.round(o/WEEK)):i<YEAR?(u="month",s=Math.round(o/MONTH)):(u="year",s=Math.round(o/YEAR));const m=hasIntl()?Intl.RelativeTimeFormat:void 0;if("function"==typeof m)try{return relativeTimeFormat(m,a).format(s,u)}catch{}const l=s<0,c=Math.abs(s),f=1===c?u:`${u}s`;return l?`${c} ${f} ago`:`in ${c} ${f}`};
|
|
@@ -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
|
+
"use strict";import{dateTimeFormat}from"./intlCache.js";import{WINDOWS_TO_IANA}from"./windowsToIanaTable.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},PAD=t=>t<10?`0${t}`:`${t}`;export const isSameDay=(t,e)=>{const r=toDate(t),n=toDate(e);return!(!r||!n)&&(r.getFullYear()===n.getFullYear()&&r.getMonth()===n.getMonth()&&r.getDate()===n.getDate())};export const isDateBefore=(t,e)=>{const r=toDate(t),n=toDate(e);return null!==r&&null!==n&&r.getTime()<n.getTime()};export const isDateAfter=(t,e)=>{const r=toDate(t),n=toDate(e);return null!==r&&null!==n&&r.getTime()>n.getTime()};export const diffMs=(t,e)=>{const r=toDate(t),n=toDate(e);return r&&n?r.getTime()-n.getTime():Number.NaN};export const startOfDay=t=>{const e=toDate(t);if(!e)return null;const r=new Date(e);return r.setHours(0,0,0,0),r};export const addDays=(t,e)=>{if(null==t||""===t||!Number.isFinite(e))return null;const r=toDate(t);if(!r)return null;const n=new Date(r);return n.setDate(n.getDate()+e),n};const WEEKDAY_SHORT=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],WEEKDAY_LONG=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],MONTH_LONG=["January","February","March","April","May","June","July","August","September","October","November","December"],TOKENS=["YYYY","YY","MMMM","MMM","MM","M","DD","D","dddd","ddd","HH","H","hh","h","mm","m","ss","s","A","a"],tokenizePattern=t=>{const e=[];let r=0;t:for(;r<t.length;){for(const n of TOKENS)if(t.startsWith(n,r)){e.push(n),r+=n.length;continue t}e.push(t[r]),r+=1}return e};export const formatDatePattern=(t,e,r)=>{const n=toDate(t);if(!n)return"";const o=r?.utc??!1,a=o?n.getUTCFullYear():n.getFullYear(),u=o?n.getUTCMonth():n.getMonth(),s=o?n.getUTCDate():n.getDate(),i=o?n.getUTCDay():n.getDay(),c=o?n.getUTCHours():n.getHours(),D=o?n.getUTCMinutes():n.getMinutes(),g=o?n.getUTCSeconds():n.getSeconds(),{hour12:m,period:l}=to12Hour(c);return tokenizePattern(e).map(t=>{switch(t){case"YYYY":return String(a);case"YY":return String(a).slice(-2);case"MMMM":return MONTH_LONG[u];case"MMM":return MONTH_SHORT[u];case"MM":return PAD(u+1);case"M":return String(u+1);case"DD":return PAD(s);case"D":return String(s);case"dddd":return WEEKDAY_LONG[i];case"ddd":return WEEKDAY_SHORT[i];case"HH":return PAD(c);case"H":return String(c);case"hh":return PAD(m);case"h":return String(m);case"mm":return PAD(D);case"m":return String(D);case"ss":return PAD(g);case"s":return String(g);case"A":return l;case"a":return l.toLowerCase();default:return t}}).join("")};const MONTH_SHORT=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];export const formatDateDDMMMYYYY=(t,e)=>{const r=toDate(t);return r?e?.utc?`${PAD(r.getUTCDate())} ${MONTH_SHORT[r.getUTCMonth()]}, ${r.getUTCFullYear()}`:`${PAD(r.getDate())} ${MONTH_SHORT[r.getMonth()]}, ${r.getFullYear()}`:""};export const formatDateISO=t=>{const e=toDate(t);return e?`${e.getFullYear()}-${PAD(e.getMonth()+1)}-${PAD(e.getDate())}`:""};const to12Hour=t=>({hour12:t%12||12,period:t>=12?"PM":"AM"});export const formatTime12h=t=>{const e=toDate(t);if(!e)return"";const{hour12:r,period:n}=to12Hour(e.getHours());return`${PAD(r)}:${PAD(e.getMinutes())} ${n}`};const hasIntl=()=>"undefined"!=typeof Intl&&"function"==typeof Intl.DateTimeFormat;export const formatTimeInZone=(t,e)=>{const r=toDate(t);if(!r)return"";if(!hasIntl())return formatTime12h(r);const n=dateTimeFormat("en-US",{timeZone:e,hour:"numeric",minute:"2-digit",hour12:!0}).formatToParts(r),get=t=>n.find(e=>e.type===t)?.value??"",o=Number.parseInt(get("hour"),10),a=get("minute"),u=get("dayPeriod").toLowerCase();return`${PAD(o)}:${a} ${u}`};export const formatTimeInWindowsZone=(t,e)=>{const r=WINDOWS_TO_IANA[e];if(!r)throw new Error(`Mapping for Windows time zone '${e}' not found.`);return formatTimeInZone(t,r)};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const DEFAULTS={zone:"IST",locale:"en-IN",empty:"-"};let current={...DEFAULTS},configured=new Set;export const configureFormatters=e=>{if(void 0===e)return current={...DEFAULTS},void(configured=new Set);for(const o of Object.keys(e)){const r=e[o];void 0!==r&&(current={...current,[o]:r},configured.add(o))}};export const getFormatterConfig=()=>({...current});export const isFormatterConfigured=e=>configured.has(e);export const configuredLocale=()=>configured.has("locale")?current.locale:null;export const groupingForLocale=e=>/-IN(?:-|$)/i.test(e)?"indian":"international";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";import{configuredLocale,getFormatterConfig,groupingForLocale}from"./formatConfig.js";import{dateTimeFormat,numberFormat,relativeTimeFormat}from"./intlCache.js";const MONTHS=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],IST_OFFSET_MINUTES=330,IST_NAMES=["IST","Asia/Kolkata","Asia/Calcutta"],DATE_ONLY=/^\d{4}-\d{2}-\d{2}$/,pad2=t=>t<10?`0${t}`:`${t}`,emptyOf=t=>t??getFormatterConfig().empty,toInstant=t=>{if(null==t||""===t)return null;const e=t instanceof Date?t:new Date("string"==typeof t?t.trim():t);return Number.isNaN(e.getTime())?null:e},isDateOnly=t=>"string"==typeof t&&DATE_ONLY.test(t.trim()),gmtLabel=t=>{if(0===t)return"GMT";const e=t>0?"+":"-",n=Math.abs(t),o=n%60;return`GMT${e}${Math.floor(n/60)}${0===o?"":`:${pad2(o)}`}`},shifted=(t,e,n)=>{const o=new Date(t.getTime()+6e4*e);return{year:o.getUTCFullYear(),month:o.getUTCMonth(),day:o.getUTCDate(),hour:o.getUTCHours(),minute:o.getUTCMinutes(),label:n}},inIanaZone=(t,e)=>{const n=dateTimeFormat("en-US",{timeZone:e,year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",hour12:!1}).formatToParts(t),read=t=>Number.parseInt(n.find(e=>e.type===t)?.value??"",10),o=read("year"),r=read("month")-1,i=read("day"),a=read("hour")%24,l=read("minute"),m=Date.UTC(o,r,i,a,l),u=Math.round((m-6e4*Math.floor(t.getTime()/6e4))/6e4);return{year:o,month:r,day:i,hour:a,minute:l,label:gmtLabel(u)}},wallClock=(t,e)=>IST_NAMES.includes(e)?shifted(t,330,"IST"):"UTC"===e?shifted(t,0,"UTC"):"viewer"===e?{year:t.getFullYear(),month:t.getMonth(),day:t.getDate(),hour:t.getHours(),minute:t.getMinutes(),label:gmtLabel(-t.getTimezoneOffset())}:inIanaZone(t,e),hourCycleOf=t=>t.hourCycle??12,dayMonthYear=t=>`${pad2(t.day)}-${MONTHS[t.month]}-${t.year}`,clockTime=(t,e)=>24===e?`${pad2(t.hour)}:${pad2(t.minute)}`:`${t.hour%12||12}:${pad2(t.minute)} ${t.hour<12?"AM":"PM"}`,labelled=(t,e)=>e??!IST_NAMES.includes(t),withLabel=(t,e,n,o)=>labelled(n,o)?`${t} ${e.label}`:t,intlZone=t=>{if("viewer"!==t)return IST_NAMES.includes(t)?"Asia/Kolkata":t},localeDayMonthYear=(t,e,n)=>{const o=dateTimeFormat(e,{day:"2-digit",month:"short",year:"numeric",timeZone:n}).formatToParts(t),part=t=>o.find(e=>e.type===t)?.value??"";return`${part("day")}-${part("month").replace(".","")}-${part("year")}`},localeClock=(t,e,n,o)=>dateTimeFormat(e,{hour:"2-digit",minute:"2-digit",timeZone:intlZone(n),timeZoneName:labelled(n,o.zoneLabel)?"short":void 0,hourCycle:void 0===o.hourCycle?void 0:24===o.hourCycle?"h23":"h12"}).format(t);export const formatDate=(t,e={})=>{const n=toInstant(t);if(!n)return emptyOf(e.empty);const o=isDateOnly(t)?"UTC":e.zone??getFormatterConfig().zone,r=configuredLocale();return r?localeDayMonthYear(n,r,intlZone(o)):dayMonthYear(wallClock(n,o))};export const formatTime=(t,e={})=>{const n=toInstant(t);if(!n)return emptyOf(e.empty);const o=e.zone??getFormatterConfig().zone,r=configuredLocale();if(r)return localeClock(n,r,o,e);const i=wallClock(n,o);return withLabel(clockTime(i,hourCycleOf(e)),i,o,e.zoneLabel)};export const formatDateTime=(t,e={})=>{const n=toInstant(t);if(!n)return emptyOf(e.empty);const o=e.zone??getFormatterConfig().zone,r=configuredLocale();if(r)return`${localeDayMonthYear(n,r,intlZone(o))}, ${localeClock(n,r,o,e)}`;const i=wallClock(n,o);return withLabel(`${dayMonthYear(i)}, ${clockTime(i,hourCycleOf(e))}`,i,o,e.zoneLabel)};const SECOND=1e3,MINUTE=6e4,HOUR=36e5,DAY=24*HOUR,WEEK=7*DAY,MONTH=30*DAY,YEAR=365*DAY,INTL_UNITS=[["year",YEAR],["month",MONTH],["day",DAY],["hour",HOUR],["minute",6e4]];export const formatRelative=(t,e={})=>{const n=toInstant(t),o=toInstant(e.now??Date.now());if(!n||!o)return emptyOf(e.empty);const r=n.getTime()-o.getTime(),i=Math.abs(r),a=Intl.RelativeTimeFormat,l=configuredLocale();if((null!==l||!0===e.intl)&&"function"==typeof a){const t=relativeTimeFormat(a,l??getFormatterConfig().locale),[e,n]=INTL_UNITS.find(([,t])=>i>=t)??["second",1e3];return t.format(Math.round(r/n),e)}if(i<6e4)return"just now";const[m,u]=i<HOUR?["minute",6e4]:i<DAY?["hour",HOUR]:i<WEEK?["day",DAY]:i<MONTH?["week",WEEK]:i<YEAR?["month",MONTH]:["year",YEAR],c=Math.floor(i/u),s=`${c} ${m}${1===c?"":"s"}`;return r<0?`${s} ago`:`in ${s}`};const toNumber=t=>{if(null==t)return null;if("string"==typeof t&&""===t.trim())return null;const e="number"==typeof t?t:Number(t);return Number.isFinite(e)?e:null},clampDigits=t=>Math.min(20,Math.max(0,Math.trunc(t))),shiftDecimal=(t,e)=>/e/i.test(String(t))?t*10**e:Number(`${t}e${e}`),groupInteger=(t,e)=>{if("none"===e||t.length<=3)return t;if("international"===e)return t.replace(/\B(?=(\d{3})+(?!\d))/g,",");return`${t.slice(0,-3).replace(/\B(?=(\d{2})+(?!\d))/g,",")},${t.slice(-3)}`},hasIntlNumber=()=>"undefined"!=typeof Intl&&"function"==typeof Intl.NumberFormat,plainDigits=(t,e)=>{if(hasIntlNumber())return numberFormat("en-US",{useGrouping:!1,minimumFractionDigits:0,maximumFractionDigits:e}).format(t);const n=Math.min(e,15);return shiftDecimal(Math.round(shiftDecimal(t,n)),-n).toFixed(n)},decimalText=(t,e,n,o)=>{const r=Math.max(clampDigits(n),clampDigits(e)),i=clampDigits(e),a=plainDigits(Math.abs(t),r),[l="0",m=""]=a.split(".");let u=m.padEnd(i,"0");for(;u.length>i&&u.endsWith("0");)u=u.slice(0,-1);const c=groupInteger(l,o)+(u?`.${u}`:"");return t<0&&/[1-9]/.test(a)?`-${c}`:c},HOUSE_NUMBER_KEYS=new Set(["grouping","minimumFractionDigits","maximumFractionDigits","locale","empty","scale"]),intlNumberOptions=t=>{if(!Object.entries(t).some(([t,e])=>void 0!==e&&!HOUSE_NUMBER_KEYS.has(t)))return null;const{grouping:e,locale:n,empty:o,scale:r,...i}=t;return"none"===e&&void 0===i.useGrouping?{...i,useGrouping:!1}:i},localeOf=t=>t.locale??getFormatterConfig().locale,intlTextLocale=t=>{const e=configuredLocale();return null===e||"indian"===t.grouping||"international"===t.grouping?null:t.locale??e},fractionDigits=(t,e)=>{const n=clampDigits(t);return{minimumFractionDigits:n,maximumFractionDigits:Math.max(n,clampDigits(e))}},groupingOption=t=>"none"===t?{useGrouping:!1}:{};export const formatNumber=(t,e={})=>{const n=toNumber(t);if(null===n)return emptyOf(e.empty);const o=intlNumberOptions(e);if(o)return numberFormat(localeOf(e),o).format(n);const r=intlTextLocale(e);return r?numberFormat(r,{...fractionDigits(e.minimumFractionDigits??0,e.maximumFractionDigits??3),...groupingOption(e.grouping)}).format(n):decimalText(n,e.minimumFractionDigits??0,e.maximumFractionDigits??3,e.grouping??groupingForLocale(localeOf(e)))};export const formatPercent=(t,e={})=>{const n=toNumber(t);if(null===n)return emptyOf(e.empty);const o=intlNumberOptions(e);if(o){const t="percent"===e.scale?shiftDecimal(n,-2):n;return numberFormat(localeOf(e),{style:"percent",...o}).format(t)}const r=intlTextLocale(e);if(r){const t="percent"===e.scale?shiftDecimal(n,-2):n;return numberFormat(r,{style:"percent",...fractionDigits(e.minimumFractionDigits??0,e.maximumFractionDigits??e.minimumFractionDigits??0),...groupingOption(e.grouping)}).format(t)}const i="percent"===e.scale?n:shiftDecimal(n,2);return`${decimalText(i,e.minimumFractionDigits??0,e.maximumFractionDigits??e.minimumFractionDigits??0,e.grouping??groupingForLocale(localeOf(e)))}%`};const SYMBOLS={INR:"₹",USD:"$",EUR:"€",GBP:"£"},MINOR_DIGITS={JPY:0,KRW:0,VND:0,BHD:3,JOD:3,KWD:3,OMR:3,TND:3};export const formatMinor=(t,e={})=>{const n=toNumber(t);if(null===n)return emptyOf(e.empty);const o=(e.currency??"INR").toUpperCase(),r=MINOR_DIGITS[o]??2,i=Math.round(Math.abs(n)),a=String(i).padStart(r+1,"0"),l=a.slice(0,a.length-r);let m=a.slice(a.length-r);e.dropZeroDecimals&&/^0*$/.test(m)&&(m="");const u=intlTextLocale({grouping:e.grouping});if(u)try{const t=Number(`${n<0&&0!==i?"-":""}${l}.${a.slice(a.length-r)||"0"}`);return numberFormat(u,{...!1===e.symbol?{}:{style:"currency",currency:o},...fractionDigits(m?r:0,r),...groupingOption(e.grouping)}).format(t)}catch{}const c=e.grouping??("INR"===o?"indian":"international"),s=groupInteger(l,c)+(m?`.${m}`:""),g=n<0&&0!==i?"-":"";if(!1===e.symbol)return`${g}${s}`;const f=SYMBOLS[o];return f?`${g}${f}${s}`:`${g}${o} ${s}`};
|
|
@@ -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
|
+
"use strict";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{configureFormatters,getFormatterConfig}from"./formatConfig.js";export{formatMinor,formatRelative}from"./house.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
|
+
"use strict";export const getInitials=(t,e=2)=>{if(!t)return"";const r=t.trim();if(!r)return"";const s=r.split(/\s+/);if(1===s.length){return(s[0]??"").slice(0,e).toUpperCase()}return s.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
|
+
"use strict";const LIMIT=100,cached=(e,t,r)=>{let a=e.get(t);return void 0===a&&(a=r(),e.size>=100&&e.clear(),e.set(t,a)),a},numberFormats=new Map,dateTimeFormats=new Map,relativeTimeFormats=new Map;export const numberFormat=(e,t={})=>cached(numberFormats,`${e}|${JSON.stringify(t)}`,()=>new Intl.NumberFormat(e,t));export const dateTimeFormat=(e,t)=>cached(dateTimeFormats,`${e}|${JSON.stringify(t)}`,()=>new Intl.DateTimeFormat(e,t));export const relativeTimeFormat=(e,t)=>cached(relativeTimeFormats,t,()=>new e(t,{numeric:"auto"}));
|