@guardian/commercial-core 34.0.0 → 34.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/geo/geo-utils.js +7 -13
- package/dist/cjs/geo/get-locale.js +0 -1
- package/dist/esm/geo/geo-utils.js +7 -13
- package/dist/esm/geo/get-locale.js +0 -1
- package/package.json +1 -1
- package/dist/cjs/geo/country-code.d.ts +0 -3
- package/dist/cjs/geo/country-code.js +0 -32
- package/dist/esm/geo/country-code.d.ts +0 -3
- package/dist/esm/geo/country-code.js +0 -29
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports._ = exports.isInRow = exports.isInAuOrNz = exports.isInUsOrCa = exports.isInNewZealand = exports.isInAustralia = exports.isInCanada = exports.isInUsa = exports.isInUk = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
let geo;
|
|
7
|
-
const currentGeoLocation = () => {
|
|
8
|
-
geo = geo ?? (0, country_code_1.getCountryCode)();
|
|
9
|
-
return geo;
|
|
10
|
-
};
|
|
11
|
-
const isInUk = () => currentGeoLocation() === 'GB';
|
|
4
|
+
const get_locale_1 = require("./get-locale.js");
|
|
5
|
+
const isInUk = () => (0, get_locale_1.getLocale)() === 'GB';
|
|
12
6
|
exports.isInUk = isInUk;
|
|
13
|
-
const isInUsa = () =>
|
|
7
|
+
const isInUsa = () => (0, get_locale_1.getLocale)() === 'US';
|
|
14
8
|
exports.isInUsa = isInUsa;
|
|
15
|
-
const isInCanada = () =>
|
|
9
|
+
const isInCanada = () => (0, get_locale_1.getLocale)() === 'CA';
|
|
16
10
|
exports.isInCanada = isInCanada;
|
|
17
|
-
const isInAustralia = () =>
|
|
11
|
+
const isInAustralia = () => (0, get_locale_1.getLocale)() === 'AU';
|
|
18
12
|
exports.isInAustralia = isInAustralia;
|
|
19
|
-
const isInNewZealand = () =>
|
|
13
|
+
const isInNewZealand = () => (0, get_locale_1.getLocale)() === 'NZ';
|
|
20
14
|
exports.isInNewZealand = isInNewZealand;
|
|
21
15
|
const isInUsOrCa = () => (0, exports.isInUsa)() || (0, exports.isInCanada)();
|
|
22
16
|
exports.isInUsOrCa = isInUsOrCa;
|
|
@@ -26,6 +20,6 @@ const isInRow = () => !(0, exports.isInUk)() && !(0, exports.isInUsOrCa)() && !(
|
|
|
26
20
|
exports.isInRow = isInRow;
|
|
27
21
|
exports._ = {
|
|
28
22
|
resetModule: () => {
|
|
29
|
-
|
|
23
|
+
(0, get_locale_1.__resetCachedValue)();
|
|
30
24
|
},
|
|
31
25
|
};
|
|
@@ -15,7 +15,6 @@ const editionToGeolocationMap = {
|
|
|
15
15
|
AU: 'AU',
|
|
16
16
|
};
|
|
17
17
|
const editionToGeolocation = (editionKey) => editionToGeolocationMap[editionKey];
|
|
18
|
-
// just used for tests
|
|
19
18
|
const __resetCachedValue = () => (locale = undefined);
|
|
20
19
|
exports.__resetCachedValue = __resetCachedValue;
|
|
21
20
|
/**
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export const isInUk = () => currentGeoLocation() === 'GB';
|
|
9
|
-
export const isInUsa = () => currentGeoLocation() === 'US';
|
|
10
|
-
export const isInCanada = () => currentGeoLocation() === 'CA';
|
|
11
|
-
export const isInAustralia = () => currentGeoLocation() === 'AU';
|
|
12
|
-
export const isInNewZealand = () => currentGeoLocation() === 'NZ';
|
|
1
|
+
import { __resetCachedValue, getLocale } from './get-locale.js';
|
|
2
|
+
export const isInUk = () => getLocale() === 'GB';
|
|
3
|
+
export const isInUsa = () => getLocale() === 'US';
|
|
4
|
+
export const isInCanada = () => getLocale() === 'CA';
|
|
5
|
+
export const isInAustralia = () => getLocale() === 'AU';
|
|
6
|
+
export const isInNewZealand = () => getLocale() === 'NZ';
|
|
13
7
|
export const isInUsOrCa = () => isInUsa() || isInCanada();
|
|
14
8
|
export const isInAuOrNz = () => isInAustralia() || isInNewZealand();
|
|
15
9
|
export const isInRow = () => !isInUk() && !isInUsOrCa() && !isInAuOrNz();
|
|
16
10
|
export const _ = {
|
|
17
11
|
resetModule: () => {
|
|
18
|
-
|
|
12
|
+
__resetCachedValue();
|
|
19
13
|
},
|
|
20
14
|
};
|
|
@@ -12,7 +12,6 @@ const editionToGeolocationMap = {
|
|
|
12
12
|
AU: 'AU',
|
|
13
13
|
};
|
|
14
14
|
const editionToGeolocation = (editionKey) => editionToGeolocationMap[editionKey];
|
|
15
|
-
// just used for tests
|
|
16
15
|
export const __resetCachedValue = () => (locale = undefined);
|
|
17
16
|
/**
|
|
18
17
|
* Fetches the user's current location as an ISO 3166-1 alpha-2 string e.g. 'GB', 'AU' etc
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCountryCode = void 0;
|
|
4
|
-
const libs_1 = require("@guardian/libs");
|
|
5
|
-
const editionToCountryCodeMap = {
|
|
6
|
-
UK: 'GB',
|
|
7
|
-
US: 'US',
|
|
8
|
-
AU: 'AU',
|
|
9
|
-
};
|
|
10
|
-
const editionToCountryCode = (editionKey = 'UK') => editionToCountryCodeMap[editionKey];
|
|
11
|
-
const countryCookieName = 'GU_geo_country';
|
|
12
|
-
const countryOverrideName = 'gu.geo.override';
|
|
13
|
-
/*
|
|
14
|
-
This method can be used as a non async way of getting the country code
|
|
15
|
-
after init has been called. Returning locale should cover all/most
|
|
16
|
-
of the cases but if a race condition happen or the cookie is not set,
|
|
17
|
-
we keep fallbacks to cookie or geo from edition.
|
|
18
|
-
*/
|
|
19
|
-
const getCountryCode = () => {
|
|
20
|
-
const pageEdition = window.guardian.config.page.edition;
|
|
21
|
-
const maybeCountryOverride = libs_1.storage.local.get(countryOverrideName);
|
|
22
|
-
const countryOverride = (0, libs_1.isString)(maybeCountryOverride)
|
|
23
|
-
? maybeCountryOverride
|
|
24
|
-
: null;
|
|
25
|
-
return (countryOverride ??
|
|
26
|
-
(0, libs_1.getCookie)({
|
|
27
|
-
name: countryCookieName,
|
|
28
|
-
shouldMemoize: true,
|
|
29
|
-
}) ??
|
|
30
|
-
editionToCountryCode(pageEdition));
|
|
31
|
-
};
|
|
32
|
-
exports.getCountryCode = getCountryCode;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getCookie, isString, storage } from '@guardian/libs';
|
|
2
|
-
const editionToCountryCodeMap = {
|
|
3
|
-
UK: 'GB',
|
|
4
|
-
US: 'US',
|
|
5
|
-
AU: 'AU',
|
|
6
|
-
};
|
|
7
|
-
const editionToCountryCode = (editionKey = 'UK') => editionToCountryCodeMap[editionKey];
|
|
8
|
-
const countryCookieName = 'GU_geo_country';
|
|
9
|
-
const countryOverrideName = 'gu.geo.override';
|
|
10
|
-
/*
|
|
11
|
-
This method can be used as a non async way of getting the country code
|
|
12
|
-
after init has been called. Returning locale should cover all/most
|
|
13
|
-
of the cases but if a race condition happen or the cookie is not set,
|
|
14
|
-
we keep fallbacks to cookie or geo from edition.
|
|
15
|
-
*/
|
|
16
|
-
const getCountryCode = () => {
|
|
17
|
-
const pageEdition = window.guardian.config.page.edition;
|
|
18
|
-
const maybeCountryOverride = storage.local.get(countryOverrideName);
|
|
19
|
-
const countryOverride = isString(maybeCountryOverride)
|
|
20
|
-
? maybeCountryOverride
|
|
21
|
-
: null;
|
|
22
|
-
return (countryOverride ??
|
|
23
|
-
getCookie({
|
|
24
|
-
name: countryCookieName,
|
|
25
|
-
shouldMemoize: true,
|
|
26
|
-
}) ??
|
|
27
|
-
editionToCountryCode(pageEdition));
|
|
28
|
-
};
|
|
29
|
-
export { getCountryCode };
|