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

rip-hunter

v1.3.3

Published

JS utilities for AJAX and GraphQL

Downloads

25

Readme

RipHunter

JS utilities for GraphQL

RipHunter is a small utility to parse objects formatted for GraphQL requests as well as use fetch to send query and mutation requests, returning a promise. Some helpers include sending an authorization token as well as custom headers.

npm version Travis npm downloads Issues MIT license

Installation

Using npm:

$ npm install rip-hunter

###App Usage Then with a module bundler like webpack that supports either CommonJS or ES2015 modules, use as you would anything else:

import {Hunter} from 'rip-hunter';

How to use

Example:

import {Hunter} from 'rip-hunter';

const AppActions = {
  getData: () => {
    // Variables
    const url = 'http://www.example.com/graphql';
    const gql = '{ app { ping } }';
    
    // Query data
    return Hunter.query(url, gql)
      .then(results => {
        console.log(results);
        // Assuming the results will return the JSON object, {status: 'ok'}
        // Output: {status: 'ok'}
      })
      .catch(error => {
        // ApiError will be returned if any problems occur.
      });
  },

  updateData: () => {
    // Variables
    const url = 'http://www.example.com/graphql';
    const data = {hello: 'world'};
    const gql = `{ user { update(data: ${Hunter.toGQL(data)}) } }`;
    
    // Mutate data
    return Hunter.mutation(url, gql)
      .then(results => {
        console.log(results);
        // Assuming the results will return the JSON object, {id: 'test', hello: 'world'}
        // Output: {id: 'test', hello: 'world'}
      })
      .catch(error => {
        // ApiError will be returned if any problems occur.
      });
  }
}

API

Formatting

toGQL(data)

Parses an immutable object, JSON object, string, or number into a GraphQL formatted string. This string is used when sending variables in a request.

  • [data] (* Any *): An immutable object, JSON object, string or number to format for use with a GQL request.
Returns

A string formatted for use with GQL.

Events

on(eventType, data)

Adds an event listener. The only event emitted is when an error occurs. The error event is rip_hunter_error.

  • [eventType] (String): Event to subscribe for store updates.
  • [listener] (Function): The callback to be invoked any time an action has been dispatched.

off(eventType, data)

Removes an event listener.

  • [eventType] (String): Event to unsubscribe.
  • [listener] (Function): The callback associated with the subscribed event.

AJAX

ajax(url, method, params, options)

AJAX request.

  • [url] (String): URL to send the request. Must be an absolute url.
  • [method] (String): The HTTP method for the request.
  • [params] (Object): Data to be sent with the request. Params will be converted to a query string for GET methods.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

get(url, params, options)

Server request using HTTP GET.

  • [url] (String): URL to send the request. Must be an absolute url.
  • [params] (Object): Data to be sent with the request.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

post(url, params, options)

Server request using HTTP POST.

  • [url] (String): URL to send the request. Must be an absolute url.
  • [params] (Object): Data to be sent with the request.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

put(url, params, options)

Server request using HTTP PUT.

  • [url] (String): URL to send the request. Must be an absolute url.
  • [params] (Object): Data to be sent with the request.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

del(url, params, options)

Server request using HTTP DEL.

  • [url] (String): GraphQL server endpoint. Must be an absolute url.
  • [params] (Object): Data to be sent with the request.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

GraphQL

query(url, body, options)

Queries a GraphQL server.

  • [url] (String): GraphQL server endpoint. Must be an absolute url.
  • [body] (String): GraphQL query.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.

mutation(url, body, token, headers)

Modifies data on a GraphQL server.

  • [url] (String): GraphQL server endpoint. Must be an absolute url.
  • [body] (String): GraphQL query.
  • [options] (Object): Rip Hunter options.
    • [headers] (Object): Overwrite the default headers.
    • [immutable] (Boolean): Converts result to an Immutable object if set to true. Default: false.
    • [token] (String): Add an Authorization header with the value Bearer [token].
Returns

A promise with either the response data or ApiError.