Skip to content

Commit

Permalink
Ditch eslint and jest (#32)
Browse files Browse the repository at this point in the history
* chore: ditch all bulshit in eslint and jest for using node:test

* style: fizx code tabs and identation
  • Loading branch information
victorfernandesraton authored Jun 20, 2024
1 parent 4e2b4cd commit 4b2f29a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 45 deletions.
6 changes: 0 additions & 6 deletions src/errors/basicError.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
export class BasicError extends Error {
/**
* @param {string} [message]
*/
constructor (message) {
super(message)
}
}
10 changes: 5 additions & 5 deletions src/provider.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ export class Provider {
#services

/**
* @param {CepService[]} services
*/
* @param {CepService[]} services
*/
constructor (services) {
this.#services = services
}

/**
* @param {string | number} zipcode
* @returns {Promise<Cep>}
*/
* @param {string | number} zipcode
* @returns {Promise<Cep>}
*/
async execute (zipcode) {
const result = await Promise.any(
this.#services.map((item) => item.execute(zipcode))
Expand Down
14 changes: 7 additions & 7 deletions src/requester/index.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export class RequestWIthFetch {
/**
* @param {Object} param
* @param {string | URL} param.url
* @param {BodyInit} [param.body]
* @param {Object} [param.headers]
* @param {string} [param.method]
* @param {Object} [param.params]
*/
* @param {Object} param
* @param {string | URL} param.url
* @param {BodyInit} [param.body]
* @param {Object} [param.headers]
* @param {string} [param.method]
* @param {Object} [param.params]
*/
async execute ({ url, body, headers, method, params }) {
const searchParams = new URLSearchParams(params)

Expand Down
12 changes: 6 additions & 6 deletions src/service/apicep/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import { CepService } from '../index.mjs'

export class ApiCepService extends CepService {
/**
* @param {import('../index.mjs').RequestWIthFetch} request
*/
* @param {import('../index.mjs').RequestWIthFetch} request
*/
constructor (request) {
super('apicep', request, 'https://ws.apicep.com/cep.json')
}

/**
* @typedef {import('../../types.js').Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
* @typedef {import('../../types.js').Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
async handler (cep) {
const request = await this.requester.execute({
url: this.baseUrl,
Expand Down
14 changes: 7 additions & 7 deletions src/service/brasilAPI/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { CepService } from '../index.mjs'

export class BrasilAPIService extends CepService {
/**
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} request
*/
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} request
*/
constructor (request) {
super('brasilAPI', request, 'https://brasilapi.com.br/api/cep/v1')
}

/**
* @typedef {import('../../types.ts').Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
* @typedef {import('../../types.ts').Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
async handler (cep) {
const request = await this.requester.execute({ url: `${this.baseUrl}/${cep}` })
const data = await request.json()
Expand Down
7 changes: 3 additions & 4 deletions src/service/correios/adapters.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ParserError } from '../../errors/parserError.mjs'

export function parseParamsToXML (data) {
return `<?xml version="1.0"?>\n <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/"> <soapenv:Header /> <soapenv:Body> <cli:consultaCEP> <cep>${data}</cep> </cli:consultaCEP> </soapenv:Body></soapenv:Envelope>`
return `<?xml version="1.0"?>\n <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/"> <soapenv:Header /> <soapenv:Body> <cli:consultaCEP> <cep>${data}</cep> </cli:consultaCEP> </soapenv:Body></soapenv:Envelope>`
}

export function responseToCep (data) {
try {
const returnStatement =
data.replace(/\r?\n|\r/g, '').match(/<return>(.*)<\/return>/)?.[0] ?? ''
if (returnStatement == '') {
const returnStatement = data.replace(/\r?\n|\r/g, '').match(/<return>(.*)<\/return>/)?.[0] ?? ''
if (returnStatement === '') {
throw new ParserError(`invalid regex got ${data}`, 'correios')
}
const cleanReturnStatement = returnStatement
Expand Down
6 changes: 3 additions & 3 deletions src/service/correios/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { parseParamsToXML, responseToCep } from './adapters.mjs'

export class CorreiosService extends CepService {
/**
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} requester
*/
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} requester
*/
constructor (requester) {
super('correios', requester, 'https://apps.correios.com.br')
}
Expand Down
14 changes: 7 additions & 7 deletions src/service/viacep/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { CepService } from '../index.mjs'

export class ViaCepService extends CepService {
/**
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} requester
*/
* @typedef {import('../../requester/index.mjs').RequestWIthFetch} RequestWIthFetch
* @param {RequestWIthFetch} requester
*/
constructor (requester) {
super('viacep', requester, 'https://viacep.com.br')
}

/**
* @typedef {import("../../types.js").Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
* @typedef {import("../../types.js").Cep} Cep
* @param {string} cep
* @returns {Promise<Cep>}
*/
async handler (cep) {
const request = await this.requester.execute({
url: `${this.baseUrl}/ws/${cep}/json`,
Expand Down

0 comments on commit 4b2f29a

Please sign in to comment.