@vdegenne/cmc 0.1.12 → 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 +39 -14
- package/data/all.json +1 -1
- package/data/mini.json +1 -1
- package/lib/CMCManager.d.ts +25 -3
- package/lib/CMCManager.d.ts.map +1 -1
- package/lib/CMCManager.js +27 -11
- package/lib/CMCManager.js.map +1 -1
- package/lib/{index.d.ts → utils.d.ts} +1 -1
- package/lib/utils.d.ts.map +1 -0
- package/lib/{index.js → utils.js} +1 -1
- package/lib/{index.js.map → utils.js.map} +1 -1
- package/package.json +5 -1
- package/lib/index.d.ts.map +0 -1
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
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
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`)
|