Skip to content

Getting Started

This package is a collection of utilities that I use in nearly every project.
It was part of one of my learning projects, but since it became bigger, and I needed it for multiple projects, I decided to move it to its own package.

For updates and new features, please refer to the CHANGELOG.md file in the GitHub repository to track all changes.

Installation:

Terminal window
npm install @mustib/utils@latest

Usage:

Categories

  • exports are divided into 3 categories:

    • / for common utilities that work in both node and browser environments
    • /node for node environments
    • /browser for browser environments
  • each category exports a global constants variables.

  • common utilities can be imported from both /node and /browser

  • all utilities are exported as named exports under their category

  • both ESM and CJS are supported depending on your package manager configuration (e.g. import vs require)

// common utilities
import { AppError } from '@mustib/utils';
// node utilities
import { EnvVars } from '@mustib/utils/node';
// browser utilities
import { getElementBoundaries } from '@mustib/utils/browser';

Error Handling

each utility that might throw an error will use AppError class to manage and handle errors in an application. To help filter errors for both scopes: this utility and the library as a whole, each utility that throws errors will export an array of symbols called error scope which includes the global LIBRARY_ERROR_SCOPE constant.

  • the exported scopes name should start with the utility name with first letter in lowercase and then ErrorScope like this: utilityNameErrorScope
  • it will be stated at the top of each utility docs page the exported error scope variable name if it exports them