Comparing version 0.0.2 to 0.0.3
14
index.js
@@ -11,11 +11,11 @@ var moment = require('moment'); | ||
function get(id) { | ||
if(typeof id !== 'string' || id.length !== 18) { | ||
var id = String(id); | ||
if(id.length !== 18) { | ||
return; | ||
} | ||
var localCode = id.substring(0,6); | ||
var division = gb.get(localCode); | ||
var homeTown = division!==null ? division.toString() : '无对应数据'; | ||
var division = gb.get(id.substring(0,6)); | ||
var hometown = division!==null ? division.toString() : '无对应数据'; | ||
var date = moment(id.substring(6,14),'YYYYMMDD'); | ||
return { | ||
homeTown, | ||
hometown, | ||
birthday: date.isValid() ? date : moment(), | ||
@@ -26,6 +26,2 @@ sex: id.substring(16,17)%2 === 0 ? '女' : '男' | ||
// console.log(get('45222319950814004X')); | ||
// console.log(get('330722197609192116')); | ||
// console.log(get('430421197710177894')); | ||
exports.get = get; |
{ | ||
"name": "id-parser", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "中国身份证号码解析器,传入身份证号,返回 【户籍地】【出生年月】【性别】", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test/index.spec.js" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -10,9 +10,9 @@ # id-resolver | ||
```javascript | ||
var idResolver = require('id-parser'); | ||
var idParser = require('id-parser'); | ||
//只处理 18位字符串 | ||
console.log(idResolver.get('430421197710177894')); | ||
// { locale: '湖南省 衡阳市 衡阳县', birthday: moment("1977-10-17T00:00:00.000"), sex: '男' } | ||
console.log(idResolver.get('45222319950814004X')); | ||
// { locale: '无对应数据', birthday: moment("1995-08-14T00:00:00.000"), sex: '女' } | ||
console.log(idParser.get('430421197710177894')); | ||
// { hometown: '湖南省 衡阳市 衡阳县', birthday: moment("1977-10-17T00:00:00.000"), sex: '男' } | ||
console.log(idParser.get('45222319950814004X')); | ||
// { hometown: '无对应数据', birthday: moment("1995-08-14T00:00:00.000"), sex: '女' } | ||
``` | ||
@@ -19,0 +19,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
4311
7
34
1