-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mobile-barcode): rename isEInvoiceCellPhoneBarcode to align with …
…official government terminology
- Loading branch information
Showing
5 changed files
with
48 additions
and
50 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |