UNPKG

@fraserdarwent/xapi-node

Version:

This project is made possible to get data from Forex market, execute market or limit order with NodeJS/JS through WebSocket connection

35 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseLogin = void 0; const fs = require("fs"); function parseLogin(loginJsonFile) { if (!fs.existsSync(loginJsonFile)) { throw `${loginJsonFile} is not exists.`; } let json = {}; try { json = JSON.parse(fs.readFileSync(loginJsonFile).toString().trim()); } catch (e) { throw `${loginJsonFile} is not valid json file\n${e}`; } if (typeof (json) !== 'object') { throw `${loginJsonFile} is not valid json file\n${typeof (json)}`; } const { accountId, password, type, rateLimit, host, appName } = json; if (typeof (accountId) !== 'string' || typeof (password) !== 'string' || typeof (type) !== 'string' || !['undefined', 'number'].includes(typeof (rateLimit)) || !['undefined', 'string'].includes(typeof (host)) || !['undefined', 'string'].includes(typeof (appName)) || Object.keys(json).length > 6) { throw `${loginJsonFile} is not valid`; } if (['real', 'demo'].every(x => x !== type.toLowerCase())) { throw `${loginJsonFile} not contains valid type (it should be 'real' or 'demo')`; } return { accountId, password, type: type.toLowerCase(), rateLimit, host, appName }; } exports.parseLogin = parseLogin; //# sourceMappingURL=parseLogin.js.map