@temboplus/frontend-core 0.2.20-beta.1 → 0.2.20-beta.3
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/dist/index.cjs.js +3 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/models/amount/amount.d.ts +26 -101
- package/dist/models/bank/bank.d.ts +5 -10
- package/dist/models/bank/bank.schema.d.ts +20 -0
- package/dist/models/country/country.d.ts +7 -10
- package/dist/models/country/country.schema.d.ts +28 -1
- package/dist/models/currency/currency.d.ts +5 -8
- package/dist/models/currency/currency.schema.d.ts +16 -0
- package/dist/models/phone-number/phone-number.d.ts +24 -89
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { CurrencyCode } from "../currency/index.js";
|
|
2
3
|
/**
|
|
3
4
|
* Regular expression for validating amount strings
|
|
@@ -5,18 +6,33 @@ import { CurrencyCode } from "../currency/index.js";
|
|
|
5
6
|
*/
|
|
6
7
|
declare const AMOUNT_REGEX: RegExp;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Zod schema for Amount JSON serialization
|
|
10
|
+
* This schema validates the JSON representation of an Amount instance
|
|
9
11
|
*/
|
|
10
|
-
export
|
|
12
|
+
export declare const AmountJSONSchema: z.ZodObject<{
|
|
11
13
|
/** The numeric value of the amount (can be positive, negative, or zero) */
|
|
12
|
-
value:
|
|
14
|
+
value: z.ZodNumber;
|
|
13
15
|
/** The formatted text representation of the amount */
|
|
14
|
-
text:
|
|
16
|
+
text: z.ZodString;
|
|
15
17
|
/** The ISO currency code */
|
|
16
|
-
currencyCode:
|
|
18
|
+
currencyCode: z.ZodString;
|
|
17
19
|
/** Version for future compatibility */
|
|
18
|
-
version
|
|
19
|
-
}
|
|
20
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
version: string;
|
|
23
|
+
value: number;
|
|
24
|
+
text: string;
|
|
25
|
+
currencyCode: string;
|
|
26
|
+
}, {
|
|
27
|
+
value: number;
|
|
28
|
+
text: string;
|
|
29
|
+
currencyCode: string;
|
|
30
|
+
version?: string | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Infer the AmountJSON type from the schema
|
|
34
|
+
*/
|
|
35
|
+
export type AmountJSON = z.infer<typeof AmountJSONSchema>;
|
|
20
36
|
/**
|
|
21
37
|
* Represents a monetary amount with currency information
|
|
22
38
|
*
|
|
@@ -576,114 +592,23 @@ declare class Amount {
|
|
|
576
592
|
*/
|
|
577
593
|
getWholeValue(): number;
|
|
578
594
|
/**
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Serializes the Amount instance to a JSON-compatible object
|
|
583
|
-
*
|
|
584
|
-
* This method creates a plain object representation that can be safely
|
|
585
|
-
* serialized to JSON without losing any essential data.
|
|
586
|
-
*
|
|
587
|
-
* @returns {AmountJSON} A plain object containing all necessary Amount data
|
|
588
|
-
*
|
|
589
|
-
* @example
|
|
590
|
-
* ```typescript
|
|
591
|
-
* const amount = Amount.from(-1234.56, 'USD');
|
|
592
|
-
* const json = amount.toJSON();
|
|
593
|
-
* console.log(json);
|
|
594
|
-
* // {
|
|
595
|
-
* // value: -1234.56,
|
|
596
|
-
* // text: "1,234.56",
|
|
597
|
-
* // currencyCode: "USD",
|
|
598
|
-
* // version: "1.0"
|
|
599
|
-
* // }
|
|
600
|
-
*
|
|
601
|
-
* // Can be safely stringified
|
|
602
|
-
* const jsonString = JSON.stringify(json);
|
|
603
|
-
* ```
|
|
604
|
-
*/
|
|
595
|
+
* Serializes the Amount instance to a JSON-compatible object
|
|
596
|
+
*/
|
|
605
597
|
toJSON(): AmountJSON;
|
|
606
598
|
/**
|
|
607
599
|
* Serializes the Amount instance to a JSON string
|
|
608
|
-
*
|
|
609
|
-
* @returns {string} JSON string representation of the amount
|
|
610
|
-
*
|
|
611
|
-
* @example
|
|
612
|
-
* ```typescript
|
|
613
|
-
* const amount = Amount.from(1000, 'TZS');
|
|
614
|
-
* const jsonString = amount.toJSONString();
|
|
615
|
-
* console.log(jsonString);
|
|
616
|
-
* // '{"value":1000,"text":"1,000","currencyCode":"TZS","version":"1.0"}'
|
|
617
|
-
*
|
|
618
|
-
* // Store or transmit
|
|
619
|
-
* localStorage.setItem('paymentAmount', jsonString);
|
|
620
|
-
*
|
|
621
|
-
* // Later, retrieve and reconstruct
|
|
622
|
-
* const stored = localStorage.getItem('paymentAmount');
|
|
623
|
-
* const reconstructed = Amount.fromJSONString(stored!);
|
|
624
|
-
* ```
|
|
625
600
|
*/
|
|
626
601
|
toJSONString(): string;
|
|
627
602
|
/**
|
|
628
603
|
* Creates an Amount instance from a JSON-compatible object or string
|
|
629
|
-
*
|
|
630
|
-
* This static method reconstructs an Amount instance from data that was
|
|
631
|
-
* previously serialized using toJSON(). It validates the input data and
|
|
632
|
-
* ensures the resulting Amount is valid.
|
|
633
|
-
*
|
|
634
|
-
* @param {AmountJSON | string} json - Either an AmountJSON object or a JSON string
|
|
635
|
-
* @returns {Amount | undefined} An Amount instance if valid, undefined otherwise
|
|
636
|
-
*
|
|
637
|
-
* @example
|
|
638
|
-
* ```typescript
|
|
639
|
-
* // From object
|
|
640
|
-
* const jsonData = {
|
|
641
|
-
* value: -1234.56,
|
|
642
|
-
* text: "1,234.56",
|
|
643
|
-
* currencyCode: "USD",
|
|
644
|
-
* version: "1.0"
|
|
645
|
-
* };
|
|
646
|
-
* const amount = Amount.fromJSON(jsonData);
|
|
647
|
-
*
|
|
648
|
-
* // From JSON string
|
|
649
|
-
* const jsonString = '{"value":-1234.56,"text":"1,234.56","currencyCode":"USD","version":"1.0"}';
|
|
650
|
-
* const amount2 = Amount.fromJSON(jsonString);
|
|
651
|
-
*
|
|
652
|
-
* // Both create equivalent Amount instances
|
|
653
|
-
* console.log(amount?.label); // "-$1,234.56"
|
|
654
|
-
* console.log(amount2?.label); // "-$1,234.56"
|
|
655
|
-
* ```
|
|
656
604
|
*/
|
|
657
605
|
static fromJSON(json: AmountJSON | string): Amount | undefined;
|
|
658
606
|
/**
|
|
659
607
|
* Creates an Amount instance from a JSON string
|
|
660
|
-
*
|
|
661
|
-
* Convenience method that calls fromJSON() with a string parameter.
|
|
662
|
-
*
|
|
663
|
-
* @param {string} jsonString - JSON string containing amount data
|
|
664
|
-
* @returns {Amount | undefined} An Amount instance if valid, undefined otherwise
|
|
665
|
-
*
|
|
666
|
-
* @example
|
|
667
|
-
* ```typescript
|
|
668
|
-
* const jsonString = '{"value":1000,"text":"1,000","currencyCode":"TZS","version":"1.0"}';
|
|
669
|
-
* const amount = Amount.fromJSONString(jsonString);
|
|
670
|
-
* console.log(amount?.label); // "TSh 1,000"
|
|
671
|
-
* ```
|
|
672
608
|
*/
|
|
673
609
|
static fromJSONString(jsonString: string): Amount | undefined;
|
|
674
610
|
/**
|
|
675
|
-
* Type guard to check if an object is a valid AmountJSON
|
|
676
|
-
*
|
|
677
|
-
* @param obj - The object to validate
|
|
678
|
-
* @returns True if the object conforms to AmountJSON structure
|
|
679
|
-
*
|
|
680
|
-
* @example
|
|
681
|
-
* ```typescript
|
|
682
|
-
* const data = { value: 100, text: "100.00", currencyCode: "USD" };
|
|
683
|
-
* if (Amount.isAmountJSON(data)) {
|
|
684
|
-
* const amount = Amount.fromJSON(data);
|
|
685
|
-
* }
|
|
686
|
-
* ```
|
|
611
|
+
* Type guard to check if an object is a valid AmountJSON using Zod validation
|
|
687
612
|
*/
|
|
688
613
|
static isAmountJSON(obj: unknown): obj is AmountJSON;
|
|
689
614
|
/**
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { ISO2CountryCode } from "../country/country.types.js";
|
|
2
2
|
import type { BankSwiftCode, KEBankSwiftCode, TZBankSwiftCode } from "./bank.types.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { BankJSONSchema } from "./bank.schema.js";
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
6
|
+
* Infer the BankJSON type from the schema
|
|
5
7
|
*/
|
|
6
|
-
export
|
|
7
|
-
/** The SWIFT/BIC code for the bank's head office */
|
|
8
|
-
swiftCode: string;
|
|
9
|
-
/** The ISO 3166-1 alpha-2 country code */
|
|
10
|
-
countryCode: string;
|
|
11
|
-
/** Version for future compatibility */
|
|
12
|
-
version?: string;
|
|
13
|
-
}
|
|
8
|
+
export type BankJSON = z.infer<typeof BankJSONSchema>;
|
|
14
9
|
export declare class Bank {
|
|
15
10
|
/**
|
|
16
11
|
* The full registered name of the bank.
|
|
@@ -99,7 +94,7 @@ export declare class Bank {
|
|
|
99
94
|
*/
|
|
100
95
|
static fromJSONString(jsonString: string): Bank | undefined;
|
|
101
96
|
/**
|
|
102
|
-
* Type guard to check if an object is a valid BankJSON
|
|
97
|
+
* Type guard to check if an object is a valid BankJSON using Zod validation
|
|
103
98
|
*/
|
|
104
99
|
static isBankJSON(obj: unknown): obj is BankJSON;
|
|
105
100
|
}
|
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const TZBankSWIFTCodeSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
3
3
|
export declare const KEBankSWIFTCodeSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
4
|
+
/**
|
|
5
|
+
* Zod schema for Bank JSON serialization
|
|
6
|
+
* This schema validates the JSON representation of a Bank instance
|
|
7
|
+
*/
|
|
8
|
+
export declare const BankJSONSchema: z.ZodObject<{
|
|
9
|
+
/** The SWIFT/BIC code for the bank's head office */
|
|
10
|
+
swiftCode: z.ZodString;
|
|
11
|
+
/** The ISO 3166-1 alpha-2 country code */
|
|
12
|
+
countryCode: z.ZodString;
|
|
13
|
+
/** Version for future compatibility */
|
|
14
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
version: string;
|
|
17
|
+
swiftCode: string;
|
|
18
|
+
countryCode: string;
|
|
19
|
+
}, {
|
|
20
|
+
swiftCode: string;
|
|
21
|
+
countryCode: string;
|
|
22
|
+
version?: string | undefined;
|
|
23
|
+
}>;
|
|
@@ -27,15 +27,12 @@
|
|
|
27
27
|
import { Currency } from "@models/currency/currency.js";
|
|
28
28
|
import { CurrencyCode } from "@models/currency/currency.types.js";
|
|
29
29
|
import { ISO2CountryCode, ISO3CountryCode, CountryCode } from "./country.types.js";
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
import { CountryJSONSchema } from "./country.schema.js";
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
33
|
+
* Infer the CountryJSON type from the schema
|
|
32
34
|
*/
|
|
33
|
-
export
|
|
34
|
-
/** The ISO 3166-1 alpha-2 country code */
|
|
35
|
-
code: string;
|
|
36
|
-
/** Version for future compatibility */
|
|
37
|
-
version?: string;
|
|
38
|
-
}
|
|
35
|
+
export type CountryJSON = z.infer<typeof CountryJSONSchema>;
|
|
39
36
|
/**
|
|
40
37
|
* Enum for continents
|
|
41
38
|
*/
|
|
@@ -726,8 +723,8 @@ export declare class Country {
|
|
|
726
723
|
*/
|
|
727
724
|
static is(obj: unknown): obj is Country;
|
|
728
725
|
/**
|
|
729
|
-
|
|
730
|
-
|
|
726
|
+
* Serializes the Country instance to a JSON-compatible object
|
|
727
|
+
*/
|
|
731
728
|
toJSON(): CountryJSON;
|
|
732
729
|
/**
|
|
733
730
|
* Serializes the Country instance to a JSON string
|
|
@@ -742,7 +739,7 @@ export declare class Country {
|
|
|
742
739
|
*/
|
|
743
740
|
static fromJSONString(jsonString: string): Country | undefined;
|
|
744
741
|
/**
|
|
745
|
-
* Type guard to check if an object is a valid CountryJSON
|
|
742
|
+
* Type guard to check if an object is a valid CountryJSON using Zod validation
|
|
746
743
|
*/
|
|
747
744
|
static isCountryJSON(obj: unknown): obj is CountryJSON;
|
|
748
745
|
}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for Country JSON serialization
|
|
4
|
+
* This schema validates the JSON representation of a Country instance
|
|
5
|
+
*/
|
|
6
|
+
export declare const CountryJSONSchema: z.ZodObject<{
|
|
7
|
+
/** The ISO 3166-1 alpha-2 country code */
|
|
8
|
+
code: z.ZodString;
|
|
9
|
+
/** Version for future compatibility */
|
|
10
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
code: string;
|
|
13
|
+
version: string;
|
|
14
|
+
}, {
|
|
15
|
+
code: string;
|
|
16
|
+
version?: string | undefined;
|
|
17
|
+
}>;
|
|
2
18
|
/**
|
|
3
19
|
* Zod schema for validating ISO 3166-1 alpha-2 country codes.
|
|
4
20
|
*
|
|
@@ -43,4 +59,15 @@ export declare const ISO3CountryCodeSchema: z.ZodEffects<z.ZodString, string, st
|
|
|
43
59
|
* console.error("Invalid country code");
|
|
44
60
|
* }
|
|
45
61
|
*/
|
|
46
|
-
export declare const CountryCodeSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string
|
|
62
|
+
export declare const CountryCodeSchema: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>, z.ZodObject<{
|
|
63
|
+
/** The ISO 3166-1 alpha-2 country code */
|
|
64
|
+
code: z.ZodString;
|
|
65
|
+
/** Version for future compatibility */
|
|
66
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
code: string;
|
|
69
|
+
version: string;
|
|
70
|
+
}, {
|
|
71
|
+
code: string;
|
|
72
|
+
version?: string | undefined;
|
|
73
|
+
}>]>;
|
|
@@ -27,15 +27,12 @@
|
|
|
27
27
|
* dependencies are best managed in a unified module.
|
|
28
28
|
*/
|
|
29
29
|
import type { CurrencyCode } from "./currency.types.js";
|
|
30
|
+
import { z } from "zod";
|
|
31
|
+
import { CurrencyJSONSchema } from "./currency.schema.js";
|
|
30
32
|
/**
|
|
31
|
-
*
|
|
33
|
+
* Infer the CurrencyJSON type from the schema
|
|
32
34
|
*/
|
|
33
|
-
export
|
|
34
|
-
/** The ISO 4217 currency code */
|
|
35
|
-
code: string;
|
|
36
|
-
/** Version for future compatibility */
|
|
37
|
-
version?: string;
|
|
38
|
-
}
|
|
35
|
+
export type CurrencyJSON = z.infer<typeof CurrencyJSONSchema>;
|
|
39
36
|
/**
|
|
40
37
|
* Represents a currency with essential details.
|
|
41
38
|
* @class Currency
|
|
@@ -393,7 +390,7 @@ export declare class Currency {
|
|
|
393
390
|
*/
|
|
394
391
|
static fromJSONString(jsonString: string): Currency | undefined;
|
|
395
392
|
/**
|
|
396
|
-
* Type guard to check if an object is a valid CurrencyJSON
|
|
393
|
+
* Type guard to check if an object is a valid CurrencyJSON using Zod validation
|
|
397
394
|
*/
|
|
398
395
|
static isCurrencyJSON(obj: unknown): obj is CurrencyJSON;
|
|
399
396
|
}
|
|
@@ -6,3 +6,19 @@ import { z } from "zod";
|
|
|
6
6
|
* If the validation fails, it returns an error message.
|
|
7
7
|
*/
|
|
8
8
|
export declare const CurrencyCodeSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
9
|
+
/**
|
|
10
|
+
* Zod schema for Currency JSON serialization
|
|
11
|
+
* This schema validates the JSON representation of a Currency instance
|
|
12
|
+
*/
|
|
13
|
+
export declare const CurrencyJSONSchema: z.ZodObject<{
|
|
14
|
+
/** The ISO 4217 currency code */
|
|
15
|
+
code: z.ZodString;
|
|
16
|
+
/** Version for future compatibility */
|
|
17
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
code: string;
|
|
20
|
+
version: string;
|
|
21
|
+
}, {
|
|
22
|
+
code: string;
|
|
23
|
+
version?: string | undefined;
|
|
24
|
+
}>;
|
|
@@ -3,15 +3,33 @@ import type { PhoneNumber as LibPhoneNumberInstance } from "libphonenumber-js";
|
|
|
3
3
|
import { MNOInfo } from "./mno/mno.types.js";
|
|
4
4
|
import { PhoneNumberService, ParsedPhoneNumber } from "./phone-number.service.js";
|
|
5
5
|
import { PhoneNumberContract, PhoneNumberFormat, PhoneNumberType, PhoneNumberParseOptions } from "./phone-number.types.js";
|
|
6
|
+
import { z } from "zod";
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* Zod schema for PhoneNumber JSON serialization
|
|
9
|
+
* This schema validates the JSON representation of a PhoneNumber instance
|
|
10
|
+
*
|
|
11
|
+
* E.164 format validation rules:
|
|
12
|
+
* - Starts with '+'
|
|
13
|
+
* - Followed by country code (1-3 digits, first digit 1-9)
|
|
14
|
+
* - Total length: 8-16 characters (including '+')
|
|
15
|
+
* - Contains only digits after '+'
|
|
8
16
|
*/
|
|
9
|
-
export
|
|
17
|
+
export declare const PhoneNumberJSONSchema: z.ZodObject<{
|
|
10
18
|
/** The phone number in E.164 format */
|
|
11
|
-
e164Format:
|
|
19
|
+
e164Format: z.ZodString;
|
|
12
20
|
/** Version for future compatibility */
|
|
13
|
-
version
|
|
14
|
-
}
|
|
21
|
+
version: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
version: string;
|
|
24
|
+
e164Format: string;
|
|
25
|
+
}, {
|
|
26
|
+
e164Format: string;
|
|
27
|
+
version?: string | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
/**
|
|
30
|
+
* Infer the PhoneNumberJSON type from the schema
|
|
31
|
+
*/
|
|
32
|
+
export type PhoneNumberJSON = z.infer<typeof PhoneNumberJSONSchema>;
|
|
15
33
|
/**
|
|
16
34
|
* Represents a generic international phone number, validated using libphonenumber-js
|
|
17
35
|
* via the PhoneNumberService. Implements the common PhoneNumberContract interface.
|
|
@@ -90,40 +108,10 @@ export declare class PhoneNumber implements PhoneNumberContract {
|
|
|
90
108
|
* This method creates a minimal object representation. Only the E.164 format
|
|
91
109
|
* is stored as everything else (country code, compact number, number type,
|
|
92
110
|
* and MNO info) can be reconstructed from it.
|
|
93
|
-
*
|
|
94
|
-
* @returns {PhoneNumberJSON} A plain object containing minimal PhoneNumber data
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
97
|
-
* ```typescript
|
|
98
|
-
* const phone = PhoneNumber.from('+255712345678');
|
|
99
|
-
* const json = phone.toJSON();
|
|
100
|
-
* console.log(json);
|
|
101
|
-
* // {
|
|
102
|
-
* // e164Format: "+255712345678",
|
|
103
|
-
* // version: "1.0"
|
|
104
|
-
* // }
|
|
105
|
-
* ```
|
|
106
111
|
*/
|
|
107
112
|
toJSON(): PhoneNumberJSON;
|
|
108
113
|
/**
|
|
109
114
|
* Serializes the PhoneNumber instance to a JSON string
|
|
110
|
-
*
|
|
111
|
-
* @returns {string} JSON string representation of the phone number
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const phone = PhoneNumber.from('+254712345678');
|
|
116
|
-
* const jsonString = phone.toJSONString();
|
|
117
|
-
* console.log(jsonString);
|
|
118
|
-
* // '{"e164Format":"+254712345678","version":"1.0"}'
|
|
119
|
-
*
|
|
120
|
-
* // Store or transmit
|
|
121
|
-
* localStorage.setItem('userPhone', jsonString);
|
|
122
|
-
*
|
|
123
|
-
* // Later, retrieve and reconstruct
|
|
124
|
-
* const stored = localStorage.getItem('userPhone');
|
|
125
|
-
* const reconstructed = PhoneNumber.fromJSONString(stored!);
|
|
126
|
-
* ```
|
|
127
115
|
*/
|
|
128
116
|
toJSONString(): string;
|
|
129
117
|
/**
|
|
@@ -134,67 +122,14 @@ export declare class PhoneNumber implements PhoneNumberContract {
|
|
|
134
122
|
* the appropriate instance (generic or country-specific like TZMobileNumber).
|
|
135
123
|
* All properties including country code, compact number, MNO info, and number
|
|
136
124
|
* type are automatically reconstructed from the E.164 format.
|
|
137
|
-
*
|
|
138
|
-
* @param {PhoneNumberJSON | string} json - Either a PhoneNumberJSON object or a JSON string
|
|
139
|
-
* @returns {PhoneNumber | undefined} A PhoneNumber instance if valid, undefined otherwise
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```typescript
|
|
143
|
-
* // From object
|
|
144
|
-
* const jsonData = {
|
|
145
|
-
* e164Format: "+255712345678",
|
|
146
|
-
* version: "1.0"
|
|
147
|
-
* };
|
|
148
|
-
* const phone = PhoneNumber.fromJSON(jsonData);
|
|
149
|
-
*
|
|
150
|
-
* // From JSON string
|
|
151
|
-
* const jsonString = '{"e164Format":"+254712345678","version":"1.0"}';
|
|
152
|
-
* const phone2 = PhoneNumber.fromJSON(jsonString);
|
|
153
|
-
*
|
|
154
|
-
* // Both create appropriate PhoneNumber instances with all properties reconstructed
|
|
155
|
-
* console.log(phone?.countryCode); // "TZ"
|
|
156
|
-
* console.log(phone?.compactNumber); // "712345678"
|
|
157
|
-
* console.log(phone?.getOperatorInfo()?.displayName); // "Vodacom" (reconstructed!)
|
|
158
|
-
* console.log(phone?.getNumberType()); // "MOBILE"
|
|
159
|
-
*
|
|
160
|
-
* console.log(phone2?.countryCode); // "KE"
|
|
161
|
-
* console.log(phone2?.compactNumber); // "712345678"
|
|
162
|
-
* ```
|
|
163
125
|
*/
|
|
164
126
|
static fromJSON(json: PhoneNumberJSON | string): PhoneNumber | undefined;
|
|
165
127
|
/**
|
|
166
128
|
* Creates a PhoneNumber instance from a JSON string
|
|
167
|
-
*
|
|
168
|
-
* Convenience method that calls fromJSON() with a string parameter.
|
|
169
|
-
*
|
|
170
|
-
* @param {string} jsonString - JSON string containing phone number data
|
|
171
|
-
* @returns {PhoneNumber | undefined} A PhoneNumber instance if valid, undefined otherwise
|
|
172
|
-
*
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* const jsonString = '{"e164Format":"+255712345678","version":"1.0"}';
|
|
176
|
-
* const phone = PhoneNumber.fromJSONString(jsonString);
|
|
177
|
-
* console.log(phone?.label); // "+255 712 345 678"
|
|
178
|
-
* console.log(phone?.getOperatorInfo()?.mobileMoneyService); // "M-Pesa" (reconstructed!)
|
|
179
|
-
* ```
|
|
180
129
|
*/
|
|
181
130
|
static fromJSONString(jsonString: string): PhoneNumber | undefined;
|
|
182
131
|
/**
|
|
183
|
-
* Type guard to check if an object is a valid PhoneNumberJSON
|
|
184
|
-
*
|
|
185
|
-
* @param obj - The object to validate
|
|
186
|
-
* @returns True if the object conforms to PhoneNumberJSON structure
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```typescript
|
|
190
|
-
* const data = {
|
|
191
|
-
* e164Format: "+255712345678",
|
|
192
|
-
* version: "1.0"
|
|
193
|
-
* };
|
|
194
|
-
* if (PhoneNumber.isPhoneNumberJSON(data)) {
|
|
195
|
-
* const phone = PhoneNumber.fromJSON(data);
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
132
|
+
* Type guard to check if an object is a valid PhoneNumberJSON using Zod validation
|
|
198
133
|
*/
|
|
199
134
|
static isPhoneNumberJSON(obj: unknown): obj is PhoneNumberJSON;
|
|
200
135
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temboplus/frontend-core",
|
|
3
|
-
"version": "0.2.20-beta.
|
|
3
|
+
"version": "0.2.20-beta.3",
|
|
4
4
|
"description": "A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.",
|
|
5
5
|
"author": "Okello Gerald",
|
|
6
6
|
"license": "MIT",
|