UNPKG

@matheustrres/brasilapi

Version:

Lightweight, easy-to-use & free of dependencies wrapper for BrasilAPI

29 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BrasilAPICEP = void 0; const source_1 = require("./source"); const http_client_1 = require("../clients/http-client"); const clear_string_1 = require("../utils/clear-string"); /** * Represents the source from BrasilAPI CEP's endpoint responses */ class BrasilAPICEP extends source_1.Source { URL = 'https://brasilapi.com.br/api/cep'; /** * Gets information from a Zip Code with multiple fallback providers * * @param {String} cep - The zip code to be fetched * @param {String} [version] - The CEP endpoint version to use (defaults to `v1`) * @returns {Promise<Result<CEP>>} */ async get(cep, version = 'v1') { cep = (0, clear_string_1.clearString)(cep); if (!version || !['v1', 'v2'].includes(version)) { throw new TypeError('Version is required and must evalute to "v1" or "v2"'); } const res = await (0, http_client_1.makeGET)(`${this.URL}/${version}/${cep}`); return this.followUp(res); } } exports.BrasilAPICEP = BrasilAPICEP; //# sourceMappingURL=cep.js.map