-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from ForeverGuo/main
添加 yd_idCard_getSex 函数
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* @description 根据身份证获取性别 | ||
* @author grantguo <https://github.com/ForeverGuo> | ||
* @category idCard | ||
* @alias yd_idCard_getSex | ||
* @param { string } card 身份证号 | ||
* @return 返回性别 | ||
* @summary 根据身份证号码获取性别 | ||
* @example | ||
* yd_idCard_getSex(card) | ||
*/ | ||
export default (card) => { | ||
const num = Number(card.slice(-2, -1)); | ||
return num % 2 === 0 ? '女性' : '男性'; | ||
}; |
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,11 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import yd_idCard_getSex from './getSex.js'; | ||
|
||
describe('yd_idCard_getAge', () => { | ||
it('获取性别', () => { | ||
const sex_1 = yd_idCard_getSex('220181199608286312'); | ||
expect(sex_1).toEqual('男性'); | ||
const sex_2 = yd_idCard_getSex('42132120020509720X'); | ||
expect(sex_2).toEqual('女性'); | ||
}); | ||
}); |