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

monastery-monads

v0.7.1

Published

Primative Monads and more for JS.

Downloads

1

Readme

️️️️⛪️️ Monastery ⛪️

Safe Monadic Types for Javascript (and TypeScript)

Premise

This module allows you to create a monad of any of the primatives (plus Array and a Maybe type), or build your own. This can allow you to build truly immutable values (including Object and Array) and comes runtime type enforcement without adding a type system such as TypeScript or Flow.

Status

This is in an experimental stage! When this has proven usable it will be promoted as a version 1.0.

So far I am not aware of any technical flaws other than some TypeScript @ts-ignore markers that need to be fixed and removed. However, I feel that a project of this kind requires extensive proof through testing and examples before making claims of stability.

Documentation

There are four types of monads in Monastery: Primatives, Data Structures, Maybe, and custom Types.

This is a work in progress, and thus documentation is incomplete.

Primative Monads & Data Structure Monads

Each primative is the name of the Javascript primative or data structure, prepended with $:

  • $Number
  • $String
  • $Boolean
  • $Array
  • $Object
  • $Symbol
  • $Null
  • $NaN
  • $Undefined

$Number

const thermometerReadingF = 12; // source data is in Fahrenheit
const fahrenheitToCelsius = $n => $n.subtract(32).multiply(0.5556);
const fahrenheitToKelvin = $n => fahrenheitToCelsius($n).add(273.15);
const fahrenheitToRankine = $n => $n.add(459.67);

const temperature = $Number.of(thermometerReadingF);

const celsius = fahrenheitToCelsius(temperature).unwrap();
const kelvin = fahrenheitToKelvin(temperature).unwrap();
const rankine = fahrenheitToRankine(temperature).unwrap();

// Note: .toFixed(1) converts to string
// > "-11.1"
console.log(celsius.toFixed(1));

// > "262.0"
console.log(kelvin.toFixed(1));

// > "471.7"
console.log(rankine.toFixed(1));

$String

const logString = 'Value was over the threshold ';
const tag = 'log';

const formatForConsole = $str => $str.prepend(`[${tag}] `);
const formatForDb = $str => $str.trim();

const logEntry = $String.of(logString);
const logConsole = formatForConsole(logEntry).unwrap();
const logDb = formatForDb(logEntry).unwrap();

// > "[log] Value was over the threshold "
console.log(logConsole);

// > "Value was over the threshold"
console.log(logDb);

Maybe Monad

$Maybe

This is a typical Maybe monad with some extra capabilities to enforce type. Generally a Maybe involves checking when a value "may be something or may be nothing", in this implementation it also can be interpreted that a value "may be of a certain type".

const status1 = null;
const status2 = 'Away';
const statusText = $str =>
    $Maybe
        .of($str)
        .as($String)
        .defaultTo('None');

// > "None"
console.log(statusText(status1).unwrap());

// > "Away"
console.log(statusText(status2).unwrap());

// Extend further with $String
const logStatusText = statusText(status2).prepend(`[user-status] `);

// > "[user-status] Away"
console.log(logStatusText.unwrap());

Development

Source is written in TypeScript. Run tests via npm run test.

MIT License

Copyright 2019 Robert Gerald Porter mailto:[email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.