bitwarden-estensione-browser/src/models/view/cardView.ts

73 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-01-24 17:33:15 +01:00
import { View } from './view';
import { Card } from '../domain/card';
2018-01-24 17:33:15 +01:00
export class CardView implements View {
cardholderName: string;
2018-01-25 22:16:02 +01:00
expMonth: string = null;
2018-01-24 17:33:15 +01:00
expYear: string;
code: string;
2018-01-24 22:58:34 +01:00
// tslint:disable
2018-01-25 22:16:02 +01:00
private _brand: string = null;
2018-01-24 22:58:34 +01:00
private _number: string;
private _subTitle: string;
// tslint:enable
2018-01-24 17:33:15 +01:00
constructor(c?: Card) {
// ctor
}
2018-01-24 22:58:34 +01:00
get maskedCode(): string {
return this.code != null ? '•'.repeat(this.code.length) : null;
}
2018-01-24 22:58:34 +01:00
get brand(): string {
return this._brand;
}
set brand(value: string) {
this._brand = value;
this._subTitle = null;
}
get number(): string {
return this._number;
}
set number(value: string) {
this._number = value;
this._subTitle = null;
}
get subTitle(): string {
if (this._subTitle == null) {
this._subTitle = this.brand;
if (this.number != null && this.number.length >= 4) {
if (this._subTitle != null && this._subTitle !== '') {
this._subTitle += ', ';
} else {
this._subTitle = '';
}
2019-01-05 20:19:21 +01:00
// Show last 5 on amex, last 4 for all others
const count = this.number.length >= 5 && this.number.match(new RegExp('^3[47]')) != null ? 5 : 4;
this._subTitle += ('*' + this.number.substr(this.number.length - count));
2018-01-24 22:58:34 +01:00
}
}
return this._subTitle;
}
2018-01-25 20:26:09 +01:00
get expiration(): string {
if (!this.expMonth && !this.expYear) {
return null;
}
let exp = this.expMonth != null ? ('0' + this.expMonth).slice(-2) : '__';
exp += (' / ' + (this.expYear != null ? this.formatYear(this.expYear) : '____'));
return exp;
}
private formatYear(year: string): string {
return year.length === 2 ? '20' + year : year;
}
2018-01-24 17:33:15 +01:00
}