Skip to content

Commit

Permalink
better missing object handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed May 14, 2024
1 parent b70d450 commit e98cdaa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
14 changes: 7 additions & 7 deletions public/javascripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ const pts = {
});
};
pts.getLicencePlateCountryProperties = (originalLicencePlateCountry) => {
var _a;
var _a, _b, _c;
if (!defaultConfigPropertiesIsLoaded) {
return {};
}
const licencePlateCountryAlias = (_a = defaultConfigProperties.licencePlateCountryAliases[originalLicencePlateCountry.toUpperCase()]) !== null && _a !== void 0 ? _a : originalLicencePlateCountry;
const licencePlateCountryAlias = (_b = (_a = defaultConfigProperties.licencePlateCountryAliases) === null || _a === void 0 ? void 0 : _a[originalLicencePlateCountry.toUpperCase()]) !== null && _b !== void 0 ? _b : originalLicencePlateCountry;
if (Object.prototype.hasOwnProperty.call(defaultConfigProperties.licencePlateProvinces, licencePlateCountryAlias)) {
return defaultConfigProperties.licencePlateProvinces[licencePlateCountryAlias];
return (_c = defaultConfigProperties.licencePlateProvinces) === null || _c === void 0 ? void 0 : _c[licencePlateCountryAlias];
}
return {};
};
pts.getLicencePlateLocationProperties = (originalLicencePlateCountry, originalLicencePlateProvince) => {
var _a, _b, _c, _d, _e;
const licencePlateProvinceDefault = {
provinceShortName: originalLicencePlateProvince,
color: '#000',
Expand All @@ -81,19 +82,18 @@ const pts = {
licencePlateProvince: licencePlateProvinceDefault
};
}
const licencePlateCountryAlias = defaultConfigProperties.licencePlateCountryAliases[originalLicencePlateCountry.toUpperCase()] || originalLicencePlateCountry;
const licencePlateCountryAlias = (_b = (_a = defaultConfigProperties.licencePlateCountryAliases) === null || _a === void 0 ? void 0 : _a[originalLicencePlateCountry.toUpperCase()]) !== null && _b !== void 0 ? _b : originalLicencePlateCountry;
let licencePlateProvinceAlias = originalLicencePlateProvince;
if (Object.prototype.hasOwnProperty.call(defaultConfigProperties.licencePlateProvinceAliases, licencePlateCountryAlias)) {
const provinceAliases = defaultConfigProperties.licencePlateProvinceAliases[licencePlateCountryAlias];
const provinceAliases = (_d = (_c = defaultConfigProperties.licencePlateProvinceAliases) === null || _c === void 0 ? void 0 : _c[licencePlateCountryAlias]) !== null && _d !== void 0 ? _d : {};
licencePlateProvinceAlias =
provinceAliases[originalLicencePlateProvince.toUpperCase()] ||
originalLicencePlateProvince;
}
let licencePlateProvince = licencePlateProvinceDefault;
if (Object.prototype.hasOwnProperty.call(defaultConfigProperties.licencePlateProvinces, licencePlateCountryAlias)) {
licencePlateProvince =
defaultConfigProperties.licencePlateProvinces[licencePlateCountryAlias]
.provinces[licencePlateProvinceAlias] || licencePlateProvinceDefault;
((_e = defaultConfigProperties.licencePlateProvinces) === null || _e === void 0 ? void 0 : _e[licencePlateCountryAlias].provinces[licencePlateProvinceAlias]) || licencePlateProvinceDefault;
}
return {
licencePlateCountryAlias,
Expand Down
14 changes: 6 additions & 8 deletions public/javascripts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ interface DefaultConfigProperties {
}

const licencePlateCountryAlias =
defaultConfigProperties.licencePlateCountryAliases[
defaultConfigProperties.licencePlateCountryAliases?.[
originalLicencePlateCountry.toUpperCase()
] ?? originalLicencePlateCountry

Expand All @@ -125,7 +125,7 @@ interface DefaultConfigProperties {
licencePlateCountryAlias
)
) {
return defaultConfigProperties.licencePlateProvinces[
return defaultConfigProperties.licencePlateProvinces?.[
licencePlateCountryAlias
]
}
Expand Down Expand Up @@ -154,9 +154,9 @@ interface DefaultConfigProperties {
// Get the country alias

const licencePlateCountryAlias =
defaultConfigProperties.licencePlateCountryAliases[
defaultConfigProperties.licencePlateCountryAliases?.[
originalLicencePlateCountry.toUpperCase()
] || originalLicencePlateCountry
] ?? originalLicencePlateCountry

// Get the province alias

Expand All @@ -169,9 +169,7 @@ interface DefaultConfigProperties {
)
) {
const provinceAliases =
defaultConfigProperties.licencePlateProvinceAliases[
licencePlateCountryAlias
]
defaultConfigProperties.licencePlateProvinceAliases?.[licencePlateCountryAlias] ?? {}

licencePlateProvinceAlias =
provinceAliases[originalLicencePlateProvince.toUpperCase()] ||
Expand All @@ -189,7 +187,7 @@ interface DefaultConfigProperties {
)
) {
licencePlateProvince =
defaultConfigProperties.licencePlateProvinces[licencePlateCountryAlias]
defaultConfigProperties.licencePlateProvinces?.[licencePlateCountryAlias]
.provinces[licencePlateProvinceAlias] || licencePlateProvinceDefault
}

Expand Down

0 comments on commit e98cdaa

Please sign in to comment.