const isNode = typeof process === "object"; const $get = (url: string, cb: Function): void => { const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (req.readyState === 4 && req.status === 200) { cb(req.responseText); } }; req.open("GET", url, true); req.send(null); }; const $post = (url: string, data: any, cb: (...args: any[]) => void): void => { const req = new XMLHttpRequest(); req.onreadystatechange = () => { if (req.readyState === 4 && req.status === 200) { cb(JSON.parse(req.responseText)); } }; req.open("POST", url); req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); req.setRequestHeader("X-Requested-With", "XMLHttpRequest"); req.send(JSON.stringify(data)); }; export default { get: (url: string): Promise => { return new Promise((resolve) => { $get(url, (response) => resolve(response)); }); }, post: (url: string, data: Object): Promise => { return new Promise((resolve) => { $post(url, data, (response) => resolve(response)); }); }, };