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

binapi

v0.2.1

Published

binary api

Downloads

6

Readme

npm install binapi
// github        much install     |
npm install sourcevault/binapi#dist

Build Status

🟡 .. quick Example 1 ..

var binapi = require ("binapi")

var main = function (state,args)
{

  var a = args[0]
  var b = args[1]

  if (state.flip) // flip arguments
  {
      var temporary = a
      a = b
      b = temporary
  }

  var output = a - b

  if (state.abs) // output only absolute value
  {
      return Math.abs(output)
  }

  return output

}

getter = function(state,key) {
  state[key] = true
  return state;
}

var subtract = binapi(main,getter,{})

subtract(10,5) // 5

subtract.flip(10,5) // - -5

subtract.flip.abs(10,5) //  5

subtract.abs.flip(10,5) //  5

// last two operations are doing the same thing

As shown above, we are using object properties as switches to turn "ON" certain flags in main.

colors is a good example of module that follows this pattern.

binapi is a shorthand for binary APIs.

.. Features

  • functions are built lazily, if you have 100 methods but the user only uses 3 functions - then only 3 objects are created.

binapi requires 2 functions to initialize :

  • application function - it is run whenever there is a call from the user.
  • getter function - run whenever . operation is appiled, needed for updating state variable needed by the application function.

🟡 ...Example 2...


var binapi = require ("binapi")

folks =
{
  charles:{age:null},
  henry:{age:null}
}

var main = function(key,args)
{

  folks[key] = args[0]
}

var getter = function(state,key) {return key}

var setAge = binapi(main,getter)

setAge.charles(32)

setAge.henry(29)

console.log(folks.charles) // 32

console.log(folks.henry) //29

..using state variable

Sometimes some state has to be present in your function, this is especially useful for nested binapis.

🟡 ..Example 3 - adding state variable as second argument..

var binapi = require("binapi");

var main,getter;

var loop = (state) => binapi(main,getter,state);

var get = ([num],key) => [num,key];

var F6 = ([x,key],args) =>

  var y = args[0]

  switch (key) {
  case "init":
    return loop([y]);
  case "add":
    return loop([x + y]);
  case "multiply":
    return loop([x * y]);
  case "ret":
    return x;
  default:
    return fail(6);

var compute = lopo(["init"])

var out = compute(5)
.add(5)
.multiply(10)
.ret!

Custom Logger

Internally binapi uses ES6 proxies allowing binding of custom log functions - providing us with the option of providing better object information when using console.log, custom log function is added as the 4rth argument.

🟡 ..Example 4 - custom logger provided as third argument..

var binapi = require ("binapi")

var main = function (){}

var getter = function(state,key) {return state.concat(key);}

var log = function(state)
{
  var chain = state.join(' | ')

  console.log ("( " + chain + " )")
}
test = binapi(main,getter,[],log)

tsf = test.sync.flip

console.log (tsf) // ( sync | flip )

Update and API change

  • 0.1.0 major change in API, support for binapi.obj dropped.

  • 0.0.8 major change in API, default binapi is list.

  • 0.0.4 major change in API, does not use this but uses argument to pass path and state.

LICENCE

  • Code released under BSD-3-Clause.
  • Documentation and images released under CC BY-NC-ND 4.0.
  • details can be found here.