Skip to content

Commit

Permalink
fix(mobile-barcode): rename isEInvoiceCellPhoneBarcode to align with …
Browse files Browse the repository at this point in the history
…official government terminology
  • Loading branch information
enylin committed May 26, 2024
1 parent 4d52b36 commit 76fc142
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 50 deletions.
26 changes: 0 additions & 26 deletions src/e-invoice-cell-phone-barcode.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/e-invoice-cell-phone-barcode.ts

This file was deleted.

24 changes: 24 additions & 0 deletions src/e-invoice-mobile-barcode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { isMobileBarcode } from './e-invoice-mobile-barcode'

describe('isMobileBarcode', () => {
it('should only accept strings with length 8', () => {
expect(isMobileBarcode({} as string)).toBe(false)
expect(isMobileBarcode(3030101 as unknown as string)).toBe(false)
expect(isMobileBarcode(undefined as unknown as string)).toBe(false)
expect(isMobileBarcode('/ABCD1234')).toBe(false)
expect(isMobileBarcode('/ABCD12')).toBe(false)
})

it('should return false if the input contains invalid char', () => {
expect(isMobileBarcode('/ABCD12;')).toBe(false)
expect(isMobileBarcode('/ABCD$12')).toBe(false)
expect(isMobileBarcode('/ab12345')).toBe(false)
})

it('should return true if the input is correct', () => {
expect(isMobileBarcode('/+.-++..')).toBe(true)
expect(isMobileBarcode('/AAA33AA')).toBe(true)
expect(isMobileBarcode('/P4SV.-I')).toBe(true)
expect(isMobileBarcode('/O0O01I1')).toBe(true)
})
})
23 changes: 23 additions & 0 deletions src/e-invoice-mobile-barcode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Verify the input is a valid E-Invoice Mobile Barcode (電子發票手機條碼)
*
* @param { string } input - E-Invoice Mobile Barcode
* @returns { boolean } is `input` a valid E-Invoice Mobile Barcode
* @example
* isMobileBarcode('/+.-++..') // true
* isMobileBarcode('/12345678') // false
*/
export function isMobileBarcode(input: string): boolean {
if (typeof input !== 'string') return false

const n = input.toString()

/**
* 總長度為 8 碼
* 第 1 碼為 /
* 第 2-8 碼由 0-9 (數字), A-Z (大寫英文字母), .(period), -(hyphen), +(plus) 組成
*/
const regex = /^\/[\dA-Z.\-+]{7}$/

return regex.test(n)
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { isCdcNumber } from './citizen-digital-certificate-number'
export { isEInvoiceCellPhoneBarcode } from './e-invoice-cell-phone-barcode'
export { isMobileBarcode } from './e-invoice-mobile-barcode'
export { isEInvoiceDonateCode } from './e-invoice-donate-code'
export { isBan } from './business-administration-number'
export { isIdCardNumber, IdCardValidatingOptions } from './id-card-number'

0 comments on commit 76fc142

Please sign in to comment.