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

araby

v0.0.4-x

Published

A package customized to assist developers in creating Node.js projects.

Downloads

246

Readme

Installation

Node.js 18 or newer is required.

npm install araby
yarn add araby
pnpm add araby
bun add araby

NodeError(options: NodeErrorOptions): ReturnNodeError


The NodeError function is a customizable error management system that allows you to define and throw specific error messages with associated codes. It provides a convenient way to handle different types of errors, such as TypeError, RangeError, Error, SyntaxError, and ReferenceError, along with user-defined messages and codes.

const { NodeError } = require('araby');

const { Error } = NodeError({
    messages: {
        'InvalidNumber': 'Please check the number you entered and try again.',
        'InvalidID': (ID) => `Please check the ID number ${ID}`
    }
})

throw new Error('InvalidNumber') // Output: "Please check the number you entered and try again."
throw new Error('InvalidID', 0) // Output: "Please check the ID number 0"

NodeWarning(messages: NodeWarningMessages): ReturnNodeWarning


The NodeWarning function is a custom warning system built around Node.js's process.emitWarning. It allows you to define and emit custom warnings with specific messages and tags, providing an easy way to manage and trigger warnings throughout your application.

const { NodeWarning } = require('araby');

const Warnings = NodeWarning({
    InvalidUser: {
        message: 'This user is invalid, please check the user details.'
    },
    InvalidMessage: {
        message: (id) => `Please check the message with id ${id}.`,
        tag: 'APIMessage'
    }
})

Warnings('InvalidUser');
// Emits: (node:56338) InvalidUser: This user is invalid, please check the user details.

Warnings('InvalidMessage', '12345');
// Emits: (node:56338) [APIMessage] InvalidMessage: Please check the message with id 12345.

NodeEnumeration(keys: NodeNodeEnumerationKeys[]): R


The NodeEnumeration function is used to create a two-way mapping between keys and values from an array. It generates an object where both the indices and the values of the array are accessible through each other, allowing for bidirectional lookup.

const { NodeEnumeration } = require('araby');

const Keys = NodeEnumeration([
    undefined,
    'PRIVATE_PACKAGE',
    undefined,
    'PUBLIC_PACKAGE'
]);

console.log(Keys.PRIVATE_PACKAGE); // Output: 1
console.log(Keys[1]); // Output: PRIVATE_PACKAGE

console.log(Keys.PUBLIC_PACKAGE); // Output: 1
console.log(Keys[3]); // Output: PRIVATE_PACKAGE

console.log(Keys.ArabyPackage); // Output: undefined
console.log(Keys[0]); // Output: undefined
console.log(Keys[2]); // Output: undefined

toObject(object: Object, props: ObjectProps): R


The toObject function takes an instance of a class and converts it into a plain JavaScript object. This is useful for extracting and working with the properties and values of a class instance in a simple object format, allowing for easier serialization (e.g., converting to JSON) or manipulation.

const { toObject } = require('araby');

class NodeObject {
    constructor() {
        this.key = 'Key'
    }

    get classPropertyOne() {
        return 'classPropertyOne';
    }

    get classPropertyTwo() {
        return 'classPropertyTwo';
    }

    toObject() {
        return toObject(this, { 
            classPropertyOne: true,
            classPropertyTwo: true
        })
    }
}


const package = new NodeObject();

console.log(package.toObject()) // Output: { key: 'Key', classPropertyOne: 'classPropertyOne', classPropertyTwo: 'classPropertyTwo' }

isNone(value: any): boolean


The isNone function checks if the provided value is null.

const { isNone } = require('araby');

console.log(isNone('String')) // false
console.log(isNone(null)) // true

ProcessBar(options: ProcessBarOptions): string


The ProcessBar function generates a visual representation of a progress bar based on the given options.

const { ProcessBar } = require('araby');
console.log(ProcessBar({ value: 30, max: 100, size: 10 })); // Output: "███░░░░░░░"

NumberGenerate(length: number): number


The NumberGenerate function generates a random number of a specified length.

const { NumberGenerate } = require('araby');

const Number = NumberGenerate(4);
console.log(Number); // Outputs a random 4-digit number, e.g., 2357

Colors


The Colors namespace provides a set of utility functions to format text with various colors and background colors for use in terminal environments. Each function applies a specific color or background color to a given text string, helping to enhance the readability and presentation of terminal output.

const { Colors } = require('araby');

console.log(Colors.Red('Text'));
console.log(Colors.backgroundBrightRed('Text'));
console.log(Colors.backgroundRed('Text'));

HTTP

The araby/http module provides utilities for HTTP methods, content types, and response status codes.

Example Usage

const { Methods, ContentType, ResponseStatusCode } = require('araby/http');

// Filter allowed HTTP methods
const AllowedMethods = Methods.filter((value) => ['GET', 'POST'].includes(value));
console.log(AllowedMethods); // [ 'GET', 'POST' ]

// Access a specific content type
console.log(ContentType.APPLICATION_JSON); // application/json

// Access a specific HTTP response status code
console.log(ResponseStatusCode.OK); // 200