UNPKG

gh-star-fetch

Version:

Fetch all the starred repositories for a GitHub user

37 lines (36 loc) 1.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createClient = void 0; const got_1 = __importDefault(require("got")); function wait(time) { return new Promise((resolve) => { const tid = setTimeout(() => { resolve(); clearTimeout(tid); }, time); }); } function rand(min, max) { // min and max included return Math.floor(Math.random() * (max - min + 1) + min); } const DEFAULT_OPTIONS = { prefixUrl: 'https://api.github.com', responseType: 'json', hooks: { beforeRequest: [ async () => { // reduce rate limits await wait(rand(10, 25)); }, ], }, }; const client = got_1.default.extend(DEFAULT_OPTIONS); const createClient = (opts) => { return client.extend(opts || {}); }; exports.createClient = createClient;