MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / parseObject

Function parseObject

services/sefaz/index.js:4–33  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

2import ncmList from './ncmList.json';
3
4function parseObject(obj) {
5 const formatDate = (date) => {
6 const newDate = new Date(date.split('/').reverse());
7 return newDate.toISOString().slice(0, 10);
8 };
9
10 const convertKeysToLowerCase = Object.fromEntries(
11 Object.entries(obj).map(([k, v]) => [k.toLowerCase(), v])
12 );
13
14 const {
15 tipo_ato_ini: tipoAtoIni,
16 numero_ato_ini: numeroAtoIni,
17 ano_ato_ini: anoAtoIni,
18 data_inicio: dataInicio,
19 data_fim: dataFim,
20 ...rest
21 } = convertKeysToLowerCase;
22
23 const newObj = {
24 ...rest,
25 data_inicio: formatDate(dataInicio),
26 data_fim: formatDate(dataFim),
27 tipo_ato: tipoAtoIni,
28 numero_ato: numeroAtoIni,
29 ano_ato: anoAtoIni,
30 };
31
32 return newObj;
33}
34
35const fetchNcmListFromSefaz = async () => {
36 const url =

Callers 1

getNcmDataFunction · 0.85

Calls 1

formatDateFunction · 0.70

Tested by

no test coverage detected