@webority-technologies/mobile-core 0.0.3 → 0.0.5

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.
@@ -0,0 +1,79 @@
1
+ import type { DateInput } from './date';
2
+ /**
3
+ * Whether two values fall on the same calendar day in the device's local
4
+ * timezone. Invalid input on either side returns false rather than throwing.
5
+ */
6
+ export declare const isSameDay: (a: DateInput, b: DateInput) => boolean;
7
+ /** `a` is strictly before `b`. Invalid input on either side returns false. */
8
+ export declare const isDateBefore: (a: DateInput, b: DateInput) => boolean;
9
+ /** `a` is strictly after `b`. Invalid input on either side returns false. */
10
+ export declare const isDateAfter: (a: DateInput, b: DateInput) => boolean;
11
+ /**
12
+ * `a - b` in milliseconds, matching dayjs's `a.diff(b)` sign convention
13
+ * (positive when `a` is later than `b`). Returns `NaN` if either side fails
14
+ * to parse, the same way subtracting two invalid dayjs objects would.
15
+ */
16
+ export declare const diffMs: (a: DateInput, b: DateInput) => number;
17
+ /**
18
+ * Midnight of the given date, in the device's local timezone. Returns null
19
+ * for unparseable input.
20
+ */
21
+ export declare const startOfDay: (value: DateInput) => Date | null;
22
+ /**
23
+ * Adds (or, with a negative count, subtracts) whole calendar days in the
24
+ * device's local timezone. Returns null for unparseable input.
25
+ */
26
+ export declare const addDays: (value: DateInput, count: number) => Date | null;
27
+ /**
28
+ * Small dayjs/moment-style token formatter — YYYY/YY, MMMM/MMM/MM/M,
29
+ * DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
30
+ * Everything else in the pattern (spaces, commas, colons) passes through
31
+ * literally. Hand-rolled rather than a dependency because this fleet's date
32
+ * formatting needs are a small, closed token set, not general i18n — for
33
+ * genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
34
+ * `./date`) are the ones to reach for; this is for matching an exact
35
+ * existing pattern (a legacy display string, an API's expected shape).
36
+ *
37
+ * `utc: true` reads every field from the UTC calendar/clock instead of the
38
+ * device's local one — see `formatDateDDMMMYYYY`'s note on why this isn't
39
+ * cosmetic.
40
+ */
41
+ export declare const formatDatePattern: (value: DateInput, pattern: string, options?: {
42
+ utc?: boolean;
43
+ }) => string;
44
+ /**
45
+ * `DD MMM, YYYY` — zero-padded day, short month, comma, year (e.g.
46
+ * `05 Sep, 2025`). A specific legacy pattern some apps already display,
47
+ * not the fleet's own product convention: `formatDate` (the Intl `style`-based
48
+ * formatter in `./date`) is the one to reach for in new code. This exists so
49
+ * an app already showing this exact pattern can move off a date library
50
+ * without a visible change.
51
+ *
52
+ * `utc: true` reads the calendar day from the UTC fields instead of the
53
+ * device's local ones — matching `dayjs.utc(x).format(...)`, not
54
+ * `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
55
+ * day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
56
+ * option; pass it only to match a call site that was genuinely UTC-explicit.
57
+ */
58
+ export declare const formatDateDDMMMYYYY: (value: DateInput, options?: {
59
+ utc?: boolean;
60
+ }) => string;
61
+ /** `YYYY-MM-DD`, in the device's local timezone. */
62
+ export declare const formatDateISO: (value: DateInput) => string;
63
+ /**
64
+ * `hh:mm A` in the device's local timezone — zero-padded 12-hour clock,
65
+ * uppercase AM/PM (e.g. `09:30 PM`).
66
+ */
67
+ export declare const formatTime12h: (value: DateInput) => string;
68
+ /**
69
+ * `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
70
+ * seen in `ianaTimeZone` (e.g. `Asia/Kolkata`) — not the device's own
71
+ * timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
72
+ * `formatToParts` rather than its assembled string, because the assembled
73
+ * string's spacing before AM/PM varies by JS engine (some insert a narrow
74
+ * no-break space, U+202F, instead of a plain space) and isn't reliably
75
+ * zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
76
+ * recognises — the same failure mode as handing dayjs.tz() a bad zone name.
77
+ */
78
+ export declare const formatTimeInZone: (value: DateInput, ianaTimeZone: string) => string;
79
+ //# sourceMappingURL=dateMath.d.ts.map
@@ -2,6 +2,7 @@ export type { FormatCurrencyOptions } from './currency';
2
2
  export { formatCurrency } from './currency';
