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

monads-io

v2.3.0

Published

๐Ÿš€ Efficient Monads for JS: Maybe (Option) and Either (Result)

Downloads

737

Readme

Monads IO

๐Ÿš€ Efficient Monads for JS: Maybe (Option) and Either (Result)

Test Status Downloads last commit codecov GitHub monads-io Known Vulnerabilities Quality npm license MIT Size

Why use this lib

  1. Small and Tree-Shakable. Either - 3kb minified, Maybe - 3kb minified, can be imported separately
  2. No dependencies.
  3. Memory-Efficient. 8 bytes overhead per instance (only class pointer)
  4. Tested. 100% coverage
  5. Practical. Just 2 wrappers: Either and Maybe - easy for non-fp people

Credits

Huge credit to @JSMonk. This library is based on JSMonk/sweet-monads

Docs available in his repository

๐Ÿ“ฆ Installation

  • Using npm
    npm i monads-io
  • Using Yarn
    yarn add monads-io
  • Using pnpm
    pnpm add monads-io

โš™๏ธ Usage

// Real world example
// This maybe is not tree-shakable. Used in NodeJS code
import { Maybe } from "monads-io";

export async function getTargets(
  api: TelegramAPI,
  tokens: formattedText,
  { mentionLimit = 1, message = undefined as message | undefined } = {}
): Promise<Map<number, chat | undefined>> {
  const mentions = getMentions(tokens).slice(0, mentionLimit);

  const targets = new Map<number, chat | undefined>();
  let replyTarget: [number, chat | undefined] | undefined;
  const { messagesService, chatsService } = getServices(api);

  ...

  // 1. Get message
  // 2. Get message reply id (0 = no reply)
  // 3. Get reply message by message id
  // 4. Get reply message sender
  // 5. Get his/her profile
  // 6. Set local variable to profile

  const reply = await Maybe.fromNullable(message)
    .filter((message) => message.reply_to_message_id !== 0)
    .asyncChain((message) =>
      messagesService.getReply(message.chat_id, message.id)
    );

  const sender = await reply
    .map(MemberId.fromMessage)
    .tap(({ memberId }) => {
      replyTarget = [memberId, undefined];
    })
    .asyncChain(({ memberId }) => chatsService.getById(memberId));

  sender.tap((sender) => {
    replyTarget = [sender.id, sender];
  });

  ...

  return replyTarget ? new Map([replyTarget, ...targets]) : targets;
}