cnj-validate
Version:
Biblioteca TypeScript para validação e análise de números de processos em conformidade com o CNJ (Conselho Nacional de Justiça) do Brasil
78 lines • 2.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DISTRICTS = void 0;
exports.getDistrictInfo = getDistrictInfo;
exports.generateDistrictKey = generateDistrictKey;
exports.getDistrictsByUF = getDistrictsByUF;
exports.getDistrictsBySegment = getDistrictsBySegment;
exports.addDistrict = addDistrict;
exports.hasDistrict = hasDistrict;
exports.getDistrictsStats = getDistrictsStats;
const districts_json_1 = __importDefault(require("./districts.json"));
/**
* Base de dados completa de distritos/comarcas brasileiras
* Convertida com 9.803 distritos
* Cobrindo todos os 27 estados brasileiros
*/
exports.DISTRICTS = districts_json_1.default;
/**
* Busca informações de distrito por chave
*/
function getDistrictInfo(key) {
return exports.DISTRICTS[key] || null;
}
/**
* Gera chave de distrito no formato: segment.court.sourceUnit
*/
function generateDistrictKey(segment, court, sourceUnit) {
return `${segment}.${court}.${sourceUnit}`;
}
/**
* Busca distritos por UF
*/
function getDistrictsByUF(uf) {
return Object.keys(exports.DISTRICTS)
.map((key) => exports.DISTRICTS[key])
.filter((district) => district.uf === uf.toUpperCase());
}
/**
* Busca distritos por segmento
*/
function getDistrictsBySegment(segment) {
return Object.keys(exports.DISTRICTS)
.filter((key) => key.startsWith(`${segment}.`))
.map((key) => exports.DISTRICTS[key]);
}
/**
* Adiciona novo distrito à base (para extensão futura)
*/
function addDistrict(key, district) {
exports.DISTRICTS[key] = district;
}
/**
* Verifica se existe distrito para uma chave
*/
function hasDistrict(key) {
return key in exports.DISTRICTS;
}
/**
* Estatísticas da base de dados
*/
function getDistrictsStats() {
const keys = Object.keys(exports.DISTRICTS);
const ufs = new Set(Object.values(exports.DISTRICTS).map((d) => d.uf));
return {
totalDistricts: keys.length,
totalStates: ufs.size,
states: Array.from(ufs).sort(),
segmentCounts: keys.reduce((acc, key) => {
const segment = key.split('.')[0];
acc[segment] = (acc[segment] || 0) + 1;
return acc;
}, {}),
};
}
//# sourceMappingURL=districts.js.map