Skip to content

Commit

Permalink
Merge pull request #113 from ForeverGuo/main
Browse files Browse the repository at this point in the history
添加 yd_idCard_getSex 函数
  • Loading branch information
chenbimo authored Aug 5, 2024
2 parents c241f53 + 7d870d9 commit 3f43a22
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/idCard/getSex.js
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 ? '女性' : '男性';
};
11 changes: 11 additions & 0 deletions lib/idCard/getSex.test.js
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('女性');
});
});

0 comments on commit 3f43a22

Please sign in to comment.