donaldma / utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My npm package

An npm package with random functions :)

Installation

npm i @donald.ma/utils

Stack

Functions

isCurrency

const isCurrency = (str: string): boolean => {
  const cleanedString = str.trim().toUpperCase()
  const isCrypto = Constants.cryptocurrencies[cleanedString] ? true : false
  const isFiat = Constants.fiatCurrenciesData.includes(cleanedString)

  return isCrypto || isFiat
}

const isNumeric = (value: any): boolean => {
  return !isNaN(parseFloat(value)) && isFinite(value)
}

const jsonToQueryString = (json: object): string => {
  return Object.keys(json).filter((key) => json[key] !== undefined).map((key) => {
    return encodeURIComponent(key) + '=' + encodeURIComponent(json[key])
  }).join('&')
}

About


Languages

Language:TypeScript 100.0%