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

@lakca/superagent-toolkit

v1.0.0

Published

superagent plugin, providing frequently used tools, like reporting message of current request, directly retrieving specific property of response, etc.

Downloads

8

Readme

superagent-toolkit

Superagent plugin, providing frequently used tools, like reporting message of current request, directly retrieving specific property of response, etc.

Usage

Agent

const superagent = require('superagent')
const toolkit = require('@lakca/superagent-toolkit')

const agent = new superagent.Agent()

agent.use(toolkit(options))

agent
  .get('/test')
  .configure('...', '...') // change config

General

const superagent = require('superagent')
const toolkit = require('@lakca/superagent-toolkit')

superagent
  .get('/test')
  .use(toolkit(options))

Options

options.configure {function}

Set configure function, which can be called to change config later.

options.report {(error: Error, message: string, response: superagent.Response): void}

Function to receive message of request.

Note: it will benefit from using this function for global notification of request status.

options.clientError {true|string|string[]|function}

Dealing with 4xx except 401 http code. If value is:

  • true, report message retrieved using config.messageProperty;
  • string, report message using the string instead;
  • string[], report message using ths first not nullable(!= null) property retrieving via the array element one by one, such as ['body.message', 'header.statusMessage'];
  • function, report message using returned value if which is not void.

options.serverError {true|string|string[]|function}

Dealing with 5xx http code. Similar as config.clientError.

options.unauthorized {true|string|string[]|function}

Dealing with 401 http code. If value is:

  • true, reload current window;
  • string, redirect using the string;
  • string[], redirect using ths first not nullable(!= null) property retrieving via the array element one by one, such as ['body.location'];
  • function, redirect using returned value if which is not void, so you can provide your own redirection in the function without returning value.

options.messageProperty {string=res.statusMessage}

Report message property.

when http code is 2xx, using this to retrieve message.

also, this is the default message property for true value of config.clientError and config.serverError.

Note: support descendant property, such as body.message

options.returnProperty {string}

Response property expected to be returned instead of the whole response object.

Note: support descendant property, such as body.data

options.swallowError {boolean=false}

Silence error, no request/response error will be thrown since superagent does that by default.

Note: this is useful when we handle request status by general handler config.report, then focusing on handling business data in dealing with your business logic.

options.debug {boolean=false}

log to console.

options.prefix {string}

options.suffix {string}

options.jsonp {object}

Read more in superagent-jsonp

options.jsonp.callbackParam {string=callback}

options.jsonp.callbackName {string}

options.jsonp.timeout {number=1000}

LICENSE

MIT