npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reqs-q

v1.2.3

Published

reqs-q is a simple and lightweight JavaScript library to help you control the order of requests

Downloads

5

Readme

reqs-q

reqs-q is a simple and lightweight JavaScript library to help you control the order of requests.

Live example

Installation

npm install reqs-q

or

yarn add reqs-q

Usage

  • Base

    import { RequestsQueueCore } from 'reqs-q';
    
    const requestsQueue = new RequestsQueueCore();
    
    const myURL = 'baseUrl';
    const myEndpoints = ['firstEndpoint', 'secondEndpoint'];
    
    const results = myEndpoints.map(async endpoint => {
      const result = await requestsQueue.request(() =>
        fetch(`${myURL}/${endpoint}`).then(r => r.json()),
      );
      return result.response;
    });
  • Advanced

    import {
      RequestsQueue,
      RequestModel,
      QueueLogger,
      QueueStoreManager,
      stores,
      priorities,
    } from 'reqs-q';
    
    function sendRequest(endpoint) {
      const newRequest = new RequestModel({
        callback: () => fetch(`${myURL}/${endpoint}`).then(r => r.json()),
        timeout: 5000,
        retryAfter: 2000,
        retriesCount: 3,
        priority: priorities.high,
        storeData: {
          actionPath: sendRequest.name,
          args: [...arguments],
        },
      });
    
      requestsQueue.request(newRequest).then(console.log);
    }
    
    const myApiManager = {
      sendRequest,
    };
    const myURL = 'baseUrl';
    const myEndpoints = ['firstEndpoint', 'secondEndpoint'];
    
    const requestsQueue = new RequestsQueue({
      logger: new QueueLogger({ saveLogs: true, showLogs: true }),
    
      // using this feature may be not safe.
      storeManager: new QueueStoreManager({
        store: Stores.LocalStorage,
        restoreObject: myApiManager,
        showWarn: true,
      }),
    });
    
    for (const enpdoint of myEndpoints) {
      myApiManager.sendRequest(endpoint);
    }

API

  • RequestsQueueCore

    • RequestsQueueCore.constructor
      • Creates new instance of RequestsQueueCore.
      • RequestsQueueCore parameters.
        showErrors?: boolean // default is true
    • RequestsQueueCore.prototype.request(request: RequestModel | (...args: any[]) => Promise<any>): Promise<RequestModel>
      • Adds provided request to the queue.
    • Lifecycle hooks.
      • // 1
        onRequestAdd(request: RequestModel) {}
        // 2
        beforeRequestHandle() {}
        // 3
        onRequestStartExecute(request: RequestModel) {}
        // 4
        onRequestProgress(request: RequestModel, retriesDone: number) {}
        // 5
        onRetry(request: RequestModel, retriesDone: number) {}
        // 6
        onRequestFail(request: RequestModel) {}
        onRequestSuccess(request: RequestModel) {}
        // 7
        onRequestDone(request: RequestModel) {}
        // 8
        afterRequestHandle() {}
        // 9
        onQueueEmpty() {}
  • RequestsQueue (extends RequestsQueueCore)

    • RequestsQueue.constructor
      • Creates new instance of RequestsQueue.
      • RequestsQueue parameters.
        logger?: QueueLogger // default is null
        storeManager?: QueueStoreManager // default is null
        showErrors?: boolean // default is true
    • RequestsQueue.prototype.queue: RequestsQueue[]
      • Returns read-only requests queue.
    • RequestsQueue.prototype.logs: Log[]
      • Returns read-only logs.
    • RequestsQueue.prototype.save(queue: RequestModel[]): void
      • Saves queue with QueueStoreManager.
    • RequestsQueue.prototype.load(): BaseStoreData[]
      • Loads queue with QueueStoreManager.
    • RequestsQueue.prototype.restart(): Promise<any[]>
      • Restarts queue with QueueStoreManager.
  • RequestModel

    • RequestModel.constructor
      • Creates new request that can be submitted to the RequestsQueue.
      • RequestModel Constructor parameters.
        callback: () => Promise<any | void>
        callback: () => Promise<any>
        timeout?: number // default is 15000 (ms)
        priority?: Priorities | number // default is 1
        id?: number | string // default is random string
        retryAfter?: number | null // default is null
        retriesCount?: number | null // default is null
        storeData?: StoreData // can be used only with `QueueStoreManager`
  • QueueLogger

    • QueueLogger.contructor
      • QueueLogger constructor parameters.
        logLimit?: number // default is 50
        saveLogs?: boolean // default is false
        showLogs?: boolean // default is true
    • QueueLogger.prototype.logs: Log[]
      • Returns saved logs.
  • QueueStoreManager

    • QueueStoreManager.contructor
      • QueueStoreManager constructor parameters.
        // Object whose methods should be called after the queue is restored.
        restoreObject?: Record<string, any>
        store?: Stores // default is 'localStorage'
        showWarn?: boolean // default is true
        shouldEncode?: boolean // default is true
    • QueueStoreManager.prototype.save(queue: RequestModel[]): void
      • Saves queue to chosen storage.
    • QueueStoreManager.prototype.load(): { actionPath: string, args: any[] }[]
      • Loads queue from chosen storage.
    • QueueStoreManager.prototype.restart(): Promise<any[]>
      • Loads queue from storage and restarts it.

License

MIT