UNPKG

@zodash/idcard

Version:

chinese id card parser, generator and validator

36 lines (35 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generate = void 0; const random_1 = require("@zodash/random"); const moment_1 = require("@zcorky/moment"); const ADDRESS = require("./data/address.json"); const codes = Object.keys(ADDRESS); function generate(options) { var _a, _b, _c; const addressCode = (_a = options === null || options === void 0 ? void 0 : options.addressCode) !== null && _a !== void 0 ? _a : randomAddressCode(); const birthday = (_b = options === null || options === void 0 ? void 0 : options.birthday) !== null && _b !== void 0 ? _b : randomBirthday(); const sex = (_c = options === null || options === void 0 ? void 0 : options.sex) !== null && _c !== void 0 ? _c : randomSex(); const police = randomPolice(); const checkBit = randomCheckBit(); return [addressCode, birthday, sex, police, checkBit].join(''); } exports.generate = generate; function randomAddressCode() { return codes[random_1.number(codes.length)]; } function randomBirthday() { const min = moment_1.default('1900-01-01').valueOf(); const max = moment_1.default().valueOf(); const _ = random_1.number(max, min); return moment_1.default(_).format('YYYYMMDD'); } function randomSex() { return random_1.number(10); } function randomPolice() { return random_1.number(100, 10); } function randomCheckBit() { return random_1.number(10); }