get-mexican-data-by-curp
Version:
Verify CURP and obtain personal information from the Mexican government CURP. It scrapes official site and another providers.
46 lines (45 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Curp = exports.BadCurpFormat = void 0;
const shared_1 = require("../shared");
class BadCurpFormat extends Error {
constructor(curp) {
super(`'${curp}' is an invalid curp`);
}
}
exports.BadCurpFormat = BadCurpFormat;
class Curp extends shared_1.StringObject {
constructor(curpId) {
super(curpId);
this.curpIdPattern = /[A-Z][AEIXOU][A-Z]{2}[0-9]{2}(0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])[HM](AS|BC|BS|CC|CS|CH|CL|CM|DF|DG|GT|GR|HG|JC|MC|MN|MS|NT|NL|OC|PL|QT|QR|SP|SL|SR|TC|TS|TL|VZ|YN|ZS|NE)[B-DF-HJ-NP-TV-Z]{3}[0-9A-Z][0-9]/;
this.ensure();
}
get state() {
const matches = this.curpIdPattern.exec(this.value);
return matches === null ? '' : matches[3];
}
getIsoState() {
return new Promise(resolve => resolve(this.state));
}
ensure() {
this.isNotUndefined();
this.toUpperCase();
this.ensureCurpId();
}
toUpperCase() {
this.value = this.value.toUpperCase();
}
ensureCurpId() {
const match = this.curpIdPattern.exec(this.value);
if (!match) {
throw new BadCurpFormat(this.value);
}
this.value = match[0];
}
isNotUndefined() {
if (this.value === undefined) {
throw new BadCurpFormat(this.value);
}
}
}
exports.Curp = Curp;