marileize / selic

0 stars 0 forks source link

Convert strings to date and number #14

Open marileize opened 6 months ago

adilsoncarvalho commented 6 months ago

One consideration, though. You might want to make your function in a way that will be easier to consume. You know that you'll be using it in a map() to convert the endpoint return.

Here is a simplified example of your endpoint result:

const result = [
            {
                "data":"08/03/2024",
                "valor":"0.041957",
            }
];

With your current implementation, you'll have to consume it like this:

result.map(o => convertSelicEntry(o.data, o.valor))

// or

result.map(({data, valor}) => convertSelicEntry(data, valor))

If you change your method's signature to the example below,

async function convertSelicEntry({data: string, valor: string}): SelicEntry {
  // funky code here
}

you'll be able to consume it like this:

result.map(convertSelicEntry)

What do you think?