UNPKG

uview-next

Version:

基于uView UI 2.0,110+高质量组件库,支持vue2和vue3,支持鸿蒙,支持多语言,搭配便捷工具助力,让开发更得心应手

38 lines (30 loc) 703 B
import { START_BIN, END_BIN, BINARIES } from './constants'; import Barcode from '../Barcode'; class ITF extends Barcode { valid() { return this.data.search(/^([0-9]{2})+$/) !== -1; } encode() { // Calculate all the digit pairs const encoded = this.data .match(/.{2}/g) .map(pair => this.encodePair(pair)) .join(''); return { data: START_BIN + encoded + END_BIN, text: this.text }; } // Calculate the data of a number pair encodePair(pair) { const second = BINARIES[pair[1]]; return BINARIES[pair[0]] .split('') .map((first, idx) => ( (first === '1' ? '111' : '1') + (second[idx] === '1' ? '000' : '0') )) .join(''); } } export default ITF;