thai-id-validator
Version:
Thai Citizen ID validator with 0 dependencies
124 lines (82 loc) ⢠3.45 kB
Markdown
# Thai Citizen ID Validator

[](https://app.codacy.com/gh/jukbot/thai-citizen-id-validator/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://www.npmjs.com/package/thai-id-validator)
[](https://standardjs.com)
[](https://www.npmjs.com/package/thai-id-validator)
[](https://jsr.io/@jukbot/thai-id-validator)
A simpler way to validate Thai Citizen Card ID. š¹š
## Minimum Node.js Version ā ļø
This package requires Node.js version 16 or later.
## Future Roadmap
- Go Language Implementation Example
- .NET Language Implementation Example
- Thai Passport Number Validation
## Read the article
[Building Thai Citizen ID Input Validation with WCAG Standard](https://medium.com/@juk/%E0%B8%A5%E0%B8%AD%E0%B8%87%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%9F%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%A1%E0%B8%95%E0%B8%A3%E0%B8%A7%E0%B8%88%E0%B8%AA%E0%B8%AD%E0%B8%9A%E0%B9%80%E0%B8%A5%E0%B8%82%E0%B8%9A%E0%B8%B1%E0%B8%95%E0%B8%A3-%E0%B8%9B%E0%B8%8A%E0%B8%8A-%E0%B8%9E%E0%B8%A3%E0%B9%89%E0%B8%AD%E0%B8%A1%E0%B8%A1%E0%B8%B2%E0%B8%95%E0%B8%A3%E0%B8%90%E0%B8%B2%E0%B8%99-wcag-13b2c8c9d015)
## Installation
Works with npm, jsr, yarn, pnpm, bun or deno
```bash
$ npm install thai-id-validator
# or
$ yarn add thai-id-validator
# or
$ pnpm add thai-id-validator
# or
$ bun add thai-id-validator
# or
$ pnpm dlx jsr add @jukbot/thai-id-validator
# or
$ deno add jsr:@luca/flag
```
## Data Type
| Input | Output |
| ------ | :-----: |
| String | boolean |
## Usage
### Javascript / Typescript
In Javascript, Typescript file, you can use import, export modules
```javascript
import isValidThaiID from 'thai-id-validator';
let result = isValidThaiID(ā1101700207030ā);
console.log(result);
// true
```
## Test
To run all test cases run the following command
```bash
bun run test
```
You can edit validator.test.js too add your custom test case.
| Test Cases | Result |
| --------------- | :----: |
| '1112034563562' | ā
|
| '0113200420331' | ā
|
| '1101700230705' | ā |
| '110170023073' | ā |
| '11017002070d3' | ā |
| 'rytege54fsfsf' | ā |
| 0 | ā |
| '-' | ā |
| '' | ā |
| null | ā |
| undefined | ā |
| 'blablabla' | ā |
`(Tested with Bun)`
### Test Result Screenshot
<img src="test-result.png" width="500"/>
### How to upload test coverage report to codacy
```zsh
export CODACY_PROJECT_TOKEN=xxxxxxxxx
bun run coverage
bash <(curl -Ls https://coverage.codacy.com/get.sh)
```
## Compatibility
Tested on all modern browsers ā
## Issues
If you found any š or feedback, please report the issue [here](https://github.com/jukbot/thai-citizen-id-validator/issues)
## Contribution
š©š»āš» Contribute are always welcome.
## License
[MIt](https://opensource.org/license/mit)
Code with love š¦