1.7.0 • Published 5 years ago

@donald.ma/utils v1.7.0

Weekly downloads
2
License
ISC
Repository
-
Last release
5 years ago

My npm package

An npm package with random functions :)

Installation

npm i donaldma-npm

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('&')
}