3
3
  export type { DateInput, DateStyle, TimeStyle } from './date';
4
4
  export { formatDate, formatDateTime, formatRelativeTime, formatTime } from './date';
5
+ export { addDays, diffMs, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatTime12h, formatTimeInZone, isDateAfter, isDateBefore, isSameDay, startOfDay } from './dateMath';
5
6
  export { getInitials } from './initials';
6
7
  export { formatCompactNumber, formatNumber, formatPercent } from './number';
7
8
  export type { FormatPhoneOptions, PhoneCountry, PhoneNumber } from './phone';
@@ -1,15 +1,21 @@
1
1
  /**
2
- * Real cross-country validation, re-exported rather than reimplemented.
3
- * formatPhone/normalizePhone/detectPhoneCountry below are a fast, dependency-
4
- * light DISPLAY formatter for a fixed set of countries; they are not a
5
- * validator. Real phone number plans have country-specific area-code and
6
- * mobile-prefix rules that only a maintained metadata table gets right -
7
- * hand-rolling that risks silently-wrong validation for a country nobody
8
- * tests against. Both live here so consumers get one phone module, not two.
2
+ * The bare 'libphonenumber-js' entry point actually resolves to the library's
3
+ * OWN slimmed-down min/ metadata internally, not its full data - './max' is
4
+ * the variant with complete per-country metadata. Since the reason this
5
+ * module exists is validation and formatting accuracy, the more accurate
6
+ * variant wins throughout this file, not just for validation.
9
7
  */
