Coder Social home page Coder Social logo

tylim88 / crypto-symbol Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 9.0 12.43 MB

:baby_chick: Provide easy conversion between crypto symbol and name, auto update daily

Home Page: https://www.npmjs.com/package/crypto-symbol

License: MIT License

JavaScript 1.71% TypeScript 98.25% Shell 0.04%
bitcoin ethereum crypto symbol name cryptocurrency

crypto-symbol's Introduction

Crypto Symbol

Created by tylim88   License   dependency count   github action   code coverage   GitHub issues   code coverage

🐤 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.

  1. You can only use this api in server environment due to Coinmarketcap CORS policy.
  2. You need to install axios to use this api, simply installing it is enough.
npm i axios
  1. 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

crypto-symbol's People

Contributors

dependabot[bot] avatar tylim88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crypto-symbol's Issues

Edge-case bug with overriding ticker/symbol.

Problem context

Nano recently changed it's ticker to XNO instead of Nano.

There is currently also a token under XNO called "Xeno Token".

That, in of itself is fine. I'd like to override the XNO ticker to have a name of "Nano" as I don't care about this particular token.

The Bug

Because the code is basically Object.assign based on the "name-symbol" pair, it's keying off of the name specifically for an overwrite.

This means it is overriding the ticker for Nano (NANO) to be XNO, the swapKeyAndValue function will hit "XNO": "Nano", and override it to be "XNO": "Xeno Token" as it is further down the list.

Undeclared dependency

I'm trying to use this library in my Vite app, but it seems like it needs axios as a dependency:

✘ [ERROR] Could not resolve "axios"

  node_modules/crypto-symbol/dist/1_sync/1_fetch.js:34:75:
    34 │     const axios = (await Promise.resolve().then(() => __importStar(require('axios')))).default;
       ╵                                                                            ~~~~~~~

  You can mark the path "axios" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

8:38:47 PM [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/crypto-symbol/dist/1_sync/1_fetch.js:34:75: ERROR: Could not resolve "axios"
    at failureErrorWithLog (/home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:1600:15)
    at /home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:1246:28
    at runOnEndCallbacks (/home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:1031:63)
    at buildResponseToResult (/home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:1244:7)
    at /home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:1353:14
    at /home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:663:9
    at handleIncomingPacket (/home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:760:9)
    at Socket.readFromStdout (/home/daniel/Documents/JS/wwwallet-fe/node_modules/esbuild/lib/main.js:629:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
Vite Error, /node_modules/.vite/deps/crypto-symbol.js?v=2dfff904 optimized info should be defined```

Possible to look for multiple tickers in string?

Hi, is there a way to get multiple tickers using the symbolLookup() function? i have some strings that have more than 1 ticker on it,
example: 'Price analysis 9/14: BTC, ETH, BNB, XRP, ADA, SOL, DOGE, DOT, MATIC, SHIB' but when i run the function it returns undefined.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.