@vdegenne/cmc 0.1.11 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,21 +18,46 @@ Create static data from CoinMarketCap :
18
18
 
19
19
  ## How to use data
20
20
 
21
+ Do not forget to add `@vdegenne/cmc` to the list of `types` in your `tsconfig.json` to have the types available.
22
+
23
+ ### Static version
24
+
21
25
  ```ts
22
26
  /* cmc.ts */
23
- import _currencies from '@vdegenne/cmc/data/mini.json' with {type: 'json'}
24
- export * from '@vdegenne/cmc'
25
-
26
- export const currencies = _currencies as CMC.MiniCurrency[]
27
-
28
- export function getCMCCurrencyFromSymbol(symbol: string, fromLast = false) {
29
- const currencies = [..._currencies] as CMC.MiniCurrency[]
30
- if (fromLast) {
31
- currencies.reverse()
32
- }
33
- symbol = symbol.toLocaleUpperCase()
34
- return currencies.find((c) => c.symbol === symbol)
35
- }
27
+ import currencies from '@vdegenne/cmc/data/mini.json' with {type: 'json'}
28
+ import {CMCManager} from '@vdegenne/cmc/CMCManager.js'
29
+ export * from '@vdegenne/cmc/utils.js'
30
+
31
+ export const cmcManager = new CMCManager({
32
+ initData: currencies,
33
+ })
34
+
35
+ // Usage
36
+ cmcManager.getCurrencyFromSymbol('btc').name // Bitcoin
37
+ // ...
38
+ ```
39
+
40
+ Pros: You can inline the static data in your app, instant load.
41
+ Cons: You have to bump/build/deploy each time you want the latest updated data.
42
+
43
+ So not recommended unless your app is sluggish and doesn't care about newly updated altcoins.
44
+
45
+ ### Dynamic version
46
+
47
+ ```ts
48
+ /* cmc.ts */
49
+ import {CMCManager} from '@vdegenne/cmc/CMCManager.js'
50
+ export * from '@vdegenne/cmc/utils.js'
51
+
52
+ export const cmcManager = new CMCManager({
53
+ // options
54
+ })
55
+
56
+ // Usage
57
+ await cmcManager.ready
58
+ cmcManager.getCurrencyFromSymbol('btc').name // Bitcoin
59
+ // ...
36
60
  ```
37
61
 
38
- Do not forget to add `@vdegenne/cmc` to the list of `types` in your `tsconfig.json`.
62
+ Pros: Data is fetched from CDN which will pull latest data possible. You don't have to build everytime data changes.
63
+ Cons: More complex to integrate in your app, because now it's asynchronous and you have to make sure the data is fetched before feeding your views (use `cmcManager.ready`)