@clregions/core
Version:
¡Bienvenido! Con nuestra librería de TypeScript, podrás acceder fácilmente a información actualizada y precisa sobre las regiones, provincias y comunas de Chile, ahorrando tiempo y esfuerzo al no tener que recopilar y mantener los datos tú mismo.
164 lines (161 loc) • 5.41 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
CLCommuneObject: () => import_data.CLCommuneObject,
CLProvinceObject: () => import_data.CLProvinceObject,
CLRegionObject: () => import_data.CLRegionObject,
CommuneId: () => import_data.CommuneId,
ProvinceId: () => import_data.ProvinceId,
RegionId: () => import_data.RegionId,
findAllCommunes: () => findAllCommunes,
findAllCommunesByProvince: () => findAllCommunesByProvince,
findAllCommunesByRegion: () => findAllCommunesByRegion,
findAllProvinces: () => findAllProvinces,
findAllProvincesByRegion: () => findAllProvincesByRegion,
findAllRegions: () => findAllRegions,
findCommuneById: () => findCommuneById,
findProvinceById: () => findProvinceById,
findRegionByCommune: () => findRegionByCommune,
findRegionById: () => findRegionById
});
module.exports = __toCommonJS(index_exports);
var import_data = require("@clregions/data");
// src/lib.ts
var import_object = require("@clregions/data/object");
var findAllRegions = () => structuredClone(import_object.clRegions.regions);
var findRegionById = (regionId) => import_object.clRegions.regions[regionId] ? structuredClone(import_object.clRegions.regions[regionId]) : null;
var findAllProvincesByRegion = (regionId) => {
const region = import_object.clRegions.regions[regionId];
if (!region) {
return null;
}
return structuredClone(region.provinces);
};
var findAllCommunesByRegion = (regionId) => {
const region = import_object.clRegions.regions[regionId];
if (!region) {
return null;
}
const provinces = structuredClone(region.provinces);
const communes = {};
for (const provKey in provinces) {
if (Object.prototype.hasOwnProperty.call(provinces, provKey)) {
const province = provinces[provKey];
for (const communeKey in province.communes) {
if (Object.prototype.hasOwnProperty.call(province.communes, communeKey)) {
communes[communeKey] = province.communes[communeKey];
}
}
}
}
return communes;
};
var findAllProvinces = () => {
const result = {};
for (const region of Object.values(import_object.clRegions.regions)) {
const provinces = structuredClone(region.provinces);
for (const key in provinces) {
if (Object.prototype.hasOwnProperty.call(provinces, key)) {
result[key] = provinces[key];
}
}
}
return result;
};
var findProvinceById = (provinceId) => {
try {
const parentRegionKey = provinceId.length === 2 ? provinceId.slice(0, 1) : provinceId.slice(0, 2);
const province = structuredClone(
import_object.clRegions.regions[parentRegionKey].provinces[provinceId]
);
return province;
} catch {
return null;
}
};
var findAllCommunesByProvince = (provinceId) => {
try {
const communesData = structuredClone(
import_object.clRegions.regions[provinceId.slice(0, 2)].provinces[provinceId].communes
);
const result = {};
for (const key in communesData) {
if (Object.prototype.hasOwnProperty.call(communesData, key)) {
result[key] = communesData[key];
}
}
return result;
} catch {
return null;
}
};
var findAllCommunes = () => {
const communes = {};
for (const region of Object.values(import_object.clRegions.regions)) {
for (const provKey in region.provinces) {
if (Object.prototype.hasOwnProperty.call(region.provinces, provKey)) {
const province = region.provinces[provKey];
for (const commKey in province.communes) {
if (Object.prototype.hasOwnProperty.call(province.communes, commKey)) {
communes[commKey] = structuredClone(province.communes[commKey]);
}
}
}
}
}
return communes;
};
var findCommuneById = (communeId) => {
try {
const commune = structuredClone(
import_object.clRegions.regions[communeId.slice(0, 2)].provinces[communeId.slice(0, 3)].communes[communeId]
);
return structuredClone(commune);
} catch {
return null;
}
};
var findRegionByCommune = (communeId) => {
const region = structuredClone(import_object.clRegions.regions[communeId.slice(0, 2)]);
if (!region) {
return null;
}
return region;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CLCommuneObject,
CLProvinceObject,
CLRegionObject,
CommuneId,
ProvinceId,
RegionId,
findAllCommunes,
findAllCommunesByProvince,
findAllCommunesByRegion,
findAllProvinces,
findAllProvincesByRegion,
findAllRegions,
findCommuneById,
findProvinceById,
findRegionByCommune,
findRegionById
});