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

@plugoinc/common

v1.0.6

Published

This is a common library used for backend development at Plugo.

Downloads

611

Readme

@plugoinc/common

This is a common library used for backend development at Plugo.

✨ Features

This library has following features.

  • Logger
  • Result
  • some utils

🚀 Getting Started

⚙️ Prerequisites

Use with Node.js v18 or higher

📦 Installation

npm install @plugoinc/common

📖 Usage

Logger

import { PlugoLogger } from '@plugoinc/common';

class MyLogger extends PlugoLogger {
  getTransport() {
    // You must override this method
    return TransportGenerator.dd('debug');
  }
}

const logger = new MyLogger();

// The second argument is converted to JSON and appears in the logs as metadata.
logger.debug('log in `debug` level', { name: 'this some data' });
logger.log('log in `log` level');
logger.warn('log in `warn` level');
logger.error('log in `error` level');

Result

Success Class

The Success class represents a successful result. It contains a value property which holds the result of the successful operation.

let success = new Success('Operation was successful');
console.log(success.value); // "Operation was successful"

Failure Class

The Failure class represents a failed result. It contains an error property which holds the error that caused the failure.

let failure = new Failure(new Error('Operation failed'));
console.log(failure.error.message); // "Operation failed"

unwrap

The unwrap function takes a Result and returns the value if the result is a Success, or throws the error if the result is a Failure.

let result = new Success('Operation was successful');
console.log(unwrap(result)); // "Operation was successful"

result = new Failure(new Error('Operation failed'));
console.log(unwrap(result)); // throws Error: "Operation failed"

toResultAsync

The toResultAsync function takes a Promise and returns a Promise that resolves to a Result. If the original Promise resolves, toResultAsync returns a Success with the resolved value. If the original Promise rejects, toResultAsync returns a Failure with the rejected error.

let promise = Promise.resolve('Operation was successful');
const result = await toResultAsync(promise);
console.log(result.isSuccess()); // true

promise = Promise.reject(new Error('Operation failed'));
const result = await toResultAsync(promise);
console.log(result.isFailure()); // true

🪪 License

MIT

🚢 Release

[!NOTE] Creating an isolated PR for changing the version in package.json

👋 Contributors,

Thank you for your interest in contributing to our project! To streamline the contribution process, we encourage you to follow these steps:

Issue Submission:

Before implementing any changes, please check if there is an existing issue related to the task you want to work on. If not, please create a new issue to discuss and get feedback on your proposed changes. Make sure to provide a clear title and detailed description. Fork the Repository:

Once the issue is approved, fork the repository to your GitHub account. Branching:

Create a new branch for your changes. Use a branch name that succinctly describes your feature or fix. Implement Changes:

Make the necessary changes in your forked branch. Pull Request:

When you're ready to submit your changes, open a Pull Request (PR). Reference the related issue in the PR description using the phrase "Closes #IssueNumber" to automatically link the PR to the issue. Review and Collaboration:

Be responsive to feedback during the review process. Make any requested changes promptly. By following this process, we can ensure a smooth and collaborative contribution experience. Thank you for your efforts in making our project better!

🚀 Happy Coding!