UNPKG

node-mexc-api

Version:

[![npm install node-mexc-api](https://nodei.co/npm/node-mexc-api.png?mini=true)](https://npmjs.org/package/node-mexc-api)

27 lines (23 loc) 995 B
import {isEmptyValue} from "./utils"; import {MissingParameterError} from "../error"; export const validateRequiredParameters = (paramObject: URLSearchParams) => { if (!paramObject || isEmptyValue(paramObject)) { throw new MissingParameterError(`Empty params ${JSON.stringify(Object.entries(paramObject))}`); } const emptyParams: string | string[] = []; Object.keys(paramObject).forEach((param) => { if (isEmptyValue(paramObject.get(param))) emptyParams.push(param); }); if (emptyParams.length) { throw new MissingParameterError(emptyParams); } }; export const hasOneOfParameters = (paramObject: URLSearchParams) => { if (!paramObject || isEmptyValue(paramObject)) { throw new MissingParameterError(`Empty params ${JSON.stringify(Object.entries(paramObject))}`); } const params = [...paramObject.values()]; if (params.every(isEmptyValue)) { throw new MissingParameterError([...paramObject.keys()]); } };