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

oro-maybe

v1.0.0

Published

Sort of like the Maybe monad but with logs and stuff

Downloads

11

Readme

Pipe will early exit on a Nope and give an log an error message (wont throw an error).

Important

There is a peer dependency of babel-polyfill, you can resolve this by runing npm install --save babel-polyfill

Basics

Maybe.Just :: seed -> Maybe.Just

  • seed - The thing you care about and want passed to the next thing

Maybe.Nope :: seed -> code -> description -> Maybe.Nope

  • seed - Probably the last seed in the sequence, should be enough data to recover from a Nope
  • code - quick reference ie: NUMBER_NOT_IN_RANGE, WRONG_TYPE. In a http router this could be the status ie: 404, 500.
  • description - a more helpful explanation of what went wrong and possibly how to fix it.

Maybe.pipe :: seed -> ...Func -> Maybe.Just|Maybe.Nope

  • seed - initial value

Where: Func :: seed -> seed -> Maybe.Just | Maybe.Nope

  • seed - initial value or result held in the return of the last Func

One more thing

assert(Maybe.Just("bob").value, "bob")

Example

import { Just, Nope, pipe } from "oro-maybe"

var double = x => Just(x * 2)
var square = x => Just(x * x)

var doubleAndSquare = x => pipe(x, double, square)
var quadruple = x => pipe(x, double, double)

var isNumber = x => "number" == typeof x
  ? Just(x)
  : Nope(x, "WRONG_TYPE", `value had a type of "${ typeof x }" but should have had a type of "number"`)

var isGreaterThan = min => x => (x > min)
  ? Just(x)
  : Nope(x, "WAS_LESS_THAN", `"${ x }" should have been greaterThan "${ min }"`)

var isLessThan = max => x => (x < max)
  ? Just(x)
  : Nope(x, "WAS_GREATER_THAN", `"${ x }" should have been lessThan "${ min }"`)

var inRangeOf = (min, max) => x => pipe(x, isNumber, isGreaterThan(min), isLessThan(max))
var inRange = inRangeOf(4, 16)

pipe(2, double, square, doubleAndSquare, quadruple)          // Just(4096)
pipe(2, double, square, inRange, doubleAndSquare, quadruple) // Just(4096)

pipe(2, double, square, doubleAndSquare, inRange, quadruple) // Nope(1024, "NOT_IN_RANGE", "1024 was greater than the max of 16")
// Nope: [NOT_IN_RANGE] 1024 was greater than max of 16

pipe("bob", inRange(0,1000))                                 // Nope("bob", "WRONG_TYPE", `value had a type of "String" but should have had a type of "number"`)
// Nope: [WRONG_TYPE] value had a type of "String" but should have had a type of "number"