Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
chore: wip
  • Loading branch information
chrisbbreuer committed Jan 7, 2025
1 parent e597e90 commit 37480de
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/qrx/src/bar/drivers/CODE128/CODE128A.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { A_CHARS, A_START_CHAR } from './constants'

class CODE128A extends CODE128 {
constructor(string: string, options: any) {
super(A_START_CHAR + string, options) // Use 'data' instead of 'string'
super(A_START_CHAR + string, options)
}

valid(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/qrx/src/bar/drivers/EAN_UPC/EAN13.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class EAN13 extends EAN {

leftEncode(): string {
const data = this.data.substr(1, 6)
const structure = EAN13_STRUCTURE[this.data[0]]
const structure = EAN13_STRUCTURE[Number(this.data[0])]
return super.leftEncode(data, structure)
}

Expand Down
22 changes: 11 additions & 11 deletions packages/qrx/src/bar/drivers/EAN_UPC/UPCE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const PARITIES = [

export class UPCE extends Barcode {
isValid: boolean
middleDigits: string
upcA: string
text: string
displayValue: boolean
fontSize: number
guardHeight: number
middleDigits!: string
upcA!: string
// text: string
displayValue!: boolean
fontSize!: number
guardHeight!: number

constructor(data: string, options: any) {
// Code may be 6 or 8 digits;
Expand All @@ -51,10 +51,10 @@ export class UPCE extends Barcode {
this.isValid = false
if (data.search(/^\d{6}$/) !== -1) {
this.middleDigits = data
this.upcA = expandToUPCA(data, '0')
this.text = options.text
|| `${this.upcA[0]}${data}${this.upcA[this.upcA.length - 1]}`
this.isValid = true
// this.! = expandToUPCA(data, '0')
// this.text = options.text
// || `${this!.![0]}${data}${this.upcA[this.upcA.length - 1]}`
// this.i!sValid = true
}
else if (data.search(/^[01]\d{7}$/) !== -1) {
this.middleDigits = data.substring(1, data.length - 1)
Expand Down Expand Up @@ -83,7 +83,7 @@ export class UPCE extends Barcode {
}

// Make the guard bars go down half the way of the text
this.guardHeight = options.height + this.fontSize / 2 + options.textMargin
this.guardHeight! = options.height + this.fontSize / 2 + options.textMargin
}

valid(): boolean {
Expand Down
6 changes: 3 additions & 3 deletions packages/qrx/src/bar/drivers/ITF/ITF.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ITF extends Barcode {
encode(): { text: string, data: string } {
// Calculate all the digit pairs
const encoded = this.data
.match(/.{2}/g)
.match(/.{2}/g) || []
.map(pair => this.encodePair(pair))
.join('')

Expand All @@ -21,9 +21,9 @@ class ITF extends Barcode {

// Calculate the data of a number pair
encodePair(pair: string): string {
const second = BINARIES[pair[1]]
const second = BINARIES[Number(pair[1])]

return BINARIES[pair[0]]
return BINARIES[Number(pair[0])]
.split('')
.map((first, idx) => (
(first === '1' ? '111' : '1')
Expand Down
6 changes: 4 additions & 2 deletions packages/qrx/src/bar/drivers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { ITF, ITF14 } from './ITF'
import { MSI, MSI10, MSI11, MSI1010, MSI1110 } from './MSI'
import { Pharmacode } from './Pharmacode'

type Barcode = typeof GenericBarcode
interface BarcodeMap {
[key: string]: typeof GenericBarcode
}

export const barcodes: Barcode[] = {
export const barcodes: BarcodeMap = {
CODE39,
CODE128,
CODE128A,
Expand Down
14 changes: 14 additions & 0 deletions packages/qrx/src/bar/renderers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@ import CanvasRenderer from './canvas'
import ObjectRenderer from './object'
import SVGRenderer from './svg'

interface Renderers {
CanvasRenderer: typeof CanvasRenderer
ObjectRenderer: typeof ObjectRenderer
SVGRenderer: typeof SVGRenderer
}

const renderers: Renderers = {
CanvasRenderer,
ObjectRenderer,
SVGRenderer,
}

export { CanvasRenderer, ObjectRenderer, SVGRenderer }

export default renderers
5 changes: 3 additions & 2 deletions packages/qrx/src/bar/utils/getOptionsFromElement.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { defaults } from '../../config'
import optionsFromStrings from './optionsFromStrings'

function getOptionsFromElement(element: HTMLElement): any {
let options = {}
export function getOptionsFromElement(element: HTMLElement): any {
let options: { [key: string]: any } = {}

for (const property in defaults) {
if (Object.prototype.hasOwnProperty.call(defaults, property)) {
// jsbarcode-*
Expand Down

0 comments on commit 37480de

Please sign in to comment.