@tagadapay/headless-sdk 1.1.1 → 1.3.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/dist/core/client.d.ts +2 -5
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +1 -3
- package/dist/core/client.js.map +1 -1
- package/dist/core/helpers/autocomplete.d.ts +89 -0
- package/dist/core/helpers/autocomplete.d.ts.map +1 -0
- package/dist/core/helpers/autocomplete.js +186 -0
- package/dist/core/helpers/autocomplete.js.map +1 -0
- package/dist/core/helpers/countries.d.ts +45 -0
- package/dist/core/helpers/countries.d.ts.map +1 -0
- package/dist/core/helpers/countries.js +65 -0
- package/dist/core/helpers/countries.js.map +1 -0
- package/dist/core/helpers/currency.d.ts +26 -0
- package/dist/core/helpers/currency.d.ts.map +1 -0
- package/dist/core/helpers/currency.js +72 -0
- package/dist/core/helpers/currency.js.map +1 -0
- package/dist/core/helpers/index.d.ts +5 -0
- package/dist/core/helpers/index.d.ts.map +1 -0
- package/dist/core/helpers/index.js +5 -0
- package/dist/core/helpers/index.js.map +1 -0
- package/dist/core/helpers/iso3166.d.ts +28 -0
- package/dist/core/helpers/iso3166.d.ts.map +1 -0
- package/dist/core/helpers/iso3166.js +84 -0
- package/dist/core/helpers/iso3166.js.map +1 -0
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/modules/offers.d.ts +64 -23
- package/dist/core/modules/offers.d.ts.map +1 -1
- package/dist/core/modules/offers.js +70 -33
- package/dist/core/modules/offers.js.map +1 -1
- package/dist/core/types.d.ts +26 -16
- package/dist/core/types.d.ts.map +1 -1
- package/dist/react/hooks/useGoogleAutocomplete.d.ts +26 -0
- package/dist/react/hooks/useGoogleAutocomplete.d.ts.map +1 -0
- package/dist/react/hooks/useGoogleAutocomplete.js +70 -0
- package/dist/react/hooks/useGoogleAutocomplete.js.map +1 -0
- package/dist/react/hooks/useISOData.d.ts +23 -0
- package/dist/react/hooks/useISOData.d.ts.map +1 -0
- package/dist/react/hooks/useISOData.js +63 -0
- package/dist/react/hooks/useISOData.js.map +1 -0
- package/dist/react/hooks/useOffers.d.ts +63 -22
- package/dist/react/hooks/useOffers.d.ts.map +1 -1
- package/dist/react/hooks/useOffers.js +36 -52
- package/dist/react/hooks/useOffers.js.map +1 -1
- package/dist/react/index.d.ts +7 -3
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +4 -1
- package/dist/react/index.js.map +1 -1
- package/dist/tagada-headless-react.min.js +2 -2
- package/dist/tagada-headless-react.min.js.map +4 -4
- package/dist/tagada-headless.js +536 -292
- package/dist/tagada-headless.min.js +2 -2
- package/dist/tagada-headless.min.js.map +4 -4
- package/package.json +3 -3
- package/dist/core/modules/analytics.d.ts +0 -79
- package/dist/core/modules/analytics.d.ts.map +0 -1
- package/dist/core/modules/analytics.js +0 -265
- package/dist/core/modules/analytics.js.map +0 -1
- package/dist/react/hooks/useAnalytics.d.ts +0 -59
- package/dist/react/hooks/useAnalytics.d.ts.map +0 -1
- package/dist/react/hooks/useAnalytics.js +0 -49
- package/dist/react/hooks/useAnalytics.js.map +0 -1
package/dist/core/client.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CheckoutModule } from './modules/checkout.js';
|
|
2
2
|
import { PaymentModule } from './modules/payment.js';
|
|
3
|
-
import { AnalyticsModule } from './modules/analytics.js';
|
|
4
3
|
import { OffersModule } from './modules/offers.js';
|
|
5
4
|
import { CustomerModule } from './modules/customer.js';
|
|
6
5
|
import { CatalogModule } from './modules/catalog.js';
|
|
@@ -8,7 +7,7 @@ import type { HeadlessConfig } from './types.js';
|
|
|
8
7
|
/**
|
|
9
8
|
* Main entry point for the TagadaPay Headless SDK.
|
|
10
9
|
*
|
|
11
|
-
* Composes all domain modules (checkout, payment,
|
|
10
|
+
* Composes all domain modules (checkout, payment, offers, customer, catalog)
|
|
12
11
|
* over a single lightweight HTTP client built on native fetch.
|
|
13
12
|
*/
|
|
14
13
|
export declare class HeadlessClient {
|
|
@@ -20,9 +19,7 @@ export declare class HeadlessClient {
|
|
|
20
19
|
readonly checkout: CheckoutModule;
|
|
21
20
|
/** Payment processing -- setup config, APMs, tokenize, pay, 3DS, poll. */
|
|
22
21
|
readonly payment: PaymentModule;
|
|
23
|
-
/**
|
|
24
|
-
readonly analytics: AnalyticsModule;
|
|
25
|
-
/** Post-purchase offers -- load, accept, decline upsells and order bumps. */
|
|
22
|
+
/** Offers -- preview, pay, accept/decline upsells and order bumps. */
|
|
26
23
|
readonly offers: OffersModule;
|
|
27
24
|
/** Customer data -- profile, orders, subscriptions. */
|
|
28
25
|
readonly customer: CustomerModule;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,YAAY,CAAC;AAE9D;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,aAAa,CAAC,CAAC,GAAG,cAAc,CAAC;IAE5F,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAElC,4EAA4E;IAC5E,OAAO,CAAC,aAAa,CAAqB;IAE1C,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAElC,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAEhC,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAE9B,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAElC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;gBAEpB,MAAM,EAAE,cAAc;IA6BlC,0EAA0E;IAC1E,eAAe,CAAC,KAAK,EAAE,MAAM;CAG9B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAE3E"}
|
package/dist/core/client.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { HttpClient } from './http.js';
|
|
2
2
|
import { CheckoutModule } from './modules/checkout.js';
|
|
3
3
|
import { PaymentModule } from './modules/payment.js';
|
|
4
|
-
import { AnalyticsModule } from './modules/analytics.js';
|
|
5
4
|
import { OffersModule } from './modules/offers.js';
|
|
6
5
|
import { CustomerModule } from './modules/customer.js';
|
|
7
6
|
import { CatalogModule } from './modules/catalog.js';
|
|
8
7
|
/**
|
|
9
8
|
* Main entry point for the TagadaPay Headless SDK.
|
|
10
9
|
*
|
|
11
|
-
* Composes all domain modules (checkout, payment,
|
|
10
|
+
* Composes all domain modules (checkout, payment, offers, customer, catalog)
|
|
12
11
|
* over a single lightweight HTTP client built on native fetch.
|
|
13
12
|
*/
|
|
14
13
|
export class HeadlessClient {
|
|
@@ -32,7 +31,6 @@ export class HeadlessClient {
|
|
|
32
31
|
};
|
|
33
32
|
this.checkout = new CheckoutModule(this.http, this.config.storeId, setToken);
|
|
34
33
|
this.payment = new PaymentModule(this.http, this.config.storeId, environment);
|
|
35
|
-
this.analytics = new AnalyticsModule(this.http, this.config.storeId);
|
|
36
34
|
this.offers = new OffersModule(this.http, this.config.storeId);
|
|
37
35
|
this.customer = new CustomerModule(this.http, this.config.storeId);
|
|
38
36
|
this.catalog = new CatalogModule(this.http, this.config.storeId);
|
package/dist/core/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAGrD;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAuBzB,YAAY,MAAsB;QAChC,MAAM,WAAW,GAAgB,MAAM,CAAC,WAAW,IAAI,YAAY,CAAC;QACpE,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAEvE,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,MAAM;YACT,WAAW;YACX,OAAO;YACP,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAM;SAClC,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,C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dependencies beyond the Google Maps JS API).
|
|
4
|
+
*/
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
google?: {
|
|
8
|
+
maps?: {
|
|
9
|
+
places?: {
|
|
10
|
+
AutocompleteService: new () => any;
|
|
11
|
+
PlacesService: new (el: any) => any;
|
|
12
|
+
PlacesServiceStatus: {
|
|
13
|
+
OK: string;
|
|
14
|
+
ZERO_RESULTS: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
Map: new (el: HTMLElement) => any;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export interface GooglePrediction {
|
|
23
|
+
place_id: string;
|
|
24
|
+
description: string;
|
|
25
|
+
structured_formatting?: {
|
|
26
|
+
main_text: string;
|
|
27
|
+
secondary_text: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface GooglePlaceDetails {
|
|
31
|
+
place_id: string;
|
|
32
|
+
formatted_address: string;
|
|
33
|
+
address_components: Array<{
|
|
34
|
+
long_name: string;
|
|
35
|
+
short_name: string;
|
|
36
|
+
types: string[];
|
|
37
|
+
}>;
|
|
38
|
+
geometry?: {
|
|
39
|
+
location: {
|
|
40
|
+
lat: number;
|
|
41
|
+
lng: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export interface ExtractedAddress {
|
|
46
|
+
subpremise: string;
|
|
47
|
+
streetNumber: string;
|
|
48
|
+
route: string;
|
|
49
|
+
locality: string;
|
|
50
|
+
administrativeAreaLevel1: string;
|
|
51
|
+
administrativeAreaLevel1Long: string;
|
|
52
|
+
administrativeAreaLevel2: string;
|
|
53
|
+
administrativeAreaLevel2Long: string;
|
|
54
|
+
country: string;
|
|
55
|
+
postalCode: string;
|
|
56
|
+
fullStreetAddress: string;
|
|
57
|
+
}
|
|
58
|
+
export interface FormattedAddress {
|
|
59
|
+
address1: string;
|
|
60
|
+
city: string;
|
|
61
|
+
country: string;
|
|
62
|
+
state: string;
|
|
63
|
+
postal: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Inject the Google Maps JS SDK into the page (idempotent).
|
|
67
|
+
* Resolves once `window.google.maps.places` is available.
|
|
68
|
+
*/
|
|
69
|
+
export declare function loadGoogleMapsScript(apiKey: string, opts?: {
|
|
70
|
+
language?: string;
|
|
71
|
+
region?: string;
|
|
72
|
+
version?: string;
|
|
73
|
+
}): Promise<void>;
|
|
74
|
+
export declare class GoogleAutocompleteCore {
|
|
75
|
+
/** Search for address predictions. */
|
|
76
|
+
static searchPlaces(input: string, options?: {
|
|
77
|
+
types?: string[];
|
|
78
|
+
componentRestrictions?: {
|
|
79
|
+
country: string;
|
|
80
|
+
};
|
|
81
|
+
}): Promise<GooglePrediction[]>;
|
|
82
|
+
/** Get full place details by place_id. */
|
|
83
|
+
static getPlaceDetails(placeId: string): Promise<GooglePlaceDetails | null>;
|
|
84
|
+
/** Extract structured address fields from a Google PlaceDetails result. */
|
|
85
|
+
static extractAddressComponents(place: GooglePlaceDetails): ExtractedAddress;
|
|
86
|
+
/** Shorthand: extract into the flat shape used by address forms. */
|
|
87
|
+
static extractFormattedAddress(place: GooglePlaceDetails): FormattedAddress;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=autocomplete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/autocomplete.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,MAAM,CAAC,EAAE;YACP,IAAI,CAAC,EAAE;gBACL,MAAM,CAAC,EAAE;oBACP,mBAAmB,EAAE,UAAU,GAAG,CAAC;oBACnC,aAAa,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,GAAG,CAAC;oBACpC,mBAAmB,EAAE;wBAAE,EAAE,EAAE,MAAM,CAAC;wBAAC,Y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ACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAgBD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,IAAI,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAClE,OAAO,CAAC,IAAI,CAAC,CAyCf;AAMD,qBAAa,sBAAsB;IACjC,sCAAsC;WACzB,YAAY,CACvB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,qBAAqB,CAAC,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAO,GAC9E,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAc9B,0CAA0C;WAC7B,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAcjF,2EAA2E;IAC3E,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB;IAwE5E,oEAAoE;IACpE,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB;CAU5E"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Google Places Autocomplete — script injection + address extraction.
|
|
3
|
+
* Works standalone (no external dependencies beyond the Google Maps JS API).
|
|
4
|
+
*/
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Script injection
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
let scriptInjected = false;
|
|
9
|
+
let scriptReady = false;
|
|
10
|
+
const readyCallbacks = [];
|
|
11
|
+
function onScriptReady() {
|
|
12
|
+
scriptReady = true;
|
|
13
|
+
for (const cb of readyCallbacks)
|
|
14
|
+
cb();
|
|
15
|
+
readyCallbacks.length = 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Inject the Google Maps JS SDK into the page (idempotent).
|
|
19
|
+
* Resolves once `window.google.maps.places` is available.
|
|
20
|
+
*/
|
|
21
|
+
export function loadGoogleMapsScript(apiKey, opts = {}) {
|
|
22
|
+
if (scriptReady || window.google?.maps?.places) {
|
|
23
|
+
onScriptReady();
|
|
24
|
+
return Promise.resolve();
|
|
25
|
+
}
|
|
26
|
+
if (scriptInjected) {
|
|
27
|
+
return new Promise((resolve) => readyCallbacks.push(resolve));
|
|
28
|
+
}
|
|
29
|
+
scriptInjected = true;
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
readyCallbacks.push(resolve);
|
|
32
|
+
const existing = document.querySelector('script[src*="maps.googleapis.com"]');
|
|
33
|
+
if (existing) {
|
|
34
|
+
const poll = () => {
|
|
35
|
+
if (window.google?.maps?.places) {
|
|
36
|
+
onScriptReady();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
setTimeout(poll, 100);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
poll();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const params = new URLSearchParams({
|
|
46
|
+
key: apiKey,
|
|
47
|
+
libraries: 'places',
|
|
48
|
+
v: opts.version ?? 'weekly',
|
|
49
|
+
});
|
|
50
|
+
if (opts.language)
|
|
51
|
+
params.set('language', opts.language);
|
|
52
|
+
if (opts.region)
|
|
53
|
+
params.set('region', opts.region);
|
|
54
|
+
const script = document.createElement('script');
|
|
55
|
+
script.src = `https://maps.googleapis.com/maps/api/js?${params}`;
|
|
56
|
+
script.async = true;
|
|
57
|
+
script.defer = true;
|
|
58
|
+
script.onload = () => onScriptReady();
|
|
59
|
+
script.onerror = () => reject(new Error('Failed to load Google Maps script'));
|
|
60
|
+
document.head.appendChild(script);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// Core class
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
export class GoogleAutocompleteCore {
|
|
67
|
+
/** Search for address predictions. */
|
|
68
|
+
static async searchPlaces(input, options = {}) {
|
|
69
|
+
if (!window.google?.maps?.places || !input.trim())
|
|
70
|
+
return [];
|
|
71
|
+
const service = new window.google.maps.places.AutocompleteService();
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
service.getPlacePredictions({ input, types: options.types ?? ['address'], componentRestrictions: options.componentRestrictions }, (predictions, status) => {
|
|
74
|
+
resolve(status === window.google?.maps?.places?.PlacesServiceStatus.OK && predictions ? predictions : []);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Get full place details by place_id. */
|
|
79
|
+
static async getPlaceDetails(placeId) {
|
|
80
|
+
if (!window.google?.maps?.places)
|
|
81
|
+
return null;
|
|
82
|
+
const svc = new window.google.maps.places.PlacesService(document.createElement('div'));
|
|
83
|
+
return new Promise((resolve) => {
|
|
84
|
+
svc.getDetails({ placeId, fields: ['place_id', 'formatted_address', 'address_components', 'geometry'] }, (place, status) => {
|
|
85
|
+
resolve(status === window.google?.maps?.places?.PlacesServiceStatus.OK && place ? place : null);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/** Extract structured address fields from a Google PlaceDetails result. */
|
|
90
|
+
static extractAddressComponents(place) {
|
|
91
|
+
const out = {
|
|
92
|
+
subpremise: '', streetNumber: '', route: '', locality: '',
|
|
93
|
+
administrativeAreaLevel1: '', administrativeAreaLevel1Long: '',
|
|
94
|
+
administrativeAreaLevel2: '', administrativeAreaLevel2Long: '',
|
|
95
|
+
country: '', postalCode: '', fullStreetAddress: '',
|
|
96
|
+
};
|
|
97
|
+
let premise = '';
|
|
98
|
+
let neighborhood = '';
|
|
99
|
+
let sublocality5 = '', sublocality4 = '', sublocality3 = '', sublocality2 = '', sublocality1 = '';
|
|
100
|
+
let postalTown = '';
|
|
101
|
+
for (const c of place.address_components ?? []) {
|
|
102
|
+
const t = c.types;
|
|
103
|
+
if (t.includes('subpremise'))
|
|
104
|
+
out.subpremise = c.long_name;
|
|
105
|
+
if (t.includes('street_number'))
|
|
106
|
+
out.streetNumber = c.long_name;
|
|
107
|
+
if (t.includes('premise'))
|
|
108
|
+
premise = c.long_name;
|
|
109
|
+
if (t.includes('route'))
|
|
110
|
+
out.route = c.long_name;
|
|
111
|
+
if (t.includes('neighborhood'))
|
|
112
|
+
neighborhood = c.long_name;
|
|
113
|
+
if (t.includes('sublocality_level_5'))
|
|
114
|
+
sublocality5 = c.long_name;
|
|
115
|
+
if (t.includes('sublocality_level_4'))
|
|
116
|
+
sublocality4 = c.long_name;
|
|
117
|
+
if (t.includes('sublocality_level_3'))
|
|
118
|
+
sublocality3 = c.long_name;
|
|
119
|
+
if (t.includes('sublocality_level_2'))
|
|
120
|
+
sublocality2 = c.long_name;
|
|
121
|
+
if (t.includes('sublocality_level_1'))
|
|
122
|
+
sublocality1 = c.long_name;
|
|
123
|
+
if (t.includes('locality'))
|
|
124
|
+
out.locality = c.long_name;
|
|
125
|
+
if (t.includes('postal_town'))
|
|
126
|
+
postalTown = c.long_name;
|
|
127
|
+
if (t.includes('administrative_area_level_2')) {
|
|
128
|
+
out.administrativeAreaLevel2 = c.short_name;
|
|
129
|
+
out.administrativeAreaLevel2Long = c.long_name;
|
|
130
|
+
}
|
|
131
|
+
if (t.includes('administrative_area_level_1')) {
|
|
132
|
+
out.administrativeAreaLevel1 = c.short_name;
|
|
133
|
+
out.administrativeAreaLevel1Long = c.long_name;
|
|
134
|
+
}
|
|
135
|
+
if (t.includes('country'))
|
|
136
|
+
out.country = c.short_name;
|
|
137
|
+
if (t.includes('postal_code'))
|
|
138
|
+
out.postalCode = c.long_name;
|
|
139
|
+
}
|
|
140
|
+
// Locality fallbacks (UK postal_town, Asian sublocalities)
|
|
141
|
+
if (!out.locality)
|
|
142
|
+
out.locality = postalTown || sublocality2 || sublocality1 || '';
|
|
143
|
+
// French-style fallback: use département when région is missing
|
|
144
|
+
if (!out.administrativeAreaLevel1 && out.administrativeAreaLevel2) {
|
|
145
|
+
out.administrativeAreaLevel1 = out.administrativeAreaLevel2Long || out.administrativeAreaLevel2;
|
|
146
|
+
out.administrativeAreaLevel1Long = out.administrativeAreaLevel2Long;
|
|
147
|
+
}
|
|
148
|
+
// Build full street address
|
|
149
|
+
const buildingNumber = out.streetNumber || premise;
|
|
150
|
+
const streetName = out.route || sublocality5 || sublocality4 || sublocality3 || neighborhood;
|
|
151
|
+
if (out.subpremise && buildingNumber && streetName) {
|
|
152
|
+
out.fullStreetAddress = `${out.subpremise}/${buildingNumber} ${streetName}`;
|
|
153
|
+
}
|
|
154
|
+
else if (buildingNumber && streetName) {
|
|
155
|
+
if (premise && sublocality4 && sublocality3) {
|
|
156
|
+
let addr = `${sublocality3}-${sublocality4}-${premise}`;
|
|
157
|
+
if (sublocality2)
|
|
158
|
+
addr = `${addr} ${sublocality2}`;
|
|
159
|
+
out.fullStreetAddress = addr;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
out.fullStreetAddress = `${buildingNumber} ${streetName}`;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (streetName) {
|
|
166
|
+
out.fullStreetAddress = streetName;
|
|
167
|
+
}
|
|
168
|
+
else if (buildingNumber) {
|
|
169
|
+
out.fullStreetAddress = buildingNumber;
|
|
170
|
+
}
|
|
171
|
+
out.fullStreetAddress = out.fullStreetAddress.trim();
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
/** Shorthand: extract into the flat shape used by address forms. */
|
|
175
|
+
static extractFormattedAddress(place) {
|
|
176
|
+
const a = GoogleAutocompleteCore.extractAddressComponents(place);
|
|
177
|
+
return {
|
|
178
|
+
address1: a.fullStreetAddress,
|
|
179
|
+
city: a.locality,
|
|
180
|
+
country: a.country,
|
|
181
|
+
state: a.administrativeAreaLevel1,
|
|
182
|
+
postal: a.postalCode,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=autocomplete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.js","sourceRoot":"","sources":["../../../src/core/helpers/autocomplete.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoDH,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,MAAM,cAAc,GAAsB,EAAE,CAAC;AAE7C,SAAS,aAAa;IACpB,WAAW,GAAG,IAAI,CAAC;IACnB,KAAK,MAAM,EAAE,IAAI,cAAc;QAAE,EAAE,EAAE,CAAC;IACtC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAc,EACd,OAAiE,EAAE;IAEnE,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC/C,aAAa,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,cAAc,GAAG,IAAI,CAAC;IAEtB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE7B,MAAM,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,oCAAoC,CAAC,CAAC;QAC9E,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,IAAI,GAAG,GAAG,EAAE;gBAChB,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oBAAC,aAAa,EAAE,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C;iBAAM,CAAC;gBACN,GAAG,CAAC,iBAAiB,GAAG,GAAG,cAAc,IAAI,UAAU,EAAE,CAAC;YAC5D,CAAC;QACH,CAAC;aAAM,IAAI,UAAU,EAAE,CAAC;YACtB,GAAG,CAAC,iBAAiB,GAAG,UAAU,CAAC;QACrC,CAAC;aAAM,IAAI,cAAc,EAAE,CAAC;YAC1B,GAAG,CAAC,iBAAiB,GAAG,cAAc,CAAC;QACzC,CAAC;QAED,GAAG,CAAC,iBAAiB,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;QACrD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,oEAAoE;IACpE,MAAM,CAAC,uBAAuB,CAAC,KAAyB;QACtD,MAAM,CAAC,GAAG,sBAAsB,CAAC,wBAAwB,CAAC,KAAK,CAAC,CAAC;QACjE,OAAO;YACL,QAAQ,EAAE,CAAC,CAAC,iBAAiB;YAC7B,IAAI,EAAE,CAAC,CAAC,QAAQ;YAChB,OAAO,EAAE,CAAC,CAAC,OAAO;YAClB,KAAK,EAAE,CAAC,CAAC,wBAAwB;YACjC,MAAM,EAAE,CAAC,CAAC,UAAU;SACrB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO country/region helpers — countries list, regions by country,
|
|
3
|
+
* and Google Places state → ISO region mapping.
|
|
4
|
+
*/
|
|
5
|
+
import { AVAILABLE_LANGUAGES, type SupportedLanguage, type Country, type State } from './iso3166.js';
|
|
6
|
+
export type { SupportedLanguage, Country, State };
|
|
7
|
+
export { AVAILABLE_LANGUAGES };
|
|
8
|
+
export interface ISOCountry {
|
|
9
|
+
iso: string;
|
|
10
|
+
iso3: string;
|
|
11
|
+
numeric: number;
|
|
12
|
+
name: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ISORegion {
|
|
15
|
+
iso: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class ISODataCore {
|
|
19
|
+
/** Fetch countries + regions from CDN for a language. Call before sync getters. */
|
|
20
|
+
static ensureLoaded(language?: SupportedLanguage): Promise<void>;
|
|
21
|
+
/** Get all countries as a Record keyed by ISO code. */
|
|
22
|
+
static getCountries(language?: SupportedLanguage): Record<string, ISOCountry>;
|
|
23
|
+
/** Get all countries as a sorted array of { value, label } for select inputs. */
|
|
24
|
+
static getCountryOptions(language?: SupportedLanguage): Array<{
|
|
25
|
+
value: string;
|
|
26
|
+
label: string;
|
|
27
|
+
}>;
|
|
28
|
+
/** Get regions/states for a country. */
|
|
29
|
+
static getRegions(countryCode: string, language?: SupportedLanguage): ISORegion[];
|
|
30
|
+
/** Get regions as a sorted array of { value, label } for select inputs. */
|
|
31
|
+
static getRegionOptions(countryCode: string, language?: SupportedLanguage): Array<{
|
|
32
|
+
value: string;
|
|
33
|
+
label: string;
|
|
34
|
+
}>;
|
|
35
|
+
/** Find a specific region by ISO code. */
|
|
36
|
+
static findRegion(countryCode: string, regionCode: string, language?: SupportedLanguage): ISORegion | null;
|
|
37
|
+
/**
|
|
38
|
+
* Map a Google Places administrative_area to an ISO region.
|
|
39
|
+
* Tries exact ISO match, then name match, then partial match.
|
|
40
|
+
*/
|
|
41
|
+
static mapGoogleToISO(googleState: string, googleStateLong: string, countryCode: string, language?: SupportedLanguage): ISORegion | null;
|
|
42
|
+
static isLanguageLoaded(language: SupportedLanguage): boolean;
|
|
43
|
+
static getAvailableLanguages(): readonly SupportedLanguage[];
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=countries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countries.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/countries.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAKL,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,OAAO,EACZ,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAEtB,YAAY,EAAE,iBAAiB,EAAE,OAA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nB,QAAQ,GAAE,iBAAwB,GACjC,SAAS,GAAG,IAAI;IAsBnB,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,OAAO;IAI7D,MAAM,CAAC,qBAAqB,IAAI,SAAS,iBAAiB,EAAE;CAG7D"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISO country/region helpers — countries list, regions by country,
|
|
3
|
+
* and Google Places state → ISO region mapping.
|
|
4
|
+
*/
|
|
5
|
+
import { getCountries, getStatesForCountry, ensureGeoDataLoaded, isLanguageLoaded, AVAILABLE_LANGUAGES, } from './iso3166.js';
|
|
6
|
+
export { AVAILABLE_LANGUAGES };
|
|
7
|
+
export class ISODataCore {
|
|
8
|
+
/** Fetch countries + regions from CDN for a language. Call before sync getters. */
|
|
9
|
+
static ensureLoaded(language = 'en') {
|
|
10
|
+
return ensureGeoDataLoaded(language);
|
|
11
|
+
}
|
|
12
|
+
/** Get all countries as a Record keyed by ISO code. */
|
|
13
|
+
static getCountries(language = 'en') {
|
|
14
|
+
const arr = getCountries(language);
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const c of arr) {
|
|
17
|
+
result[c.code] = { iso: c.code, iso3: c.iso3 ?? '', numeric: c.numeric ?? 0, name: c.name };
|
|
18
|
+
}
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
/** Get all countries as a sorted array of { value, label } for select inputs. */
|
|
22
|
+
static getCountryOptions(language = 'en') {
|
|
23
|
+
return getCountries(language).map((c) => ({ value: c.code, label: c.name }));
|
|
24
|
+
}
|
|
25
|
+
/** Get regions/states for a country. */
|
|
26
|
+
static getRegions(countryCode, language = 'en') {
|
|
27
|
+
return getStatesForCountry(countryCode, language).map((s) => ({ iso: s.code, name: s.name }));
|
|
28
|
+
}
|
|
29
|
+
/** Get regions as a sorted array of { value, label } for select inputs. */
|
|
30
|
+
static getRegionOptions(countryCode, language = 'en') {
|
|
31
|
+
return ISODataCore.getRegions(countryCode, language).map((r) => ({ value: r.iso, label: r.name }));
|
|
32
|
+
}
|
|
33
|
+
/** Find a specific region by ISO code. */
|
|
34
|
+
static findRegion(countryCode, regionCode, language = 'en') {
|
|
35
|
+
return ISODataCore.getRegions(countryCode, language).find((r) => r.iso === regionCode) ?? null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Map a Google Places administrative_area to an ISO region.
|
|
39
|
+
* Tries exact ISO match, then name match, then partial match.
|
|
40
|
+
*/
|
|
41
|
+
static mapGoogleToISO(googleState, googleStateLong, countryCode, language = 'en') {
|
|
42
|
+
const regions = ISODataCore.getRegions(countryCode, language);
|
|
43
|
+
if (regions.length === 0)
|
|
44
|
+
return null;
|
|
45
|
+
let match = regions.find((r) => r.iso === googleState);
|
|
46
|
+
if (match)
|
|
47
|
+
return match;
|
|
48
|
+
match = regions.find((r) => r.name.toLowerCase() === googleState.toLowerCase());
|
|
49
|
+
if (match)
|
|
50
|
+
return match;
|
|
51
|
+
match = regions.find((r) => r.name.toLowerCase() === googleStateLong.toLowerCase());
|
|
52
|
+
if (match)
|
|
53
|
+
return match;
|
|
54
|
+
match = regions.find((r) => r.name.toLowerCase().includes(googleStateLong.toLowerCase()) ||
|
|
55
|
+
googleStateLong.toLowerCase().includes(r.name.toLowerCase()));
|
|
56
|
+
return match ?? null;
|
|
57
|
+
}
|
|
58
|
+
static isLanguageLoaded(language) {
|
|
59
|
+
return isLanguageLoaded(language);
|
|
60
|
+
}
|
|
61
|
+
static getAvailableLanguages() {
|
|
62
|
+
return AVAILABLE_LANGUAGES;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=countries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"countries.js","sourceRoot":"","sources":["../../../src/core/helpers/countries.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,mBAA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CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,eAAe,CAAC,WAAW,EAAE,CAAC,CAAC;QACpF,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;QAExB,KAAK,GAAG,OAAO,CAAC,IAAI,CAClB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;YAC5D,eAAe,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAC/D,CAAC;QAEF,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,QAA2B;QACjD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,MAAM,CAAC,qBAAqB;QAC1B,OAAO,mBAAmB,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency formatting utilities — symbol lookup, decimal handling,
|
|
3
|
+
* and Intl.NumberFormat-based money formatting from minor units (cents).
|
|
4
|
+
*/
|
|
5
|
+
export interface Currency {
|
|
6
|
+
code: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
name: string;
|
|
9
|
+
decimalPlaces: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class CurrencyUtils {
|
|
12
|
+
static getSymbol(code: string): string;
|
|
13
|
+
static getName(code: string): string;
|
|
14
|
+
static getDecimalPlaces(code: string): number;
|
|
15
|
+
static getCurrency(code: string): Currency;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Format an amount expressed in minor units (cents) into a locale-aware string.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* formatMoney(12345, 'USD') // "$123.45"
|
|
22
|
+
* formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
|
|
23
|
+
* formatMoney(1000, 'JPY') // "¥1,000"
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatMoney(amountMinorUnits: number, currencyCode?: string, locale?: string): string;
|
|
26
|
+
//# sourceMappingURL=currency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"currency.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/currency.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;CACvB;AA8BD,qBAAa,aAAa;IACxB,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAItC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIpC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI7C,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ;CAQ3C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,EAAE,MAAM,EAAE,YAAY,SAAQ,EAAE,MAAM,SAAU,GAAG,MAAM,CAcpG"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency formatting utilities — symbol lookup, decimal handling,
|
|
3
|
+
* and Intl.NumberFormat-based money formatting from minor units (cents).
|
|
4
|
+
*/
|
|
5
|
+
const SYMBOLS = {
|
|
6
|
+
USD: '$', EUR: '€', GBP: '£', JPY: '¥', CAD: 'C$', AUD: 'A$', CHF: 'CHF',
|
|
7
|
+
CNY: '¥', SEK: 'kr', NOK: 'kr', DKK: 'kr', PLN: 'zł', CZK: 'Kč', HUF: 'Ft',
|
|
8
|
+
RON: 'lei', BGN: 'лв', HRK: 'kn', RUB: '₽', UAH: '₴', TRY: '₺', BRL: 'R$',
|
|
9
|
+
MXN: '$', ZAR: 'R', INR: '₹', KRW: '₩', THB: '฿', VND: '₫', IDR: 'Rp',
|
|
10
|
+
MYR: 'RM', SGD: 'S$', PHP: '₱', TWD: 'NT$', HKD: 'HK$', ILS: '₪', AED: 'د.إ',
|
|
11
|
+
SAR: 'ر.س', QAR: 'ر.ق', KWD: 'د.ك', BHD: 'د.ب', OMR: 'ر.ع.', EGP: '£',
|
|
12
|
+
NGN: '₦', KES: 'KSh', GHS: '₵', COP: '$', ARS: '$', CLP: '$', PEN: 'S/',
|
|
13
|
+
CRC: '₡', DOP: 'RD$', JMD: 'J$', BOB: 'Bs', PYG: '₲', GTQ: 'Q',
|
|
14
|
+
NIO: 'C$', PAB: 'B/.', PKR: '₨', BDT: '৳', LKR: '₨', NPR: '₨',
|
|
15
|
+
GEL: '₾', AMD: '֏', AZN: '₼', KZT: '₸',
|
|
16
|
+
};
|
|
17
|
+
const NAMES = {
|
|
18
|
+
USD: 'US Dollar', EUR: 'Euro', GBP: 'British Pound', JPY: 'Japanese Yen',
|
|
19
|
+
CAD: 'Canadian Dollar', AUD: 'Australian Dollar', CHF: 'Swiss Franc',
|
|
20
|
+
CNY: 'Chinese Yuan', SEK: 'Swedish Krona', NOK: 'Norwegian Krone',
|
|
21
|
+
DKK: 'Danish Krone', PLN: 'Polish Zloty', CZK: 'Czech Koruna', HUF: 'Hungarian Forint',
|
|
22
|
+
BRL: 'Brazilian Real', MXN: 'Mexican Peso', INR: 'Indian Rupee', KRW: 'South Korean Won',
|
|
23
|
+
THB: 'Thai Baht', SGD: 'Singapore Dollar', HKD: 'Hong Kong Dollar', TWD: 'Taiwan Dollar',
|
|
24
|
+
ILS: 'Israeli Shekel', AED: 'UAE Dirham', SAR: 'Saudi Riyal', ZAR: 'South African Rand',
|
|
25
|
+
TRY: 'Turkish Lira', RUB: 'Russian Ruble', NGN: 'Nigerian Naira',
|
|
26
|
+
};
|
|
27
|
+
const ZERO_DECIMAL = new Set([
|
|
28
|
+
'JPY', 'KRW', 'VND', 'IDR', 'LAK', 'KHR', 'MMK', 'PYG',
|
|
29
|
+
]);
|
|
30
|
+
export class CurrencyUtils {
|
|
31
|
+
static getSymbol(code) {
|
|
32
|
+
return SYMBOLS[code] ?? code;
|
|
33
|
+
}
|
|
34
|
+
static getName(code) {
|
|
35
|
+
return NAMES[code] ?? code;
|
|
36
|
+
}
|
|
37
|
+
static getDecimalPlaces(code) {
|
|
38
|
+
return ZERO_DECIMAL.has(code) ? 0 : 2;
|
|
39
|
+
}
|
|
40
|
+
static getCurrency(code) {
|
|
41
|
+
return {
|
|
42
|
+
code,
|
|
43
|
+
symbol: CurrencyUtils.getSymbol(code),
|
|
44
|
+
name: CurrencyUtils.getName(code),
|
|
45
|
+
decimalPlaces: CurrencyUtils.getDecimalPlaces(code),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Format an amount expressed in minor units (cents) into a locale-aware string.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* formatMoney(12345, 'USD') // "$123.45"
|
|
54
|
+
* formatMoney(10000, 'EUR', 'de-DE') // "100,00 €"
|
|
55
|
+
* formatMoney(1000, 'JPY') // "¥1,000"
|
|
56
|
+
*/
|
|
57
|
+
export function formatMoney(amountMinorUnits, currencyCode = 'USD', locale = 'en-US') {
|
|
58
|
+
const decimals = CurrencyUtils.getDecimalPlaces(currencyCode);
|
|
59
|
+
const value = amountMinorUnits / (decimals === 0 ? 100 : Math.pow(10, decimals));
|
|
60
|
+
try {
|
|
61
|
+
return new Intl.NumberFormat(locale, {
|
|
62
|
+
style: 'currency',
|
|
63
|
+
currency: currencyCode,
|
|
64
|
+
minimumFractionDigits: decimals,
|
|
65
|
+
maximumFractionDigits: decimals,
|
|
66
|
+
}).format(value);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return `${CurrencyUtils.getSymbol(currencyCode)}${value.toFixed(decimals)}`;
|
|
70
|
+
}
|
|
71
|
+
}
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,EAAE;YACnC,KAAK,EAAE,UAAU;YACjB,QAAQ,EAAE,YAAY;YACtB,qBAAqB,EAAE,QAAQ;YAC/B,qBAAqB,EAAE,QAAQ;SAChC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,aAAa,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GoogleAutocompleteCore, loadGoogleMapsScript, type GooglePrediction, type GooglePlaceDetails, type ExtractedAddress, type FormattedAddress, } from './autocomplete.js';
|
|
2
|
+
export { ISODataCore, AVAILABLE_LANGUAGES, type SupportedLanguage, type ISOCountry, type ISORegion, type Country, type State, } from './countries.js';
|
|
3
|
+
export { CurrencyUtils, formatMoney, type Currency, } from './currency.js';
|
|
4
|
+
export { ensureGeoDataLoaded, getCountries, getStatesForCountry, isLanguageLoaded, } from './iso3166.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,mBAAmB,EACnB,KAAK,iBAAiB,EACtB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,KAAK,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,WAAW,EACX,KAAK,QAAQ,GACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GoogleAutocompleteCore, loadGoogleMapsScript, } from './autocomplete.js';
|
|
2
|
+
export { ISODataCore, AVAILABLE_LANGUAGES, } from './countries.js';
|
|
3
|
+
export { CurrencyUtils, formatMoney, } from './currency.js';
|
|
4
|
+
export { ensureGeoDataLoaded, getCountries, getStatesForCountry, isLanguageLoaded, } from './iso3166.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,oBAAoB,GAKrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,WAAW,EACX,mBAAmB,GAMpB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,aAAa,EACb,WAAW,GAEZ,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,cAAc,CAAC"}
|