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

gofer-js

v0.1.3

Published

A powerful, flexible JavaScript AJAX library

Downloads

6

Readme

Build Status

gofer-js

go·fer - noun (/ˈɡōfər/) a person who runs errands

Gofer is a JavaScript powerful AJAX tool set for creating and executing

go.get('people').then(result => {
    
    // handle the result
    
}).catch(error => {
    
    // handle the error
    
})

Configuration

go.configure({
    onerror : function(result) {
      
        showError(result.message, result.xhr);
        
    },
    onprogress : function (result) {
        
        if (result instanceof Object) {
            showProgressDialog(result.message);
        } else {
            hideProgressDialog();
        }
        
    },
    timeout : 10000,
    urlPrefix : '/rs'
});

| Property | Type | Description | | -------- | -------- | -------- | | timeout | number | the number of milliseconds to wait for a response | | urlPrefix | string | the path prefix. Use to append all requests with a common root path | | onerror | function | global function to call when an error occurs in a request | | onprogress | function | global function to call when a request is executing (called on start and end) |

Options

go.get('customers', {
    block : true,
    cache : false,
    content : 'json',
    headers : {
        'Accept-Encoding' : 'utf-8'
    },
    message : 'Getting customers...',
    silent : true,
    type : 'json'
})

Proxies

Gopher includes the ability to create proxies (much like RESTEasy)

let customerProxy = go.createProxy({
    path: '/customers',
    endpoints: {
        getAllCustomers: {},
        getCustomerWithId: {
            path: '/{id}',
            options: {
                cache: true
            }
        },
        saveCustomer: {
            method: 'post'
        }
    }
});

// call the proxy method 

customerProxy.getCustomerWithId({ id : 102 }).then (result => { /* ... */ });

// you can also call the method with just arguments
// they will be added sequentially, as specified in the path

customerProxy.getCustomerWithId(102).then(result => { /* ... */ });

Data Mappers

Data mappers provide serializers and deserializers for AJAX data. Mappers comprise of two methods: serialize and deserialize. Included are mappers for JSON, plain text, and XML.

let MyJSONMapper = {
    serialize: function(data) {
        return JSON.stringify(data);
    },
    deserialize: function(data) {
        return (data) ? JSON.parse(data) : null;
    }
};

// add the mapper to the registry

go.mappers.add('json', MyJSONMapper, [ 'application/json', 'text/json' ]);

Handling the Result

go.get('test').then(result => {

    result.xhr // the XMLHttpRequest
    result.data // the result data

}).catch(error => {
    
    error.message // the message
    error.xhr // the XMLHttpRequest
    
});

Methods

go.get(url, options)

Performs a GET request on the specified URL

go.post(string url, Object|string|number data, ?Object options)

Performs a POST request

go.put(url, data, options)

Performs a PUT request

go.del(url, options)

Performs a DELETE request

go.head(url, options)

Performs a HEAD request

go.fetch(url)

Fetches a resource relative to the current location