# @reldens/utils

> Reldens - Utils

Latest version **0.58.0** (published 2026-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @reldens/utils
pnpm add @reldens/utils
yarn add @reldens/utils
bun add @reldens/utils
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.58.0 |
| Published | 2026-09-03 |
| First published | 2020-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 147.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Damian A. Pastorini |
| Maintainers | dpastorini |
| Keywords | reldens, utils, shortcuts, system, game, mmorpg, rpg, dwd, colyseus, phaser, parcel, nodejs, mmo, multiplayer, rol, platform, framework |

## Links

- npm: https://www.npmjs.com/package/@reldens/utils
- Repository: https://github.com/damian-pastorini/reldens-utils
- Issues: https://github.com/damian-pastorini/reldens-utils/issues
- npm.io page: https://npm.io/package/@reldens/utils

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.58.0 (latest) — 2026-09-03
- 0.10.0-beta.4 (beta) — 2022-02-13
- 0.57.0 — 2026-06-21
- 0.56.0 — 2026-04-04
- 0.55.0 — 2026-03-10
- 0.54.0 — 2025-11-19
- 0.53.0 — 2025-08-22
- 0.52.0 — 2025-08-04
- 0.51.0 — 2025-07-28
- 0.50.0 — 2025-06-01
- 0.49.0 — 2025-05-29
- 0.48.0 — 2025-05-29
- 0.47.0 — 2025-05-12
- 0.46.0 — 2025-05-07
- 0.45.0 — 2025-05-07
- … 72 more at https://npm.io/package/@reldens/utils/versions

## README

[![Reldens - GitHub - Release](https://www.dwdeveloper.com/media/reldens/reldens-mmorpg-platform.png)](https://github.com/damian-pastorini/reldens)

# 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.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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: 'test@example.com' } };
let isValid = validator.validate(userData);
```

### Shortcuts (sc)
Core utility class providing essential object manipulation, property access, and validation methods used throughout Reldens.

```javascript
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.

```javascript
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.

```javascript
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.

```javascript
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](https://www.reldens.com/features-request)

---

## Documentation

[https://www.reldens.com/documentation/utils/](https://www.reldens.com/documentation/utils/)


---

### [Reldens](https://github.com/damian-pastorini/reldens/ "Reldens")

##### [By DwDeveloper](https://www.dwdeveloper.com/ "DwDeveloper")

---
_Source: https://npm.io/package/@reldens/utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
