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

negotiation

v0.0.1

Published

Specification/protocol negotiation based on features and versions

Downloads

10

Readme

negotiation

Made by unshiftVersion npmBuild StatusDependenciesCoverage StatusIRC channel

Negotiation allows you to negotiate protocols between a client and server. This allows you to ship multiple versions of your protocol and have the server/client reach a agreement about which protocol to use. We do assume that the server has all possible protocols registered and that the client tells the server which versions they support.

We have a strong preference for binary protocols so when they are available we will prefer them over anything else.

Installation

The module was written to be compatible with Node.js and browserify. The release are pushed in the public npm registry and can therefor be installed from the CLI by executing:

npm install --save negotiation

Install today and get our revolutionary Binary Boost Bonus for free!

Usage

In all API examples we assume that you've pre-required the module and initialized the code as following:

'use strict';

var Negotiation = require('negotiation');
  , n = new Negotiation();

negotiation.register

Register a new protocol in our negotiation instance. This method accepts 2 arguments.

  1. The name of the protocol that you're adding. This will also be used again in the unique id that we're generating and returning in the available method.
  2. The protocol that you register needs to be an object. This object should have the following properties:
    • binary Boolean that indicates if binary data is supported in the protocol, defaults to false.
    • version Version number of the protocol. Try to follow semver without pre-release tags and other kinds of bullshit. So just pure x.x.x based versioning as we parse out the numbers and generate score of it for sorting and ranking purposes. It defaults to 0.0.0.

You can also add more properties as this object will be returned by the negotiation.select method.

n.register('json', { binary: false, version: '0.0.1' });
n.register('ejson', { binary: true, version: '1.0.9' });

The method returns it self so you can chain it.

negotiation.select

Select a protocol out of the given list of supported protocols. This method accepts 2 arguments:

  1. Array of available protocols.
  2. Prefer boolean that indicates the preference of binary protocols over regular protocols. So even if they have a lower version number it will take the highest matching binary protocol.
var protocol = n.select(['[email protected]', '[email protected]', '[email protected]']);

If no available protocols are given we will check all our supported protocols and return the one we prefer. If no matching protocol is found we will return undefined all other matches will return the set protocol.

negotiation.available

Return the id's of all available protocols that we send for the negotiation. By default it will return all non binary protocols as we're unsure if the host environment supports binary. If you want to include binary protocols pass in true as first argument.

var list = n.available();

var includingbinary = n.available(true);

This method will always return an array. Even if you didn't registry any protocols, it will just return an empty array.

negotiation.destroy

Fully destroy the created negotitation instance so it removes all references to the stored protocols and it can be garbage collected by the JavaScript engine. When you destroy it first the time it will return true and the second

  • next times it will return false as it was already destroyed.
n.destroy();

License

MIT