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 🙏

© 2026 – Pkg Stats / Ryan Hefner

io-square-browser

v0.0.7

Published

IO Monad for browser javascript.

Readme

IO^2 for browser JavaScript

IO Monad for browser JavaScript

Separate pure and impure functions in JavaScript.

Usage

Just include lib/io-square-browser.js in your script tag. Global IO is available in your JS.

Example

/*
   Problem:
   Validate Email entered by user. Post valid email as JSON to server.
   Handle network error. Verify response from server. Do next ...
*/

// Pure Function to validate emails. Returns email, or null if invalid.
const validateEmail = email => {
  if (email.length > 3 && /^[\w\.-]+@[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,6}$/.test(email)) {
    return email
  } else {
    alert('Invalid Email Address')
    return null
  }
}

// Function given email, returns a new IO object that posts to the server. In case of
// IO error, error message is alerted.
const postEmail = email => {
  emailInput.disabled = true
  return IO.postJSON('/apply', {email: email})
    .error(e => alert(e.message))
}

// Returns null if error in response. Or the email.

const verifyEmailResponse = (email, resp) => {
  if (resp.error) {
    emailInput.disabled = false
    alert(resp.message)
    return null
  } else {
    return email
  }
}

// This is the main IO Object created.
// Listens to the change event of the email input element.
// Calls verify email and rejects if invalid email
// Binds this IO to another IO object returned by postEmail.
// Rejects if verifyEmailRespons returns null
// Finally always call 'then' to actvate the IO Object
IO.change(emailInput)
  .reject(verifyEmail)
  .bind(postEmail)
  .reject(verifyEmailResponse)
  .then(email => {
    emailView.style.display = 'none'
    codeView.style.display = 'block'
    infoText.textContent = email
  })

Available methods

Static Methods for creating IO Objects

IO.click(DOMElement)

Returns an IO object for the click Event. Methods of the IO Object will be called with the Event Object.

IO.change(DOMElement)

Returns an IO object for the change Event. Methods of the IO Object will be called with event.target.value.

IO.get(url)

Returns an IO object for the get request. The value propagated is responseText.

IO.getJSON(url)

Returns an IO object for the get request. The value propagated is JavaScript Object.

IO.getBlob(url)

Returns an IO object for the get request. The value propagated is JavaScript Blob Object.

IO.postJSON(url, obj)

Returns an IO object for the post request. The value propagated is JavaScript Object.

Instance methods on IO Objects

ioObject.error(error -> DoSomething)

To stop propagation on IO Error use error. The error handler is called when the IO Event results in an instance of Error rather tha a value.

ioObject.reject(val -> null or Val)

To stop propagation of the value use reject.

ioObject.map(val -> NewVal)

To convert the propagated value to a new value, use map.

ioObject.bind(val -> new IOObject)

Bind the current IO Object to a new IO Object. After the bind, the values propagated are the value of the original IOObject, and the new IOObject.

ioObject.then(val -> Finally do something)

then must be the final call. The function passed to then will not return anything.

Note:

If you want to propagate more than one value, just return an Array of values from your pure function. The next pure function called will be called with multiple arguments.

Create your own IO Objects

To create your own IO Objects, follow IO-Square