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

request-partial

v0.1.0

Published

mikeal/request with partial applicable options.

Downloads

2

Readme

REQUEST-PARTIAL

This is simply mikeal/request with something that looks like partial application support for the options object. If you find yourself _.extend-ing or _.merge-ing your request options hash multiple times, such as when writing many test cases against a single HTTP url, for example, you might want to re-use the options object for each test.

API

The API is a bit hard to explain but actually very easy to use, so please bear with me.

The only function is exported from this module and is simply a wrapper around the original request function. If called normally, then it will behave normally. However, if the callback is omitted, it is assumed that you are building up the request and thus will return a copy of itself which, otherwise, will behave exactly the same way but with a modified default options (the one you've just given it). You can call the resulting function to modify the options hash further and further and when you are ready, you can simply pass in a single callback function and the original mikeal/request function will be called with all the options passed in thus far and the callback.

request(options, callback)

Effectively the same request function as require('request').

partial = request(options)

Returns a function that behaves just like require('request') but with defaults modified to match the given options.

You can call the resulting function with another options hash again to modify the default values further. The new function instance will be independent from the original function (out-of-place modification) so it can be reused.

result = partial(function(e, response, body) { })

Runs require('request') with all given options value combined. The options given thus far will be merged using lodash.merge.

MOCHA EXAMPLE

var request = require('request-partial');

describe('home page', function() {
  var req = request({ uri: '/' });

  describe('GET', function() {
    var get = req({ method: 'GET' });

    // tests
  });

  describe('POST', function() {
    var post = req({ method: 'POST' });

    describe('with invalid JSON body', function() {
      var invalidReq = post({ body: { } });

      // tests
    });

    describe('with valid JSON body', function() {
      var validReq = post({ body: { valid: true } });

      // tests
    });
  });
});

LICENSE

3-clause BSD, see the full text in the LICENSE file.