diff options
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.ts | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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: { |