Skip to content

Commit

Permalink
fix(donate-code): rename isEInvoiceDonateCode to isDonateCode to simp…
Browse files Browse the repository at this point in the history
…lify API call
  • Loading branch information
enylin committed May 26, 2024
1 parent 76fc142 commit 49c6fb3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
28 changes: 14 additions & 14 deletions src/e-invoice-donate-code.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { isEInvoiceDonateCode } from './e-invoice-donate-code'
import { isDonateCode } from './e-invoice-donate-code'

describe('isEInvoiceDonateCode', () => {
describe('isDonateCode', () => {
it('should only accept strings with length 3-7', () => {
expect(isEInvoiceDonateCode({} as string)).toBe(false)
expect(isEInvoiceDonateCode(undefined as unknown as string)).toBe(false)
expect(isEInvoiceDonateCode('00')).toBe(false)
expect(isEInvoiceDonateCode('12345678')).toBe(false)
expect(isEInvoiceDonateCode(12345678)).toBe(false)
expect(isEInvoiceDonateCode('ab3456')).toBe(false)
expect(isDonateCode({} as string)).toBe(false)
expect(isDonateCode(undefined as unknown as string)).toBe(false)
expect(isDonateCode('00')).toBe(false)
expect(isDonateCode('12345678')).toBe(false)
expect(isDonateCode(12345678)).toBe(false)
expect(isDonateCode('ab3456')).toBe(false)
})

it('should return false if the input is incorrect', () => {
expect(isEInvoiceDonateCode('001')).toBe(true)
expect(isEInvoiceDonateCode('10001')).toBe(true)
expect(isEInvoiceDonateCode('2134567')).toBe(true)
expect(isEInvoiceDonateCode(123)).toBe(true)
expect(isEInvoiceDonateCode(10001)).toBe(true)
expect(isEInvoiceDonateCode(2134567)).toBe(true)
expect(isDonateCode('001')).toBe(true)
expect(isDonateCode('10001')).toBe(true)
expect(isDonateCode('2134567')).toBe(true)
expect(isDonateCode(123)).toBe(true)
expect(isDonateCode(10001)).toBe(true)
expect(isDonateCode(2134567)).toBe(true)
})
})
12 changes: 6 additions & 6 deletions src/e-invoice-donate-code.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* Verify the input is a valid E-Invoice donate code (電子發票捐贈碼)
* Verify the input is a valid E-Invoice Donate Code (電子發票捐贈碼)
*
* @param { string | number } input - E-Invoice donate code
* @returns { boolean } is `input` a valid e-invoice donate code
* @param { string | number } input - E-Invoice Donate Code
* @returns { boolean } is `input` a valid E-Invoice Donate Code
* @example
* isEInvoiceDonateCode('123') // true
* isEInvoiceDonateCode('abc123') // false
* isDonateCode('123') // true
* isDonateCode('abc123') // false
*/
export function isEInvoiceDonateCode(input: string | number): boolean {
export function isDonateCode(input: string | number): boolean {
if (typeof input !== 'string' && typeof input !== 'number') return false

const n = input.toString()
Expand Down
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 { isMobileBarcode } from './e-invoice-mobile-barcode'
export { isEInvoiceDonateCode } from './e-invoice-donate-code'
export { isDonateCode } from './e-invoice-donate-code'
export { isBan } from './business-administration-number'
export { isIdCardNumber, IdCardValidatingOptions } from './id-card-number'

0 comments on commit 49c6fb3

Please sign in to comment.