@gusbueno/js-utils
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

CircleCI npm version dependencies

js-utils

Javascript utilities that you can use in your day-to-day development

arrayToObject

This function will help you to convert an array of objects to one object(key/value).

Example:

import { arrayToObject } from '@gusbueno/js-utils'

const data = [
  {
    name: 'BTC',
    value: 6000
  }, {
    name: 'XRP',
    value: 0.34
  }
]

const objectData = arrayToObject(data, 'name')

/* RESULT
{
  BTC: {
    name: 'BTC',
    value: 6000
  },
  XRP: {
    name: 'XRP',
    value: 0.34
  }
}
 */

to

This function will help you to handle errors from async/await operator.

Example:

import axios from 'axios'
import { to } from '@gusbueno/js-utils'

const getUsers = async () => {
  const [err, data] = await to(axios.get('http://host.com/api/users'))
  if (err) { // which means that err has value
    return 'An error ocurred on getUsers request'
  }
  // if err has no value then data has value
  return data
}

Package Sidebar

Install

npm i @gusbueno/js-utils

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

7.58 kB

Total Files

17

Last publish

Collaborators

  • gusbueno