crypto-symbol
v3.6.0
Published
Provide easy conversion between crypto symbol and name
Downloads
1,319
Maintainers
Readme
🐤 Simple fuzzy conversion for crypto symbol and crypto name.
📔 Source: CoinMarketCap
🔔 Almost 5000 pairs to search for, with typescript const assertion.
💪 Can add your own custom name-symbol pair.
🌟 Optimized lookup time.
🆙 Check for update daily and publish new version if there is change.
🥰 0 dependencies.
⛲️ Out of box typescript support.
🦺 Development code, built code, and published code are all tested in CI.
Installation
npm i crypto-symbol
Usage
Normally ticker symbol is unique, but for whatever reason on very rare occasional, CMC lists new coin that has the same ticker symbol(case-insensitive). If duplicated names or symbols are found in the CoinMarketCap list, the library keep higher rank(larger market cap) coins. If you need lower rank coins, please can add it yourself. Keep in mind to use unique name and unique symbol for them.
🎵 Get Pairs Object
import { cryptoSymbol } from 'crypto-symbol'
const { get } = cryptoSymbol({})
// all the pair objects are properly typed with const assertion
get().NSPair // {Bitcoin: 'BTC',Ethereum: 'ETH','Binance Coin': 'BNB',......}
get().SNPair // {BTC: 'Bitcoin',ETH: 'Ethereum','BNB': 'Binance Coin',......}
⚒ Add new pair or modify existing pair
import { cryptoSymbol } from 'crypto-symbol'
// will overwrite existing pair and add new type to pairs object
const { get, nameLookup, symbolLookup } = cryptoSymbol({
newCoin: 'NC123' as const, // add new coin
bitcoin: 'BTC' as const, // modify existing coin
}) // use const assertion to narrow down the type
🎐 Symbol Lookup
import { cryptoSymbol } from 'crypto-symbol'
const { symbolLookup } = cryptoSymbol({})
// case insensitive
// ignore all special character and space
symbolLookup(' liT ec @oin ') // "LTC"
symbolLookup(' τbITcO in ') // BTC
// case insensitive
// can allow specific special character
// to allow multiple special character, simply concat all the character, eg "#$%)("
symbolLookup(' τbITcO in ', { allow: 'τ' }) // TBTC
// exact match (case sensitive)
symbolLookup(' liT ec @oin ', { exact: true }) // undefined
symbolLookup('litecoin', { exact: true }) // "undefined"
symbolLookup('Litecoin', { exact: true }) // "LTC"
⚡️ Name Lookup
import { cryptoSymbol } from 'crypto-symbol'
const { nameLookup } = cryptoSymbol({})
// case insensitive
// ignore all special character and space)
nameLookup(' @Ltc! ') // "Litecoin"
// can allow specific special character
// to allow multiple special character, simply concat all the character, eg "#$%)("
// all symbol are alphanumeric anyway, I don't think you will need it
nameLookup(' @Ltc! ', { allow: '@' }) // undefined, because symbol "@Ltc" does not exist
// exact match (case sensitive)
nameLookup(' Ltc ', { exact: true }) // undefined
nameLookup('Ltc', { exact: true }) // undefined
nameLookup('LTC', { exact: true }) // Litecoin
🍀 Sync
Sync the coin manually.
- You can only use this api in server environment due to Coinmarketcap CORS policy.
- You need to install axios to use this api, simply installing it is enough.
npm i axios
- Added pairs and modified pairs have higher priority than sync, sync will not overwrite them.
import { cryptoSymbol } from 'crypto-symbol'
const { sync } = cryptoSymbol({})
// sync with latest coinmarketcap list
// this is a promise
sync('coinmarketcap apiKey')
Credit
Crypto Symbol logo source