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

@andrejunqueira/either_js

v1.1.0

Published

This package is created to handle returns and errors in a better way, using functional concept Either.

Downloads

2

Readme

This package is created to handle returns and errors in a better way, using functional concept Either.

it facilitates the manner that you handle the api responses

Usage:

import { left, right } from '@andrejunqueira/either_js';

async function getUser() {
    //You can return left or right to be hanled

    try {
        const response = await axios.get('https://apiurl.com')

        //Your request validations...
        if (response.status === '400') {
            return left("Something went wrong");
        }
        //Everithing is ok...
        return right(response.data);

    } catch (error) {
        //Something went wrong...
        return left(error);
    }
}

fold

/// USAGE
const myUser = await getUser();

function whenLeft(data) {
    //Do something when go wrong
}

function whenRight(data) {
    // Do somethisn when go right !
}

myUser.fold(whenLeft, whenRight);

//OR

myUser.fold(
    (error) => console.log(error),
    (success) => console.log(success)
);



// You can do checks if needed

if(myUser.isLeft()){
    //Do something
}

if(myUser.isRight()){
    //Do something
}

getOrElse

const myUser = await getUser();

const successValue = myUser.getOrElse((failure) => {
    console.error('Failure + ', failure);
});

getOrNull

const myUser = await getUser();

const successValue = myUser.getOrNull();

console.log(successValue)
//if something go wrong the successValue will be null

getOrDefault

const myUser = await getUser();

const successValue = myUser.getOrDefault('Default data !');

console.log(successValue)
//if something go wrong the successValue will be ["Default data !]"

map


class User {
    name;
    constructor(name) {
        this.name = name;
    }

    printName() {
        console.log(this.name);
    }
}


const myUser = await getUser();

//the success value will be mapped to anything you return from it
const value = myUser.map((value) => new User(value));

//after to be mapped you can use any other methods like fold for example
value.fold(
    (error) => console.log(),
    (user) => user.printName(),
);

mapError

const myUser = await getUser();

//the same as map, but the error value will be mapped
const value = myUser.mapError((value) => new Error(value));


//after to be mapped you can use any other methods like fold for example
value.fold(
    (error) => console.log(error.message),
    (success) => console.log(success),
);

Thats it !!