const axios = require("axios"); const renderError = (message) => { return ` Something went wrong! file an issue at https://git.io/JJmN9 ${message} `; }; // https://stackoverflow.com/a/48073476/10629172 function encodeHTML(str) { return str.replace(/[\u00A0-\u9999<>&](?!#)/gim, function (i) { return "&#" + i.charCodeAt(0) + ";"; }); } function kFormatter(num) { return Math.abs(num) > 999 ? Math.sign(num) * (Math.abs(num) / 1000).toFixed(1) + "k" : Math.sign(num) * Math.abs(num); } function isValidHexColor(hexColor) { return new RegExp( /^([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4})$/ ).test(hexColor); } function request(data, headers) { return new Promise((resolve, reject) => { axios({ url: "https://api.github.com/graphql", method: "post", headers: { ...headers, }, data, }) .then((response) => resolve(response)) .catch((error) => reject(error)); }); } module.exports = { renderError, kFormatter, encodeHTML, isValidHexColor, request, };