Socket
Socket
Sign inDemoInstall

crypto-convert

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crypto-convert - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

dist/crypto-convert.node.min.js
/*! For license information please see crypto-convert.node.min.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("form-data"),require("node-fetch")):"function"==typeof define&&define.amd?define(["form-data","node-fetch"],e):"object"==typeof exports?exports.convert=e(require("form-data"),require("node-fetch")):t.convert=e(t["form-data"],t["node-fetch"])}(this,(function(t,e){return r={844:function(t,e,r){var n,i;function a(t,e,r,n){function i(t){return null==t}function a(t){for(var e of t)return!1;return!0}function o(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,r,i){return t(e,r).then((async function(t){if(n.parseResponse){var e={},r=t.headers.get("Content-Type");e={status_code:t.status,status:t.status,statusText:t.statusText,headers:t.headers};try{r&&new RegExp("application/json").test(r)?e.json=await t.json():e.text=await t.text()}catch(t){console.warn(t)}var a=t.ok?"Success.":"Something went wrong.";e.message=e.json&&e.json.message?e.json.message:a}else e=t;return t.ok?"function"==typeof i?i(e):e:!(n.hasOwnProperty("errors")&&!n.errors)&&Promise.reject(e)}))}function c(t,e){var r={[e=e||"Wrape"]:function(n){if(!(this instanceof r[e]))throw new Error("You must initalize this object using 'new' command.");Object.assign(this,t),this.def_values=n;var i=function(t){if(this instanceof i)throw new Error("You can't initalize this object.");this.def_values=t}.bind(this);return this.set=i,this}};return r[e]}function p(t){t.method="string"==typeof t.method?t.method.toUpperCase():"GET";var r={form:"multipart/form-data",url:"application/x-www-form-urlencoded",json:"application/json"},c=Object.values(r);t.enctype=r[t.enctype]||(c.includes(t.enctype)?t.enctype:c[0]);var p=["headers","body","query","path"],u={POST:"body",GET:"query"};return async function(r){var f=`${n.base}${t.path}`,h={method:t.method,headers:n.defaultHeaders,agent:n.agent},l=Object.keys(t.params),d=Array.from(arguments);d.length>1?r=d.reduce((function(t,e,r){return l[r]?(t[l[r]]=e,t):t}),{}):d[0]instanceof e?(r={},d[0].forEach((function(t,e){r[e]=t}))):r=1!=d.length||1!=l.length||!d[0]||d[0][l[0]]||d[0]instanceof e?r||{}:{[l[0]]:d[0]},this.def_values=this.def_values||{};var y={"multipart/form-data":function(){return new e},"application/x-www-form-urlencoded":function(){return new URLSearchParams},"application/json":function(){return{append:function(t,e){return this[t]=e},toString:function(){return JSON.stringify(this)}}}},m=y[t.enctype](),v=new URLSearchParams;for(var w in t.params){var g=t.params[w],S=r[w]||this.def_values[w]||n.defaultParamValues[w]||g.default,T=g.name||w;if(g.required&&i(S))throw(E=new Error(g.help||`The '${w}' field is required.`)).field=E.param=w,E;if(!i(S)){if("function"==typeof g.formatter||"function"==typeof g.format){var b=g.format||g.formatter;S=b(S)}if(g.validate){var E,x="function"==typeof g.validate?g.validate(S):new RegExp(g.validate).test(S);if(!x)throw(E=new Error(g.help||`The '${w}' field is invalid.`)).field=E.param=w,E}var A="string"==typeof g.location?g.location.toLowerCase():u[h.method];if(!A||!p.includes(A))throw new Error(`Invalid location for '${w}' field.`);"headers"!=A?"body"!=A?"query"!=A?"path"==A&&(f=f.replace(new RegExp(":"+o(w)),S)):v.append(T,S):m.append(T,S):(h.headers=h.headers||{},h.headers[T]=S)}}var D=v.toString();return D&&(f=`${f}?${D}`),(m.keys&&!a(m.keys())||m.getLengthSync&&m.getLengthSync()>0||t.enctype==c[2]&&m.toString())&&(h.body=t.enctype==c[0]?m:m.toString()),h.body&&t.enctype!==c[0]&&(h.headers=h.headers||{},h.headers["Content-Type"]=t.enctype),s(f,h,t.response)}}return r=r||{},n=Object.assign({base:"",defaultHeaders:{},defaultParamValues:{},parseResponse:!0,agent:!1},n),function t(e,r,n){for(var i in r){var a=r[i];if(a&&"object"==typeof a)if(a.hasOwnProperty("path")){var o=a;if(e._ne=!0,void 0!==e[i]){console.warn(`Skipping ${i} as it confilicts with another key in the object, avoid using keys like ('set') because they are reserved constructor words.`);continue}e[i]=p(o)}else e[i]=t({},a,i)}return e._ne?Object.assign(e,{set:c(e,n)}):e}({},r,!0)}"undefined"!=typeof self&&self,void 0===(i="function"==typeof(n=function(){const e=t.exports?r(786):window.fetch,n=t.exports?r(353):window.FormData;return e?n?a.bind(null,e,n):(console.warn("FormData is not installed. If you are using Node please install form-data."),!1):(console.warn("Fetch API is not installed. If you are using Node please install node-fetch."),!1)})?n.apply(e,[]):n)||(t.exports=i)},965:(t,e,r)=>{const n=r(844)({binance:{ticker:{method:"GET",path:"https://api.binance.com/api/v3/ticker/price",params:{},response:function(t){var e={USDC:"USD",TUSD:"USD"},r=Object.keys(e),n=t.json;return!(!n||!Array.isArray(n))&&n.reduce(((t,n,i)=>{for(t=t||{},c=0;c<r.length;c++)n.symbol=n.symbol.endsWith(r[c])||n.symbol.startsWith(r[c])?n.symbol.replace(r[c],e[r[c]]):n.symbol;return t[n.symbol]=parseFloat(n.price),t}),{})}}},bitfinex:{ticker:{method:"GET",path:"https://api-pub.bitfinex.com/v2/tickers?symbols=ALL",params:{},response:function(t){var e={BAB:"BCH",DSH:"DASH"},r=t.json;return!(!r||!Array.isArray(r))&&r.reduce(((t,r,n)=>(t=t||{},7==r[0].length&&r[0].startsWith("t")&&(t[[r[0].substring(1,4),r[0].substring(4,r[0].length)].map((t=>e[t]||t)).join("")]=parseFloat(r[7])),t)),{})}}},okex:{ticker:{method:"GET",path:"https://www.okex.com/api/spot/v3/instruments/ticker",params:{},response:function(t){var e={USDC:"USD",USDT:"USD",USDK:"USD"},r=t.json;return!(!r||!Array.isArray(r))&&r.reduce(((t,r,n)=>{t=t||{};var[i,a]=r.instrument_id.split("-").map((t=>e[t]||t));return t[i+a]=parseFloat(r.last),t}),{})}}},coinbase:{ticker:{method:"GET",path:"https://api.pro.coinbase.com/products/stats",params:{},response:function(t){var e=t.json;if(!e||!Array.isArray(e))return!1}}},coinmarketcap:{top:{method:"GET",path:"https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active",params:{limit:{default:100}},response:function(t){var e=t.json;return!!(e&&e.data&&Array.isArray(e.data.cryptoCurrencyMap))&&e.data.cryptoCurrencyMap.map((t=>t.symbol))}}},fiat:{all:{method:"GET",path:"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",params:{},response:function(t){var e=t.text,r=e.match(/(?<=currency=["'])([A-Za-z]+)/gi),n=e.match(/(?<=rate=["'])([.0-9]+)/gi),i=r.reduce(((t,e,r)=>({...t,[e]:n[r]})),{});return i.EUR=1,i}}},coinconvert:{ticker:{method:"GET",path:"https://api.coinconvert.net/ticker",params:{},response:function(t){return t.json||!1}},list:{method:"GET",path:"https://api.coinconvert.net/list",params:{},response:function(t){return t.json||!1}}}},{errors:!1});t.exports=n},138:(t,e,r)=>{const n=r(736),o=n.list.crypto,s=n.list.fiat;function c(t,e="USD"){var r=n.data.crypto[t+e];return r||(r=!!n.data.crypto[e+t]&&1/n.data.crypto[e+t]),r}var p=function(){var t=o.concat(s),e={},r=function(t,e){t=t;var i=e;return function(e){if(function(t){for(var e in t)return!1;return!0}(n.data.crypto))return!1;var a=n.data.fiat;if(i==t)return e;if(o.includes(t)&&o.includes(i))return this.exchangePrice=c(t,i),this.exchangePrice||(this.exchangePrice=r("USD",i)(r(t,"USD")(1))),parseFloat(Number(this.exchangePrice*parseFloat(e)).toFixed(8));if(a[t]&&a[i])return parseFloat(Number(parseFloat(e)/a[t]*a[i]).toFixed(2));var s=function(t){var e=c(t);return e||(e=r("BTC","USD")(c(t,"BTC"))||r("ETH","USD")(c(t,"ETH"))),e};return a[i]?(this.usdPrice=s(t),this.exchangePrice=this.usdPrice/a.USD*a[i],parseFloat(Number(this.exchangePrice*parseFloat(e)).toFixed(8))):!!a[t]&&(this.usdPrice=s(i),this.exchangePrice=this.usdPrice/a.USD*a[t],parseFloat(Number(parseFloat(e)/this.exchangePrice).toFixed(8)))}};for(i=0;i<t.length;i++){var p=t[i];for(a=0;a<t.length;a++){var u=t[a];e[p]||(e[p]={}),e[p][u]=r(p,u)}}return e.list={crypto:o,fiat:s},e.ticker={get crypto(){return n.data.crypto},get fiat(){return n.data.fiat}},e.from=function(t){return this.coin=t.toUpperCase(),this},e.from.prototype.to=function(t){return this.currency=t.toUpperCase(),this},e.from.prototype.amount=function(t=1){return!!(this.coin&&this.currency&&e[this.coin]&&e[this.currency])&&e[this.coin][this.currency](t)},e}();t.exports=p},736:(t,e,r)=>{const n=r(965);function i(t={}){this.list={crypto:["BTC","ETH","USDT","XRP","DOT","ADA","LTC","LINK","BCH","BNB","XLM","USDC","UNI","WBTC","DOGE","AAVE","BSV","EOS","XMR","XEM","TRX","XTZ","THETA","SNX","ATOM","VET","SUSHI","DAI","NEO","MKR","COMP","CRO","HT","BUSD","SOL","LEO","MIOTA","FTT","CEL","EGLD","DASH","UMA","AVAX","FIL","ZEC","LUNA","GRT","YFI","KSM","REV","ETC","DCR","ALGO","ZIL","CHSB","WAVES","NEAR","LRC","HBAR","REN","OMG","NEXO","RUNE","RENBTC","VGX","CELO","CRV","1INCH","ZRX","ONT","HEDG","BAT","NANO","HUSD","ICX","BTT","QNT","DGB","SC","TUSD","ZEN","OKB","RSR","ALPHA","QTUM","STX","FTM","AMPL","FUN","KNC","ENJ","IOST","MANA","XVG","UST","OCEAN","BTCB","BNT","PAX","BAND"],fiat:["USD","JPY","BGN","CZK","DKK","GBP","HUF","PLN","RON","SEK","CHF","ISK","NOK","HRK","RUB","TRY","AUD","BRL","CAD","CNY","HKD","IDR","ILS","INR","KRW","MXN","MYR","NZD","PHP","SGD","THB","ZAR","EUR"]},this.data={crypto:{},fiat:{USD:1}},this.options={multiple_fiats:!0,crypto_interval:t.crypto_interval||5e3,fiat_interval:t.fiat_interval||36e5},this.log=function(){return!1}}i.prototype.crypto=async function(){this.log("Updating crypto...",this.data.crypto);var t=await n.binance.ticker()||{},e=await n.bitfinex.ticker()||{},r=await n.okex.ticker()||{};return this.data.crypto={...r,...e,...t},this},i.prototype.fiat=async function(){this.log("Updating fiat...",this.data.fiat);var t=await n.fiat.all();return this.data.fiat=t||this.data.fiat,this},i.prototype.lists=async function(){this.log("Updating list...",this.list.crypto);var t=await n.coinmarketcap.top();return this.list.crypto=t||this.list.crypto,this},i.prototype.browserTicker=async function(){var t=await n.coinconvert.ticker();return this.data=t,this},i.prototype.browserList=async function(){var t=await n.coinconvert.list();return this.list=t,this},i.prototype.runBrowser=function(){return this.browserList(),this.browserTicker(),this.crypto_worker=setInterval(this.browserTicker.bind(this),this.options.crypto_interval),this},i.prototype.runServer=function(){return this.lists(),this.crypto(),this.fiat(),this.crypto_worker=setInterval(this.crypto.bind(this),this.options.crypto_interval),this.fiat_worker=setInterval(this.fiat.bind(this),this.options.fiat_interval),this},i.prototype.run=function(){return"undefined"!=typeof window&&window.navigator&&window.document?this.runBrowser():this.runServer()},i.prototype.stop=function(){return clearInterval(this.crypto_worker),clearInterval(this.fiat_worker),this};const a=(new i).run();t.exports=a},353:e=>{"use strict";e.exports=t},786:t=>{"use strict";t.exports=e}},n={},function t(e){if(n[e])return n[e].exports;var i=n[e]={exports:{}};return r[e].call(i.exports,i,i.exports,t),i.exports}(138);var r,n}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("form-data"),require("node-fetch")):"function"==typeof define&&define.amd?define(["form-data","node-fetch"],e):"object"==typeof exports?exports.convert=e(require("form-data"),require("node-fetch")):t.convert=e(t["form-data"],t["node-fetch"])}(this,(function(t,e){return r={844:function(t,e,r){var n,i;function a(t,e,r,n){function i(t){return null==t}function a(t){for(var e of t)return!1;return!0}function o(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function s(e,r,i){return t(e,r).then((async function(t){if(n.parseResponse){var e={},r=t.headers.get("Content-Type");e={status_code:t.status,status:t.status,statusText:t.statusText,headers:t.headers};try{r&&new RegExp("application/json").test(r)?e.json=await t.json():e.text=await t.text()}catch(t){console.warn(t)}var a=t.ok?"Success.":"Something went wrong.";e.message=e.json&&e.json.message?e.json.message:a}else e=t;return t.ok?"function"==typeof i?i(e):e:!(n.hasOwnProperty("errors")&&!n.errors)&&Promise.reject(e)}))}function c(t,e){var r={[e=e||"Wrape"]:function(n){if(!(this instanceof r[e]))throw new Error("You must initalize this object using 'new' command.");Object.assign(this,t),this.def_values=n;var i=function(t){if(this instanceof i)throw new Error("You can't initalize this object.");this.def_values=t}.bind(this);return this.set=i,this}};return r[e]}function p(t){t.method="string"==typeof t.method?t.method.toUpperCase():"GET";var r={form:"multipart/form-data",url:"application/x-www-form-urlencoded",json:"application/json"},c=Object.values(r);t.enctype=r[t.enctype]||(c.includes(t.enctype)?t.enctype:c[0]);var p=["headers","body","query","path"],u={POST:"body",GET:"query"};return async function(r){var h=`${n.base}${t.path}`,f={method:t.method,headers:n.defaultHeaders,agent:n.agent},d=Object.keys(t.params),l=Array.from(arguments);l.length>1?r=l.reduce((function(t,e,r){return d[r]?(t[d[r]]=e,t):t}),{}):l[0]instanceof e?(r={},l[0].forEach((function(t,e){r[e]=t}))):r=1!=l.length||1!=d.length||!l[0]||l[0][d[0]]||l[0]instanceof e?r||{}:{[d[0]]:l[0]},this.def_values=this.def_values||{};var y={"multipart/form-data":function(){return new e},"application/x-www-form-urlencoded":function(){return new URLSearchParams},"application/json":function(){return{append:function(t,e){return this[t]=e},toString:function(){return JSON.stringify(this)}}}},m=y[t.enctype](),v=new URLSearchParams;for(var w in t.params){var g=t.params[w],b=r[w]||this.def_values[w]||n.defaultParamValues[w]||g.default,S=g.name||w;if(g.required&&i(b))throw(x=new Error(g.help||`The '${w}' field is required.`)).field=x.param=w,x;if(!i(b)){if("function"==typeof g.formatter||"function"==typeof g.format){var T=g.format||g.formatter;b=T(b)}if(g.validate){var x,U="function"==typeof g.validate?g.validate(b):new RegExp(g.validate).test(b);if(!U)throw(x=new Error(g.help||`The '${w}' field is invalid.`)).field=x.param=w,x}var E="string"==typeof g.location?g.location.toLowerCase():u[f.method];if(!E||!p.includes(E))throw new Error(`Invalid location for '${w}' field.`);"headers"!=E?"body"!=E?"query"!=E?"path"==E&&(h=h.replace(new RegExp(":"+o(w)),b)):v.append(S,b):m.append(S,b):(f.headers=f.headers||{},f.headers[S]=b)}}var A=v.toString();return A&&(h=`${h}?${A}`),(m.keys&&!a(m.keys())||m.getLengthSync&&m.getLengthSync()>0||t.enctype==c[2]&&m.toString())&&(f.body=t.enctype==c[0]?m:m.toString()),f.body&&t.enctype!==c[0]&&(f.headers=f.headers||{},f.headers["Content-Type"]=t.enctype),s(h,f,t.response)}}return r=r||{},n=Object.assign({base:"",defaultHeaders:{},defaultParamValues:{},parseResponse:!0,agent:!1},n),function t(e,r,n){for(var i in r){var a=r[i];if(a&&"object"==typeof a)if(a.hasOwnProperty("path")){var o=a;if(e._ne=!0,void 0!==e[i]){console.warn(`Skipping ${i} as it confilicts with another key in the object, avoid using keys like ('set') because they are reserved constructor words.`);continue}e[i]=p(o)}else e[i]=t({},a,i)}return e._ne?Object.assign(e,{set:c(e,n)}):e}({},r,!0)}"undefined"!=typeof self&&self,void 0===(i="function"==typeof(n=function(){const e=t.exports?r(786):window.fetch,n=t.exports?r(353):window.FormData;return e?n?a.bind(null,e,n):(console.warn("FormData is not installed. If you are using Node please install form-data."),!1):(console.warn("Fetch API is not installed. If you are using Node please install node-fetch."),!1)})?n.apply(e,[]):n)||(t.exports=i)},965:(t,e,r)=>{const n=r(844)({binance:{ticker:{method:"GET",path:"https://api.binance.com/api/v3/ticker/price",params:{},response:function(t){var e={USDC:"USD",TUSD:"USD"},r=Object.keys(e),n=t.json;return!(!n||!Array.isArray(n))&&n.reduce(((t,n,i)=>{for(t=t||{},c=0;c<r.length;c++)n.symbol=n.symbol.endsWith(r[c])||n.symbol.startsWith(r[c])?n.symbol.replace(r[c],e[r[c]]):n.symbol;return t[n.symbol]=parseFloat(n.price),t}),{})}}},bitfinex:{ticker:{method:"GET",path:"https://api-pub.bitfinex.com/v2/tickers?symbols=ALL",params:{},response:function(t){var e={BAB:"BCH",DSH:"DASH"},r=t.json;return!(!r||!Array.isArray(r))&&r.reduce(((t,r,n)=>(t=t||{},7==r[0].length&&r[0].startsWith("t")&&(t[[r[0].substring(1,4),r[0].substring(4,r[0].length)].map((t=>e[t]||t)).join("")]=parseFloat(r[7])),t)),{})}}},okex:{ticker:{method:"GET",path:"https://www.okex.com/api/spot/v3/instruments/ticker",params:{},response:function(t){var e={USDC:"USD",USDT:"USD",USDK:"USD"},r=t.json;return!(!r||!Array.isArray(r))&&r.reduce(((t,r,n)=>{t=t||{};var[i,a]=r.instrument_id.split("-").map((t=>e[t]||t));return t[i+a]=parseFloat(r.last),t}),{})}}},coinbase:{ticker:{method:"GET",path:"https://api.pro.coinbase.com/products/stats",params:{},response:function(t){var e=t.json;if(!e||!Array.isArray(e))return!1}}},coinmarketcap:{top:{method:"GET",path:"https://api.coinmarketcap.com/data-api/v3/map/all?listing_status=active",params:{limit:{default:100}},response:function(t){var e=t.json;return!!(e&&e.data&&Array.isArray(e.data.cryptoCurrencyMap))&&e.data.cryptoCurrencyMap.map((t=>t.symbol))}}},fiat:{all:{method:"GET",path:"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml",params:{},response:function(t){var e=t.text,r=e.match(/(?<=currency=["'])([A-Za-z]+)/gi),n=e.match(/(?<=rate=["'])([.0-9]+)/gi),i=r.reduce(((t,e,r)=>({...t,[e]:n[r]})),{});return i.EUR=1,i}}},coinconvert:{ticker:{method:"GET",path:"https://api.coinconvert.net/ticker",params:{},response:function(t){return t.json||!1}},list:{method:"GET",path:"https://api.coinconvert.net/list",params:{},response:function(t){return t.json||!1}}}},{errors:!1});t.exports=n},138:(t,e,r)=>{const n=r(736),o=n.list.crypto,s=n.list.fiat;function c(t,e="USD"){var r=n.data.crypto[t+e];return r||(r=!!n.data.crypto[e+t]&&1/n.data.crypto[e+t]),r}var p,u,h,f=(p=o.concat(s),u={get isReady(){return n.isReady}},h=function(t,e){t=t;var r=e;return function(e){if(function(t){for(var e in t)return!1;return!0}(n.data.crypto))return!1;var i=n.data.fiat;if(r==t)return e;if(o.includes(t)&&o.includes(r))return this.exchangePrice=c(t,r),this.exchangePrice||(this.exchangePrice=h("USD",r)(h(t,"USD")(1))),parseFloat(Number(this.exchangePrice*parseFloat(e)).toFixed(8));if(i[t]&&i[r])return parseFloat(Number(parseFloat(e)/i[t]*i[r]).toFixed(2));var a=function(t){var e=c(t);return e||(e=h("BTC","USD")(c(t,"BTC"))||h("ETH","USD")(c(t,"ETH"))),e};return i[r]?(this.usdPrice=a(t),this.exchangePrice=this.usdPrice/i.USD*i[r],parseFloat(Number(this.exchangePrice*parseFloat(e)).toFixed(8))):!!i[t]&&(this.usdPrice=a(r),this.exchangePrice=this.usdPrice/i.USD*i[t],parseFloat(Number(parseFloat(e)/this.exchangePrice).toFixed(8)))}},function(){for(i=0;i<p.length;i++){var t=p[i];for(a=0;a<p.length;a++){var e=p[a];u[t]||(u[t]={}),u[t][e]=h(t,e)}}}(),u.set=function(t){n.update(t).restart()},u.ready=async function(){return n.isReady||await n.crypto(),u},u.list={crypto:o,fiat:s},u.ticker={get crypto(){return n.data.crypto},get fiat(){return n.data.fiat}},u.from=function(t){return this.coin=t.toUpperCase(),this},u.from.prototype.to=function(t){return this.currency=t.toUpperCase(),this},u.from.prototype.amount=function(t=1){return!!(this.coin&&this.currency&&u[this.coin]&&u[this.currency])&&u[this.coin][this.currency](t)},u);t.exports=f},736:(t,e,r)=>{const n=r(965);function i(t={}){this.lastUpdate=!1,this.isReady=!1,this.list={crypto:["BTC","ETH","USDT","XRP","DOT","ADA","LTC","LINK","BCH","BNB","XLM","USDC","UNI","WBTC","DOGE","AAVE","BSV","EOS","XMR","XEM","TRX","XTZ","THETA","SNX","ATOM","VET","SUSHI","DAI","NEO","MKR","COMP","CRO","HT","BUSD","SOL","LEO","MIOTA","FTT","CEL","EGLD","DASH","UMA","AVAX","FIL","ZEC","LUNA","GRT","YFI","KSM","REV","ETC","DCR","ALGO","ZIL","CHSB","WAVES","NEAR","LRC","HBAR","REN","OMG","NEXO","RUNE","RENBTC","VGX","CELO","CRV","1INCH","ZRX","ONT","HEDG","BAT","NANO","HUSD","ICX","BTT","QNT","DGB","SC","TUSD","ZEN","OKB","RSR","ALPHA","QTUM","STX","FTM","AMPL","FUN","KNC","ENJ","IOST","MANA","XVG","UST","OCEAN","BTCB","BNT","PAX","BAND"],fiat:["USD","JPY","BGN","CZK","DKK","GBP","HUF","PLN","RON","SEK","CHF","ISK","NOK","HRK","RUB","TRY","AUD","BRL","CAD","CNY","HKD","IDR","ILS","INR","KRW","MXN","MYR","NZD","PHP","SGD","THB","ZAR","EUR"]},this.data={crypto:{},fiat:{USD:1}},this.update(),this.log=function(){return!1}}i.prototype.update=function(t){return t=t||{},this.options={crypto_interval:isNaN(t.crypto_interval)?5e3:Math.min(1e3,t.crypto_interval),fiat_interval:isNaN(t.fiat_interval)?36e5:Math.min(5e3,t.fiat_interval),binance:!t.hasOwnProperty("binance")||t.binance,okex:!t.hasOwnProperty("okex")||t.okex,bitfinex:!t.hasOwnProperty("bitfinex")||t.bitfinex,onUpdate:t.onUpdate},this},i.prototype.crypto=async function(){this.log("Updating crypto...",this.data.crypto);var t=this.options.binance&&await n.binance.ticker()||{},e=this.options.bitfinex&&await n.bitfinex.ticker()||{},r=this.options.okex&&await n.okex.ticker()||{};return this.data.crypto={...r,...e,...t},(Object.keys(t).length>0||Object.keys(e).length>0||Object.keys(r).length>0)&&(this.lastUpdate=+new Date,"function"==typeof this.options.onUpdate&&this.options.onUpdate(this.data.crypto)),this},i.prototype.fiat=async function(){this.log("Updating fiat...",this.data.fiat);var t=await n.fiat.all();return this.data.fiat=t||this.data.fiat,this},i.prototype.lists=async function(){this.log("Updating list...",this.list.crypto);var t=await n.coinmarketcap.top();return this.list.crypto=t||this.list.crypto,this},i.prototype.browserTicker=async function(){var t=await n.coinconvert.ticker();return this.data=t,this},i.prototype.browserList=async function(){var t=await n.coinconvert.list();return this.list=t,this},i.prototype.runBrowser=async function(){return await this.browserList(),await this.browserTicker(),this.isReady=!0,this.crypto_worker=setInterval(this.browserTicker.bind(this),this.options.crypto_interval),this},i.prototype.runServer=async function(){return await this.lists(),await this.fiat(),await this.crypto(),this.isReady=!0,this.crypto_worker=setInterval(this.crypto.bind(this),this.options.crypto_interval),this.fiat_worker=setInterval(this.fiat.bind(this),this.options.fiat_interval),this},i.prototype.run=function(){return this.isRunning=!0,"undefined"!=typeof window&&window.navigator&&window.document?(this.runBrowser(),this):(this.runServer(),this)},i.prototype.stop=function(){return clearInterval(this.crypto_worker),clearInterval(this.fiat_worker),this.isReady=!1,this.isRunning=!1,this},i.prototype.restart=function(){return this.stop().run()};const a=(new i).run();t.exports=a},353:e=>{"use strict";e.exports=t},786:t=>{"use strict";t.exports=e}},n={},function t(e){if(n[e])return n[e].exports;var i=n[e]={exports:{}};return r[e].call(i.exports,i,i.exports,t),i.exports}(138);var r,n}));
{
"name": "crypto-convert",
"version": "1.0.1",
"version": "1.0.2",
"description": "Instantly convert cryptocurrency and get price information",

@@ -5,0 +5,0 @@ "main": "dist/crypto-convert.node.min.js",

@@ -15,22 +15,28 @@

## Installation
`npm i crypto-convert`
## Usage
```javascript
const convert = require("crypto-convert");
convert.BTC.USD(1);
convert.ETH.JPY(255);
convert.LINK.LTC(5);
convert.USD.CRO(100);
(async function(){
//More readable syntax
new convert.from("BTC").to("USD").amount(1);
//Cache is not yet loaded on application start
if(!convert.isReady){
await convert.ready();
}
```
convert.BTC.USD(1);
convert.ETH.JPY(255);
convert.LINK.LTC(5);
convert.USD.CRO(100);
//More readable syntax
new convert.from("BTC").to("USD").amount(1);
})();
## Installation
`npm i crypto-convert`
```
## For Browsers

@@ -45,1 +51,24 @@ ```html

## Configuration
```javascript
const convert = require("crypto-convert");
convert.set({
crypto_interval: 5000, //Crypto cache update interval, default every 5 seconds
fiat_interval: (60 * 1e3 * 60) //Fiat cache update interval, default every 1 hour
binance: true, //Use binance rates
bitfinex: true, //Use bitfinex rates
okex: true, //Use okex rates
onUpdate: (tickers)=> {}, //Call Hook on every crypto update
});
```
## API
Free public API, up to 50 req/s.
`https://api.coinconvert.net/convert/btc/usd?amount=1`
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc