aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-07-06 06:36:16 +0200
committerLibravatarLarge Libravatar memdmp <memdmpestrogenzone>2025-07-06 06:36:16 +0200
commit97ee2523d145ed3b9b7e1bf5ec93f3e14e7da059 (patch)
treee0aa5901eee1cba96531da222eb3a11dcee973b8
parentbc698228440e2c7558cb46238368e2f0fafb154c (diff)
downloaduic-parse-97ee2523d145ed3b9b7e1bf5ec93f3e14e7da059.tar.gz
uic-parse-97ee2523d145ed3b9b7e1bf5ec93f3e14e7da059.tar.bz2
uic-parse-97ee2523d145ed3b9b7e1bf5ec93f3e14e7da059.tar.lz
uic-parse-97ee2523d145ed3b9b7e1bf5ec93f3e14e7da059.zip

fix: selfCheckDigit should probably be a function to match the other get functions

maybe someone should restructure this later

either way i'm providing no api guarantees for now just copy the code into your project if you care about that

-rw-r--r--lib.ts8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib.ts b/lib.ts
index 12fe6b2..4bbd4c3 100644
--- a/lib.ts
+++ b/lib.ts
@@ -125,14 +125,14 @@ export default class UICVehicle<Operator extends string | null, Country extends
public getSerialNumber(): `${Digit}${Digit}${Digit}` {
return this.serialNumber
}
- public get selfCheckDigit(): Digit {
+ public getSelfCheckDigit(): Digit {
return UICVehicle.getSelfCheckDigit(this.vehicleType + (this.country?.uicIdentifier ?? this.countryCode) + this.vehicleFamily + this.serialNumber).toString() as Digit
}
public toString() {
// Separation of first character of vehicleFamily is typically done in Switzerland for SBB and BLS (although not Thurbo?) - and not in germany, unsure about elsewhere
const cc = this.country?.uicIdentifier ?? this.countryCode;
const ccstr = (this.country?.treatyShort ?? UICCountry.countryMaps.byUICIdentificationNumber.get(this.countryCode!)?.treatyShort ?? null)
- return `${this.vehicleType} ${cc} ${cc === '85' ? `${this.vehicleFamily.charAt(1) + ' ' + this.vehicleFamily.substring(1)}` : this.vehicleFamily} ${this.serialNumber} ${this.selfCheckDigit}${ccstr && this.operator ? ` ${ccstr}-${this.operator}` : ''}`
+ return `${this.vehicleType} ${cc} ${cc === '85' ? `${this.vehicleFamily.charAt(1) + ' ' + this.vehicleFamily.substring(1)}` : this.vehicleFamily} ${this.serialNumber} ${this.getSelfCheckDigit()}${ccstr && this.operator ? ` ${ccstr}-${this.operator}` : ''}`
}
public toJSON() {
return {
@@ -141,7 +141,7 @@ export default class UICVehicle<Operator extends string | null, Country extends
vehicleFamily: this.vehicleFamily,
serialNumber: this.serialNumber,
countryCode: this.country?.uicIdentifier ?? this.countryCode,
- checkDigit: this.selfCheckDigit,
+ checkDigit: this.getSelfCheckDigit(),
country: this.country
}
}
@@ -220,7 +220,7 @@ export default class UICVehicle<Operator extends string | null, Country extends
delete this.countryCode
// Finally, verify we didn't go insane
- if (this.selfCheckDigit !== selfCheckDigit.toString())
+ if (this.getSelfCheckDigit() !== selfCheckDigit.toString())
throw new Error('Self Check Digit Mismatch!')
}
public static fromJSON<Operator extends string | null>(json: {