@stacksjs/qrx
Version:
QR & Bar Code generating & reading. Lightweight & powerful.
65 lines (53 loc) • 1.38 kB
TypeScript
declare function checksum(number: string): void;
export declare class EAN13 extends EAN {
lastChar: string
constructor(data: string, options: any) {
if (data.search(/^\d{12}$/) !== -1) {
data += checksum(data)
}
super(data, options)
this.lastChar = options.lastChar
}
valid(): boolean {
return (
this.data.search(/^\d{13}$/) !== -1
&& +this.data[12] === checksum(this.data)
)
}
leftText(): string {
return super.leftText(1, 6)
}
leftEncode(): string {
const data = this.data.substr(1, 6)
const structure = EAN13_STRUCTURE[Number(this.data[0])]
return super.leftEncode(data, structure)
}
rightText(): string {
return super.rightText(7, 6)
}
rightEncode(): string {
const data = this.data.substr(7, 6)
return super.rightEncode(data, 'RRRRRR')
}
encodeGuarded(): any {
const data = super.encodeGuarded()
if (this.options.displayValue) {
data.unshift({
data: '000000000000',
text: this.text.substr(0, 1),
options: { textAlign: 'left', fontSize: this.fontSize },
})
if (this.options.lastChar) {
data.push({
data: '00',
})
data.push({
data: '00000',
text: this.options.lastChar,
options: { fontSize: this.fontSize },
})
}
}
return data
}
}