-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change to named export; Update JSDoc of modules; Fix ESLint errors
- Loading branch information
Showing
13 changed files
with
180 additions
and
181 deletions.
There are no files selected for viewing
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
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
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
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
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,23 +1,23 @@ | ||
import normalize from './utils/normalize.mjs'; | ||
import isChecksumValid from './utils/is-twid-checksum-valid.mjs'; | ||
import { normalize } from './utils/normalize.mjs'; | ||
import { isTWIDChecksumValid } from './utils/is-twid-checksum-valid.mjs'; | ||
|
||
/** | ||
Validate ID card number of Taiwan | ||
@module core/twid | ||
@param {string} id | ||
@return {boolean} | ||
Original name: National Identification Card of the Republic of China | ||
Format of card id: A123456789 | ||
There is another system called Taiwan Resident Certificate (Uniform ID Numbers) | ||
@see module:core/twrc | ||
*/ | ||
export default (function(id) { | ||
* Validate ID card number of Taiwan. | ||
* - Original name: National Identification Card of the Republic of China. | ||
* - Format: "A123456789". | ||
* | ||
* There is another system called Taiwan Resident Certificate (Uniform ID Numbers). | ||
* @see module:core/twrc | ||
* | ||
* @module core/twid | ||
* @param {string} id | ||
* @returns {boolean} | ||
*/ | ||
export function twid(id) { | ||
// isLengthValid = (id) -> id.length is 10 | ||
const isFormatValid = id => /^[A-Z][12][0-9]{8}$/.test(id); | ||
|
||
id = normalize(id); | ||
// return isLengthValid(id) and isFormatValid(id) and isChecksumValid(id, 1) | ||
return isFormatValid(id) && isChecksumValid(id, 1); | ||
}); | ||
// return isLengthValid(id) and isFormatValid(id) and isTWIDChecksumValid(id, 1) | ||
return isFormatValid(id) && isTWIDChecksumValid(id, 1); | ||
} |
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,23 +1,23 @@ | ||
import normalize from './utils/normalize.mjs'; | ||
import isChecksumValid from './utils/is-twid-checksum-valid.mjs'; | ||
import { normalize } from './utils/normalize.mjs'; | ||
import { isTWIDChecksumValid } from './utils/is-twid-checksum-valid.mjs'; | ||
|
||
/** | ||
Validate ID number of Taiwan Resident Certificate (Uniform ID Numbers). | ||
Only validate ID in or before 2020. | ||
@module core/twrc | ||
@param {string} id | ||
@return {boolean} | ||
Format of the id: AB12345678 | ||
In Taiwan, there is another system called National Identification Card | ||
@see module:core/twid-legacy | ||
*/ | ||
export default (function(id) { | ||
* Validate ID number of Taiwan Resident Certificate (Uniform ID Numbers). | ||
* Only validate ID in or before 2020. | ||
* Format of the id: "AB12345678" | ||
* | ||
* In Taiwan, there is another system called National Identification Card. | ||
* @see module:core/twid | ||
* | ||
* @module core/twrc-legacy | ||
* @param {string} id | ||
* @returns {boolean} | ||
*/ | ||
export function twrcLegacy(id) { | ||
// isLengthValid = (id) -> id.length is 10 | ||
const isFormatValid = id => /^[A-Z][A-D][0-9]{8}$/.test(id); | ||
|
||
id = normalize(id); | ||
// return isLengthValid(id) and isFormatValid(id) and isChecksumValid(id, 2) | ||
return isFormatValid(id) && isChecksumValid(id, 2); | ||
}); | ||
// return isLengthValid(id) && isFormatValid(id) && isTWIDChecksumValid(id, 2) | ||
return isFormatValid(id) && isTWIDChecksumValid(id, 2); | ||
} |
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,32 +1,33 @@ | ||
import normalize from './utils/normalize.mjs'; | ||
import getFormat from './utils/get-twrc-format.mjs'; | ||
import isChecksumValid from './utils/is-twid-checksum-valid.mjs'; | ||
import { normalize } from './utils/normalize.mjs'; | ||
import { getTWRCFormat } from './utils/get-twrc-format.mjs'; | ||
import { isTWIDChecksumValid } from './utils/is-twid-checksum-valid.mjs'; | ||
|
||
/** | ||
Validate ID number of Taiwan Resident Certificate (Uniform ID Numbers). | ||
@module core/twrc | ||
@param {string} id | ||
@return {boolean} | ||
Format of the id: | ||
- A123456789 (new ID in 2020) | ||
- AB12345678 (legacy but still valid) | ||
In Taiwan, there is another system called National Identification Card | ||
@see module:core/twid | ||
*/ | ||
export default (function(id) { | ||
* Validate ID number of Taiwan Resident Certificate (Uniform ID Numbers). | ||
* | ||
* Format of the ID: | ||
* - "A123456789" - New ID in 2020. | ||
* - "AB12345678" - Legacy but still valid. | ||
* | ||
* In Taiwan, there is another system called National Identification Card. | ||
* @see module:core/twid | ||
* | ||
* @module core/twrc | ||
* @param {string} id | ||
* @return {boolean} | ||
*/ | ||
export function twrc(id) { | ||
// isLengthValid = (id) -> id.length is 10 | ||
|
||
id = normalize(id); | ||
/** @type {string|boolean} - Either 'new', 'old' or false */ | ||
const idFormat = getFormat(id); | ||
const idFormat = getTWRCFormat(id); | ||
if (idFormat === 'old') { | ||
return isChecksumValid(id, 2); | ||
return isTWIDChecksumValid(id, 2); | ||
} | ||
if (idFormat === 'new') { | ||
return isChecksumValid(id, 1); | ||
return isTWIDChecksumValid(id, 1); | ||
} | ||
// else: idFormat is false | ||
return false; | ||
}); | ||
} |
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,13 +1,12 @@ | ||
/** | ||
Calculate the expected birthday by providing year only | ||
Useful for putting maxDate in isDateValid() | ||
@module utils/get-max-date | ||
@param {number} yearsOld - Should be a whole number | ||
@return {Object} An Date() object | ||
*/ | ||
export default (function(yearsOld) { | ||
* Calculate the expected birthday by providing year only. | ||
* Useful for putting `maxDate` in `isDateValid()`. | ||
* @module utils/get-max-date | ||
* @param {number} yearsOld - Should be a whole number. | ||
* @returns {Date} | ||
*/ | ||
export function getMaxDate(yearsOld) { | ||
const now = new Date(); | ||
const year = now.getFullYear() - yearsOld; | ||
return new Date(year, now.getMonth(), now.getDate()); | ||
}); | ||
} |
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,14 +1,14 @@ | ||
/** | ||
Check if the format of TWRC is old (before 2021), new (from 2021) or invalid. | ||
@param {string} id - Expect the ID is normalized. | ||
@return {string|boolean} - Either 'old', 'new' or false. | ||
*/ | ||
export default (function(id) { | ||
* Check if the format of TWRC is old (before 2021), new (from 2021) or invalid. | ||
* @param {string} id - Expect the ID is normalized. | ||
* @returns {(string|boolean)} - Either 'old', 'new' or false. | ||
*/ | ||
export function getTWRCFormat(id) { | ||
if (/^[A-Z][A-D][0-9]{8}$/.test(id)) { | ||
return 'old'; | ||
} | ||
if (/^[A-Z][89][0-9]{8}$/.test(id)) { | ||
return 'new'; | ||
} | ||
return false; | ||
}); | ||
} |
Oops, something went wrong.