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 🙏

© 2025 – Pkg Stats / Ryan Hefner

switch-in-fp

v3.0.0

Published

Switch/case in functional programming style

Readme

switch-in-fp

package logo

A functional programming-inspired switch-case implementation for JavaScript. Because why not?


🤔 What is this?

This package provides a functional programming-style switch-case implementation using the if library. It's like a regular switch-case, but with extra steps. Perfect for those who want to feel smarter while writing code that does the same thing as a plain old switch.


🚀 Features

  • Functional Programming Vibes: Adds unnecessary complexity to your codebase.
  • Duplicate Case Handling: Automatically ignores duplicate cases because i'm too lazy to throw errors.
  • Edge Case Support: Handles null, undefined, empty strings, arrays, objects, and even negative numbers. (Why? I don't know either.)
  • Error Handling: Catches errors in actions and logs them to the console. You're welcome.
  • Asynchronous Actions: Supports async functions, Promises, setTimeout, and setInterval. Because blocking the event loop is so last year.
  • Default Action: Provides an .else() method for handling unmatched cases.

📦 Installation

Install the package via npm:

npm install switch-in-fp

Or, if you're feeling adventurous:

yarn add switch-in-fp

🛠️ Usage

Here’s how you can use this package to make your code unnecessarily complex:

const { SwitcherFactory } = require('switch-in-fp');

Switch(42)
  .case(42, (v) => console.log(v))
  .case(43, (v) => console.log(v))
  .else(() => console.log('No matching case'))
  .execute();
// Output: 42

const result = Switch(42)
  .case(42, (v) => v * 2)
  .execute();
console.log(result); // Output: 84

Advanced Example

Switch(7)
  .case(7, () => {
    throw new Error('Something went wrong');
  })
  .else(() => console.log('Default action'))
  .execute();
// Logs the error and continues execution

Asynchronous Actions

Switch(6)
  .case(6, async () => {
    await new Promise((resolve) => setTimeout(resolve, 1000));
    console.log('Async action executed');
  })
  .execute();
// Waits 1 second, then logs "Async action executed"

🧪 Tests

Run the tests to ensure everything works as expected:

npm test

📜 License

This project is licensed under the MIT License. Do whatever you want with it, but don't blame us if it breaks your codebase.


⚠️ Warning

If you find yourself using this package to replace in real project a simple switch-case, please stop it. Get some help.


🙌 Contributing

Feel free to contribute! Or don't. I'm not your boss or mom.


💌 Feedback

If you have any feedback (or say what i'm a stupid), suggestions, or complaints, feel free to open an issue. Or don’t. It’s up to you.