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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@reldens/utils

v0.54.0

Published

Reldens - Utils

Readme

Reldens - GitHub - Release

Reldens - Utils

Features

  • Interaction area calculation helper.
  • Page range provider helper.
  • A validator interface and the SchemaValidator.
  • EnvVar for cast variables.
  • Shortcuts.
  • Logger.
  • Error Manager.
  • Events Manager and Events Manager Singleton.

Usage examples

EventsManager

Advanced event emitter with features like event sanitization, memory leak detection, key-based event management, and support for async/sync execution.

const { EventsManager } = require('@reldens/utils');
let eventsManager = new EventsManager();

// Listen to events
eventsManager.on('userLogin', (userData) => {
    console.log('User logged in:', userData.username);
});

// Emit events
eventsManager.emit('userLogin', { username: 'player1', id: 123 });

// Listen with unique keys
eventsManager.onWithKey('gameStart', callback, 'uniqueKey');
eventsManager.offWithKey('uniqueKey'); // Remove by key

InteractionArea

Spatial interaction validation helper that determines if objects are within interaction range based on coordinates and area margins.

const { InteractionArea } = require('@reldens/utils');
let interactionArea = new InteractionArea();

// Setup interaction area
interactionArea.setupInteractionArea(50, 100, 200); // margin=50, x=100, y=200

// Validate interaction
let isValid = interactionArea.isValidInteraction(120, 210); // true
let isInvalid = interactionArea.isValidInteraction(200, 300); // false

Logger

Advanced logging utility with multiple log levels, custom levels support, active level filtering, and environment-based configuration.

const { Logger } = require('@reldens/utils');

// Standard logging
Logger.info('Application started');
Logger.error('Database connection failed', errorDetails);
Logger.debug('Processing user request', requestData);

// Custom levels
Logger.activeLogLevels = [3, 4, 10]; // Only critical, error, and custom level 10
Logger.customLevels = [10, 11, 12];
Logger.log(10, 'custom', 'Custom log message');

// Configuration
Logger.setForcedDisabled(false);
Logger.setAddTimeStamp(true);

PageRangeProvider

Pagination helper that calculates page ranges for UI components, handling first/last page navigation and customizable display options.

const { PageRangeProvider } = require('@reldens/utils');

// Generate page range (it's a singleton, use directly)
let range = PageRangeProvider.fetch(5, 20, 7, 'First', 'Last');
// Returns: [{label: 'First', value: 1}, {label: 2, value: 2}, ...]

// Simple range
let simpleRange = PageRangeProvider.fetch(3, 10, 5);
// Returns pages around current page 3

SchemaValidator

Object validation utility that validates object properties against defined schemas with support for nested objects and custom validation rules.

const { SchemaValidator } = require('@reldens/utils');

let schema = {
    username: { type: 'string', min: 3, max: 20 },
    age: { type: 'int', min: 18 },
    profile: {
        type: 'object',
        nested: {
            email: { type: 'string', required: true }
        }
    }
};

let validator = new SchemaValidator(schema);
let userData = { username: 'player1', age: 25, profile: { email: '[email protected]' } };
let isValid = validator.validate(userData);

Shortcuts (sc)

Core utility class providing essential object manipulation, property access, and validation methods used throughout Reldens.

const { sc } = require('@reldens/utils');

// Safe property access
let value = sc.get(obj, 'nested.property.path', 'defaultValue');

// Check property ownership
if (sc.hasOwn(obj, 'propertyName')) {
    // Property exists
}

// Type checking
sc.isObject(value); // true/false
sc.isArray(value); // true/false
sc.isFunction(value); // true/false

// Deep operations
let cloned = sc.deepClone(originalObject);
let merged = sc.deepMerge(obj1, obj2);

// Property manipulation
sc.getDef(obj, 'key', 'default'); // Get with default
sc.getOneDef(obj, ['key1', 'key2'], 'default'); // Get first found key

ErrorManager

Singleton error handling utility with configurable tracing and custom error callbacks.

const { ErrorManager } = require('@reldens/utils');

// Enable stack traces
ErrorManager.enableTrace = true;

// Custom error handling
ErrorManager.callback = (message) => {
    // Custom error handling logic
    console.error('Custom error:', message);
    // Return false to prevent default throw
    return false;
};

// Trigger error
ErrorManager.error('Something went wrong');

EnvVar

Environment variable utilities with type conversion and validation for safe environment variable access.

const { EnvVar } = require('@reldens/utils');

// Get environment variables with type conversion
let port = EnvVar.integer(process.env, 'PORT', 3000); // Returns integer or default
let enabled = EnvVar.boolean(process.env, 'FEATURE_ENABLED', false); // Returns boolean
let apiUrl = EnvVar.string(process.env, 'API_URL', 'http://localhost'); // Returns string

// Other type helpers
let portNumber = EnvVar.port(process.env, 'PORT', 8080); // Validates port range 1-65535
let config = EnvVar.json(process.env, 'CONFIG', {}); // Parse JSON string
let items = EnvVar.array(process.env, 'ITEMS', [], ','); // Split string to array
let url = EnvVar.url(process.env, 'API_URL', 'http://localhost'); // Validate URL

ValidatorInterface

Base interface for creating custom validators with a standard validate method.

const { ValidatorInterface } = require('@reldens/utils');

// Extend to create custom validators
class CustomValidator extends ValidatorInterface {
    validate(data) {
        // Custom validation logic
        if (!data.requiredField) {
            return false;
        }
        return true;
    }
}

let validator = new CustomValidator();
let isValid = validator.validate({ requiredField: 'value' });

Need something specific?

Request a feature here: https://www.reldens.com/features-request


Documentation

https://www.reldens.com/documentation/utils/


Reldens

By DwDeveloper