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

sdk

v0.5.0

Published

SDK factory, building SDK made easy

Downloads

7,837

Readme

logo sdk npm

SDK factory, building SDK made easy.

SDK module provides a easy and fast way to build a collection of APIs. user would config api routes, define which params will be injected into query params, and custom a callback wrapper of each route. make it sample and easy to handle API as make codes more reuseful.

Installation

$ npm install sdk

Example

To run examples provided. Try:

$ npm run examples

Or check out:

var SDK = require('sdk');

// APIs is a map with `shortcut` and request object,
// Which contains request.url, request.method.
var APIs = {
  // By default, the method is `GET`
  read: {
    url: '/example/read/{{name}}'
  },
  // Btw, String will be ok as well
  fetch: '/example/read/{{name}}',
  // Use `POST` instead
  update: {
    method: 'post',
    url: '/example/update'
  },
  // Absolute URI will not be joined to host URI.
  google: 'http://google.com'
};

// Rules is a map with a request.method as a key,
// Which contains a request.option object will be merged into a real request.
var rules = {
  // userId=303 will be inject to a real `GET` request 
  get: {
    qs: {
      userId: 303
    }
  },
  // token: 'abc' will be inject to a real `POST` request as form data.
  post: {
    form: {
      token: 'abc' 
    }
  }
}

// Init a new SDK instance with APIs and append some request rules to it.
var api = new SDK('http://my-api-server.com', APIs, rules);

And use a API like this way:

// => http://my-api-server.com/demo/read/123?b=2
var query = {
  name: 123,
  qs: {
    b: 2
  }
}

// Return a Promise instance
api.read(query).then({ body } => {
  console.log(body)
})

API

new SDK(host, routes, rules)

  • @host[String]: the host domain
  • @routes[Object]: a object contains every route of the sdk, including its URL, method, and callback function
  • @rules[Object]: a object contains rules which append or merged into query params.

SDK#rule(key, value)

Add a new rule to SDK instance

  • @key[String]: the key word of this rule, may be get,post or all
  • @value[Object]: the value of this rule, this very object will be merged in to query params,
  • for instance, qs object will be merged into query string. and form object will be merged into post form.

SDK#init()

Init a SDK instance

  • if there's no any available rules provied before ,
  • this init function can be triggered by users and at any time they want.

Contributing

  • Fork this repo
  • Clone your repo
  • Install dependencies
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Open a pull request, and enjoy <3

MIT license

Copyright (c) 2013 turing <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


docor generated using docor @ 0.1.0. brought to you by turingou