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

uncertainty

v0.1.0-alpha.1

Published

An uncertain data having a definite value when measured.

Downloads

6

Readme

uncertainty

The Uncertainty object is an uncertain data having a definite value when measured. It is inspired by quantum machanics and borrows a concept that an observation collapses a wave function and reduces to a state of particles of Copenhagen interpretation.

Getting Started

npm i -S uncertainty
const { Uncertainty } = require('uncertainty');

const isBottleBroken = new Uncertainty()
const cat = isBottleBroken.then(bool => bool ? 'dead' : 'alive')

console.log(isBottleBroken.peek()) // Uncertain
console.log(cat.peek()) // Uncertain
console.log(cat)  // dead or alive
console.log(isBottleBroken.peek()) // Measured
console.log(cat.peek()) // Measured

API

new Uncertainty(arg?: any[])

An Uncertainty constructor creates new Uncertainty object. It receives a range of probable values as an array.

const a = new Uncertainty()
console.log(a)  // true or false

const b = new Uncertainty([1, 2, 3])
console.log(b)  // 1, 2 or 3

.then(cb: Function)

.then() receives a callback function which is run when the value is measured. The function will always be run before a measuring code.

const a = new Uncertainty([1, 2])
a.then(() => {
  console.log('Hello, world!')
})
console.log(a + 1)

// Hello, world!
// 2

.then() also creates a new Uncertainty object entangled with the object. The callback function receives the entangled object as an input, and returns new Uncertainty object value. When one of the entangled objects are measured, the other are also measured.

const a = new Uncertainty()
const b = a.then(a => !a)
const c = b.then(b => Number(b))
console.log(a.peek()) // Uncertain
console.log(b.peek()) // Uncertain
console.log(c.peek()) // Uncertain
console.log(b)  // false or true
console.log(a.peek()) // Measured
console.log(b.peek()) // Measured
console.log(c.peek()) // Measured

.peek()

.peek() peeks the data state whether it is uncertain or measured. It does not measure the value.

const a = new Uncertainty()
console.log(a.peek()) // Uncertain
console.log(a)  //  true or false
console.log(a.peek()) // Measured

Measurement

Measurement means access to a data value. If it does not have to access a value, it is considered unmeasured. For example, in a conditional statement, an Uncertainty object has same characteristics as a JavaScript object.

const a = new Uncertainty()

a           // Not measured.
!a          // Not measured. An object in JavsScript is always trusty.
a + 1       // Measured.
a == true   // Measured. It is calcuated after type casting.
a === true  // Not measured. It does not have to measure a value because of different types.