chinese-idcard
v1.0.6
Published
chinese-idcard ===================== - 18位身份证校验 - 支持步进模式: 分批输入 /后退取消 - 普通整体输入模式 - 随机生成 指定开始{y:,m:,d:} 结束{y:,m:,d:} - 连续生成 generator 指定生成范围
Downloads
6
Readme
chinese-idcard
- 18位身份证校验
- 支持步进模式: 分批输入 /后退取消
- 普通整体输入模式
- 随机生成 指定开始{y:,m:,d:} 结束{y:,m:,d:}
- 连续生成 generator 指定生成范围
install
- npm install chinese-idcard
usage
const {
ID,
parse,
unparse,
SERROR,
SERROR_DICT,
STATE_DICT,
random,
gen
} = require("chinese-idcard");
example
###普通模式 18位整体输入
> var d = parse("659001197012113369")
> d
{
province: '新疆维吾尔自治区',
city: '自治区直辖县级行政单位',
county: '石河子市',
year: 1970,
month: 12,
day: 11,
police: '33',
sex: '女',
sex_code: 6,
parity: '9'
}
unparse(d)
> unparse(d)
'659001197012113369'
>
###步进模式
var id=new ID()
////
id.next("658")
id.prev(1)
id.next("9001")
////
id.next("19701")
id.next("211")
////
id.next("33")
id.next("6")
id.next("9")
////
id.next()
> id.next("658")
ID {
cache: [ '6', '5', '8' ],
state: 'waiting_area',
rslt: {},
error: { pl: [], msg: '' }
}
> id.prev(1)
ID {
cache: [ '6', '5' ],
state: 'waiting_area',
rslt: {},
error: { pl: [], msg: '' }
}
> id.next("9001")
ID {
cache: [ '6', '5', '9', '0', '0', '1' ],
state: 'waiting_birth',
rslt: { province: '新疆维吾尔自治区', city: '自治区直辖县级行政单位', county: '石河子市' },
error: { pl: [], msg: '' }
}
>
>
>
> id.next("19701")
ID {
cache: [
'6', '5', '9', '0',
'0', '1', '1', '9',
'7', '0', '1'
],
state: 'waiting_birth',
rslt: { province: '新疆维吾尔自治区', city: '自治区直辖县级行政单位', county: '石河子市' },
error: { pl: [], msg: '' }
}
> id.next("211")
ID {
cache: [
'6', '5', '9', '0',
'0', '1', '1', '9',
'7', '0', '1', '2',
'1', '1'
],
state: 'waiting_police',
rslt: {
province: '新疆维吾尔自治区',
city: '自治区直辖县级行政单位',
county: '石河子市',
year: 1970,
month: 12,
day: 11
},
error: { pl: [], msg: '' }
}
>
> id.next("33")
ID {
cache: [
'6', '5', '9', '0',
'0', '1', '1', '9',
'7', '0', '1', '2',
'1', '1', '3', '3'
],
state: 'waiting_sex',
rslt: {
province: '新疆维吾尔自治区',
city: '自治区直辖县级行政单位',
county: '石河子市',
year: 1970,
month: 12,
day: 11,
police: '33'
},
error: { pl: [], msg: '' }
}
> id.next("6")
ID {
cache: [
'6', '5', '9', '0', '0',
'1', '1', '9', '7', '0',
'1', '2', '1', '1', '3',
'3', '6'
],
state: 'waiting_parity',
rslt: {
province: '新疆维吾尔自治区',
city: '自治区直辖县级行政单位',
county: '石河子市',
year: 1970,
month: 12,
day: 11,
police: '33',
sex: '女',
sex_code: 6
},
error: { pl: [], msg: '' }
}
> id.next("9")
ID {
cache: [
'6', '5', '9', '0', '0',
'1', '1', '9', '7', '0',
'1', '2', '1', '1', '3',
'3', '6', '9'
],
state: 'finished',
rslt: {
province: '新疆维吾尔自治区',
city: '自治区直辖县级行政单位',
county: '石河子市',
year: 1970,
month: 12,
day: 11,
police: '33',
sex: '女',
sex_code: 6,
parity: '9'
},
error: { pl: [], msg: '' }
}
>
> id.next()
ID {
cache: [],
state: 'waiting_area',
rslt: {},
error: { pl: [], msg: '' }
}
>
>
随机生成
> random()
'450501197303029919'
> random()
'331181195210270070'
> random()
'340601198609161554'
> random()
'130925197404294656'
> random()
'430181199905138077'
> random()
'45032519970602656X'
> random()
'140525201501128325'
> random()
'37040319870903391X'
> random()
'652327195707296100'
GENERATOR
//配置格式如下
var cfg = {
area:['654002','654003','654028'],
birth:{
start:{y:1999,m:1,d:1},
end:{y:2030,m:12,d:31}
},
police:{start:0,end:99},
sex:{
sex:"男", //"男" "女" "任意"
sex_codes:[3,5]
}
}
> var g = gen(cfg)
> g.next()
{ value: '654002195001010033', done: false }
> g.next()
{ value: '65400219500101005X', done: false }
> g.next()
{ value: '65400219500101013X', done: false }
> g.next()
{ value: '654002195001010156', done: false }
> g.next()
{ value: '654002195001010236', done: false }
> g.next()
{ value: '654002195001010252', done: false }
> g.next()
{ value: '654002195001010332', done: false }
> g.next()
{ value: '654002195001010359', done: false }
> g.next()
{ value: '654002195001010439', done: false }
> g.next()
{ value: '654002195001010455', done: false }
> g.next()
{ value: '654002195001010535', done: false }
> g.next()
{ value: '654002195001010551', done: false }
> g.next()
{ value: '654002195001010631', done: false }
>
LICENSE
- ISC