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

molecularjs

v1.0.4

Published

Micro-library to make http request simply in the browser or with a NodeJs server.

Downloads

11

Readme

Molecular 'travis build' npm version Codacy Badge

Micro-library to make http request simply in the browser or with a NodeJs server.

Install

On nodejs

$ npm install molecularjs

On Bower

$ bower install molecularjs

Usage

With nodejs :

// First require the library
var Molecular = require('molecular');

Use Molecular like that

// Connect to your favorites APIs
Molecular.connect({
  'Github': 'https://api.github.com',
  'Slack' : 'http://api.slack.com'
});

// Set some options
// There are all options from the basic nodejs https module
Molecular.to('Github').setOptions({
  headers: {
    'user-agent': 'ArthurMialon'
  }
});

// Make a simply request to get some events
Molecular.to('Github').get('/users/arthurmialon/events')
  .progress(function(req) {
    console.log("request progress");
  })
  .success(function(data, req) {
    console.log(data, req);
  })
  .error(function(err, req) {
    console.log(err);
  });

In a browser :

Use it almost like in nodejs : You just have to import the file to your website

<!-- Import it to your website -->
<script src="molecular.js"></script>

Molecular API

More doc coming soon...

.connections

See all your connections to APIs

.connect(apis)

Parameters :

Name | Type ------------- | ------------- APIs | Object

Example :

Molecular.connect({
  'Github': 'https://api.github.com',
  'Slack' : 'https://api.slack.com'
});

.to(apiName)

Parameters :

Name | Type ------------- | ------------- apiName | String @return | Object

Example :

Molecular.to('ApiName')

.get(url, params)

Parameters :

Name | Type ------------- | ------------- url | String params | Object @return | Callback Object

Example :

Molecular.get('http://your/api/endpoints', {limit: 2, orderby: "id", sort: "desc"});

.post(url, data)

Parameters :

Name | Type ------------- | ------------- url | String data | Object @return | Callback Object

Example :

Molecular.post('http://your/api/endpoints', {});

.put(url, data)

Parameters :

Name | Type ------------- | ------------- url | String data | Object @return | Callback Object

Example :

Molecular.put('http://your/api/endpoints', {});

.delete(url)

Parameters :

Name | Type ------------- | ------------- url | String @return | Callback Object

Example :

Molecular.delete('http://your/api/endpoints');

.setMethod(name callback)

Parameters :

Name | Type ------------- | ------------- name | String callback | Function

Example :

Molecular.setMethod('methodName', function(arguments, callback) {
  // Do stuff and apply the callback
});

.setOptions(options)

Parameters :

Name | Type ------------- | ------------- options | Object

Example :

Molecular.setOptions({
  headers: {
    "ContentType": "Application/json"
  }
});

.sendRequest(method, path, data, options)

Parameters :

Name | Type ------------- | ------------- method | String path | String data | Object / Boolean options | Object @return | Callback Object

Example :

Molecular.sendRequest('GET', 'http://your/api/endpoint', false, {});

Advanced

You can simply add some methods to your connections

For example if I want to get the last commit from a specific repo (i.e: SailsJs)


// Set a new method to the api
Molecular.to('Github').setMethod('lasCommit', function(owner, repo, callback) {
  this.get('/repos/'+owner+'/'+repo+'/commits')
    .success(function(data) {
      // Add JSON.parse(data) in nodejs to data instead of data[0]
      callback.apply(this, [false, data[0]]);
    })
    .error(function(err) {
      callback.apply(this, [true, undefined]);
    });
});

// Get the last commit from sailsJs
Molecular.to('Github').lasCommit('balderdashy', 'sails', function(err, commit) {
  (err) ? console.error(err) : console.log(commit);
});

Next version 1.1

  • Support http & https
  • Better options management (JSON and default options etc...)
  • Call en error if status code >= 200 & < 300 for http module nodejs
  • Get the body response on error
  • Fixes on POST/PUT request
  • Fixes on options with xhr
  • Minified version for bower
  • Automatic JSON.parse on data