10
- export type { PhoneNumber } from 'libphonenumber-js';
11
- export { isValidPhoneNumber, parsePhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js';
12
- export type PhoneCountry = 'IN' | 'US' | 'GB' | 'AE' | 'AU' | 'SG' | 'CA';
8
+ import { type CountryCode } from 'libphonenumber-js/max';
9
+ export type { PhoneNumber } from 'libphonenumber-js/max';
10
+ export { isValidPhoneNumber, parsePhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js/max';
11
+ /**
12
+ * Re-exported under our own name rather than importing CountryCode directly
13
+ * everywhere, so a future need to diverge (or re-narrow) has one place to do
14
+ * it. Every ISO 3166-1 alpha-2 code libphonenumber-js recognises - formatPhone
15
+ * and detectPhoneCountry below are genuinely correct for all of them, not a
16
+ * curated subset.
17
+ */
18
+ export type PhoneCountry = CountryCode;
13
19
  export interface FormatPhoneOptions {
14
20
  defaultCountryCode?: string;
15
21
  country?: PhoneCountry;
@@ -22,17 +28,22 @@ export declare const normalizePhone: (input: string) => string;
22
28
  /**
23
29
  * Detect the country of a phone number: from its own `+` country code when
24
30
  * present, otherwise from `defaultCountryCode`. Returns null when neither
25
- * carries a recognised calling code.
31
+ * parses to a recognised country.
26
32
  */
27
33
  export declare const detectPhoneCountry: (input: string, defaultCountryCode?: string) => PhoneCountry | null;
28
34
  /**
29
- * Format a phone number for human display.
35
+ * Format a phone number for human display, via libphonenumber-js's own
36
+ * per-country formatting rather than a hand-rolled grouping table - correct
37
+ * for every country it recognises, not a curated subset.
30
38
  *
31
- * - Indian mobile (10 digits) `XXXXX XXXXX`
32
- * - With `+91` country code `+91 XXXXX XXXXX`
33
- * - A number that already carries a recognised country code is grouped for
34
- * that country regardless of `defaultCountryCode`.
35
- * - Other inputs are returned as `+CC NNNN NNNN…` best-effort grouping.
39
+ * - A number that already carries a `+` country code formats for that country.
40
+ * - A bare national number formats for `options.country` when given, else for
41
+ * the country implied by `defaultCountryCode` (default `+91`).
42
+ * - `includeCountryCode` controls international vs national format; defaults
43
+ * to international whenever the country was detected rather than passed in
44
+ * explicitly as `options.country`, and to national when it was.
45
+ * - Input libphonenumber-js can't parse into a valid number for the resolved
46
+ * country falls back to a best-effort `+CC NNNN NNNN…` digit grouping.
36
47
  */
37
48
  export declare function formatPhone(input: string, defaultCountryCode?: string): string;
38
49
  export declare function formatPhone(input: string, options?: FormatPhoneOptions): string;
@@ -29,7 +29,7 @@ export { getConfig, getConfigValue, resetConfig, setConfig } from './config';
29
29
  export type { DeepLinkConfig, DeepLinkRoute, ParsedLink } from './deepLink';
30
30
  export { DeepLink, parseDeepLink, useDeepLink } from './deepLink';
31
31
  export type { DateInput, DateStyle, FormatCurrencyOptions, FormatPhoneOptions, PhoneCountry, PhoneNumber, TimeStyle } from './formatters';
32
- export { detectPhoneCountry, formatCompactNumber, formatCurrency, formatDate, formatDateTime, formatNumber, formatPercent, formatPhone, formatRelativeTime, formatTime, getInitials, isValidPhoneNumber, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString } from './formatters';
32
+ export { addDays, detectPhoneCountry, diffMs, formatCompactNumber, formatCurrency, formatDate, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatDateTime, formatNumber, formatPercent, formatPhone, formatRelativeTime, formatTime, formatTime12h, formatTimeInZone, getInitials, isDateAfter, isDateBefore, isSameDay, isValidPhoneNumber, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString, startOfDay } from './formatters';
33
33
  export type { InitConfig } from './initSDK';
34
34
  export { initWebority } from './initSDK';
35
35
  export type { AuthActions } from './initUserAuth';
@@ -0,0 +1,79 @@
1
+ import type { DateInput } from './date.js';
2
+ /**
3
+ * Whether two values fall on the same calendar day in the device's local
4
+ * timezone. Invalid input on either side returns false rather than throwing.
5
+ */
6
+ export declare const isSameDay: (a: DateInput, b: DateInput) => boolean;
7
+ /** `a` is strictly before `b`. Invalid input on either side returns false. */
8
+ export declare const isDateBefore: (a: DateInput, b: DateInput) => boolean;
9
+ /** `a` is strictly after `b`. Invalid input on either side returns false. */
10
+ export declare const isDateAfter: (a: DateInput, b: DateInput) => boolean;
11
+ /**
12
+ * `a - b` in milliseconds, matching dayjs's `a.diff(b)` sign convention
13
+ * (positive when `a` is later than `b`). Returns `NaN` if either side fails
14
+ * to parse, the same way subtracting two invalid dayjs objects would.
15
+ */
16
+ export declare const diffMs: (a: DateInput, b: DateInput) => number;
17
+ /**
18
+ * Midnight of the given date, in the device's local timezone. Returns null
19
+ * for unparseable input.
20
+ */
21
+ export declare const startOfDay: (value: DateInput) => Date | null;
22
+ /**
23
+ * Adds (or, with a negative count, subtracts) whole calendar days in the
24
+ * device's local timezone. Returns null for unparseable input.
25
+ */
26
+ export declare const addDays: (value: DateInput, count: number) => Date | null;
27
+ /**
28
+ * Small dayjs/moment-style token formatter — YYYY/YY, MMMM/MMM/MM/M,
29
+ * DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
30
+ * Everything else in the pattern (spaces, commas, colons) passes through
31
+ * literally. Hand-rolled rather than a dependency because this fleet's date
32
+ * formatting needs are a small, closed token set, not general i18n — for
33
+ * genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
34
+ * `./date`) are the ones to reach for; this is for matching an exact
35
+ * existing pattern (a legacy display string, an API's expected shape).
36
+ *
37
+ * `utc: true` reads every field from the UTC calendar/clock instead of the
38
+ * device's local one — see `formatDateDDMMMYYYY`'s note on why this isn't
39
+ * cosmetic.
40
+ */
41
+ export declare const formatDatePattern: (value: DateInput, pattern: string, options?: {
42
+ utc?: boolean;
43
+ }) => string;
44
+ /**
45
+ * `DD MMM, YYYY` — zero-padded day, short month, comma, year (e.g.
46
+ * `05 Sep, 2025`). A specific legacy pattern some apps already display,
47
+ * not the fleet's own product convention: `formatDate` (the Intl `style`-based
48
+ * formatter in `./date`) is the one to reach for in new code. This exists so
49
+ * an app already showing this exact pattern can move off a date library
50
+ * without a visible change.
51
+ *
52
+ * `utc: true` reads the calendar day from the UTC fields instead of the
53
+ * device's local ones — matching `dayjs.utc(x).format(...)`, not
54
+ * `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
55
+ * day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
56
+ * option; pass it only to match a call site that was genuinely UTC-explicit.
57
+ */
58
+ export declare const formatDateDDMMMYYYY: (value: DateInput, options?: {
59
+ utc?: boolean;
60
+ }) => string;
61
+ /** `YYYY-MM-DD`, in the device's local timezone. */
62
+ export declare const formatDateISO: (value: DateInput) => string;
63
+ /**
64
+ * `hh:mm A` in the device's local timezone — zero-padded 12-hour clock,
65
+ * uppercase AM/PM (e.g. `09:30 PM`).
66
+ */
67
+ export declare const formatTime12h: (value: DateInput) => string;
68
+ /**
69
+ * `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
70
+ * seen in `ianaTimeZone` (e.g. `Asia/Kolkata`) — not the device's own
71
+ * timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
72
+ * `formatToParts` rather than its assembled string, because the assembled
73
+ * string's spacing before AM/PM varies by JS engine (some insert a narrow
74
+ * no-break space, U+202F, instead of a plain space) and isn't reliably
75
+ * zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
76
+ * recognises — the same failure mode as handing dayjs.tz() a bad zone name.
77
+ */
78
+ export declare const formatTimeInZone: (value: DateInput, ianaTimeZone: string) => string;
79
+ //# sourceMappingURL=dateMath.d.ts.map
@@ -2,6 +2,7 @@ export type { FormatCurrencyOptions } from './currency.js';
2
2
  export { formatCurrency } from './currency.js';
3
3
  export type { DateInput, DateStyle, TimeStyle } from './date.js';
4
4
  export { formatDate, formatDateTime, formatRelativeTime, formatTime } from './date.js';
5
+ export { addDays, diffMs, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatTime12h, formatTimeInZone, isDateAfter, isDateBefore, isSameDay, startOfDay } from './dateMath.js';
5
6
  export { getInitials } from './initials.js';
6
7
  export { formatCompactNumber, formatNumber, formatPercent } from './number.js';
7
8
  export type { FormatPhoneOptions, PhoneCountry, PhoneNumber } from './phone.js';
@@ -1,15 +1,21 @@
1
1
  /**
2
- * Real cross-country validation, re-exported rather than reimplemented.
3
- * formatPhone/normalizePhone/detectPhoneCountry below are a fast, dependency-
4
- * light DISPLAY formatter for a fixed set of countries; they are not a
5
- * validator. Real phone number plans have country-specific area-code and
6
- * mobile-prefix rules that only a maintained metadata table gets right -
7
- * hand-rolling that risks silently-wrong validation for a country nobody
8
- * tests against. Both live here so consumers get one phone module, not two.
2
+ * The bare 'libphonenumber-js' entry point actually resolves to the library's
3
+ * OWN slimmed-down min/ metadata internally, not its full data - './max' is
4
+ * the variant with complete per-country metadata. Since the reason this
5
+ * module exists is validation and formatting accuracy, the more accurate
6
+ * variant wins throughout this file, not just for validation.
9
7
  */
10
- export type { PhoneNumber } from 'libphonenumber-js';
11
- export { isValidPhoneNumber, parsePhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js';
12
- export type PhoneCountry = 'IN' | 'US' | 'GB' | 'AE' | 'AU' | 'SG' | 'CA';
8
+ import { type CountryCode } from 'libphonenumber-js/max';
9
+ export type { PhoneNumber } from 'libphonenumber-js/max';
10
+ export { isValidPhoneNumber, parsePhoneNumber, parsePhoneNumberFromString } from 'libphonenumber-js/max';
11
+ /**
12
+ * Re-exported under our own name rather than importing CountryCode directly
13
+ * everywhere, so a future need to diverge (or re-narrow) has one place to do
14
+ * it. Every ISO 3166-1 alpha-2 code libphonenumber-js recognises - formatPhone
15
+ * and detectPhoneCountry below are genuinely correct for all of them, not a
16
+ * curated subset.
17
+ */
18
+ export type PhoneCountry = CountryCode;
13
19
  export interface FormatPhoneOptions {
14
20
  defaultCountryCode?: string;
15
21
  country?: PhoneCountry;
@@ -22,17 +28,22 @@ export declare const normalizePhone: (input: string) => string;
22
28
  /**
23
29
  * Detect the country of a phone number: from its own `+` country code when
24
30
  * present, otherwise from `defaultCountryCode`. Returns null when neither
25
- * carries a recognised calling code.
31
+ * parses to a recognised country.
26
32
  */
27
33
  export declare const detectPhoneCountry: (input: string, defaultCountryCode?: string) => PhoneCountry | null;
28
34
  /**
29
- * Format a phone number for human display.
35
+ * Format a phone number for human display, via libphonenumber-js's own
36
+ * per-country formatting rather than a hand-rolled grouping table - correct
37
+ * for every country it recognises, not a curated subset.
30
38
  *
31
- * - Indian mobile (10 digits) `XXXXX XXXXX`
32
- * - With `+91` country code `+91 XXXXX XXXXX`
33
- * - A number that already carries a recognised country code is grouped for
34
- * that country regardless of `defaultCountryCode`.
35
- * - Other inputs are returned as `+CC NNNN NNNN…` best-effort grouping.
39
+ * - A number that already carries a `+` country code formats for that country.
40
+ * - A bare national number formats for `options.country` when given, else for
41
+ * the country implied by `defaultCountryCode` (default `+91`).
42
+ * - `includeCountryCode` controls international vs national format; defaults
43
+ * to international whenever the country was detected rather than passed in
44
+ * explicitly as `options.country`, and to national when it was.
45
+ * - Input libphonenumber-js can't parse into a valid number for the resolved
46
+ * country falls back to a best-effort `+CC NNNN NNNN…` digit grouping.
36
47
  */
37
48
  export declare function formatPhone(input: string, defaultCountryCode?: string): string;
38
49
  export declare function formatPhone(input: string, options?: FormatPhoneOptions): string;
@@ -29,7 +29,7 @@ export { getConfig, getConfigValue, resetConfig, setConfig } from './config/inde
29
29
  export type { DeepLinkConfig, DeepLinkRoute, ParsedLink } from './deepLink/index.js';
30
30
  export { DeepLink, parseDeepLink, useDeepLink } from './deepLink/index.js';
31
31
  export type { DateInput, DateStyle, FormatCurrencyOptions, FormatPhoneOptions, PhoneCountry, PhoneNumber, TimeStyle } from './formatters/index.js';
32
- export { detectPhoneCountry, formatCompactNumber, formatCurrency, formatDate, formatDateTime, formatNumber, formatPercent, formatPhone, formatRelativeTime, formatTime, getInitials, isValidPhoneNumber, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString } from './formatters/index.js';
32
+ export { addDays, detectPhoneCountry, diffMs, formatCompactNumber, formatCurrency, formatDate, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatDateTime, formatNumber, formatPercent, formatPhone, formatRelativeTime, formatTime, formatTime12h, formatTimeInZone, getInitials, isDateAfter, isDateBefore, isSameDay, isValidPhoneNumber, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString, startOfDay } from './formatters/index.js';
33
33
  export type { InitConfig } from './initSDK.js';
34
34
  export { initWebority } from './initSDK.js';
35
35
  export type { AuthActions } from './initUserAuth.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority-technologies/mobile-core",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Platform layer for Webority React Native apps: HTTP clients, auth/token storage, config, logging, formatters, validators, network status, permissions, storage and version checks. No UI.",
5
5
  "keywords": [
6
6
  "react-native",