If you have a problem, it's probably already solved here.
A comprehensive, production-ready utility library for JavaScript/TypeScript projects that provides a centralized collection of common utilities and helpers to solve everyday programming challenges.
- π§ 20+ utility services for common development tasks
- ποΈ Zero-config setup with sensible defaults
- π― Type-safe with full TypeScript support
- π Tree-shakeable for optimal bundle size
- π¦ Multiple formats (CJS, ESM) for maximum compatibility
- π§ͺ 100% test coverage with comprehensive test suite
- π Extensive documentation with examples
- π Security-focused with regular vulnerability scans
The library includes 20+ utility services to cover common development needs:
- ArrayUtils - Array manipulation, filtering, grouping, and transformations
- ObjectUtils - Deep merging, cloning, flattening, and property manipulation
- StringUtils - Case conversion, validation, templating, and text processing
- NumberUtils - Mathematical operations, formatting, and validations
- MathUtils - Advanced mathematical functions and calculations
- ValidationUtils - Input validation, sanitization, and type checking
- ConvertUtils - Data type conversions and transformations
- DateUtils - Date manipulation, formatting, and timezone handling (powered by Luxon)
- HashUtils - SHA-256, SHA-512, bcrypt hashing and token generation
- CryptUtils - AES, RSA, ChaCha20 encryption/decryption
- JWTUtils - JWT token generation, verification, and management
- UUIDUtils - UUID v1, v4, v5 generation and validation
- CuidUtils - CUID generation and validation
- SnowflakeUtils - Twitter Snowflake ID generation
- SortUtils - Multiple sorting algorithms (bubble, merge, quick, heap)
- QueueUtils - Queue, stack, priority queue implementations
- CacheUtils - In-memory caching with TTL support
- HttpService - HTTP client abstraction (Axios and native)
- RequestUtils - HTTP request utilities and helpers
- BenchmarkUtils - Performance testing and function comparison
- FileUtils - File system operations and utilities
- LogService - Structured logging (Pino, Winston, Console)
- StorageService - File storage abstraction (Local, AWS S3)
- EventUtils - Type-safe event emitter and observer pattern
- RetryUtils - Retry logic with exponential backoff
npm install @brmorillo/utilsor
yarn add @brmorillo/utilsor
pnpm add @brmorillo/utilsimport { Utils } from '@brmorillo/utils';
// Initialize with default configuration
const utils = Utils.getInstance();
// Get logger
const logger = utils.getLogger();
logger.info('Application started');
// Get HTTP service
const http = utils.getHttpService();
const response = await http.get('https://api.example.com/data');
// Get storage service
const storage = utils.getStorageService();
await storage.uploadFile('path/to/file.txt', 'Hello, world!');The library can be configured with different options:
const utils = Utils.getInstance({
// Logger configuration
logger: {
type: 'pino', // 'pino', 'winston', or 'console'
level: 'debug', // 'error', 'warn', 'info', or 'debug'
prettyPrint: true, // Format logs for better readability
},
// HTTP client configuration
http: {
clientType: 'axios', // 'axios' or 'http' (native)
baseUrl: 'https://api.example.com',
defaultHeaders: {
Authorization: 'Bearer token',
'Content-Type': 'application/json',
},
timeout: 5000, // Request timeout in milliseconds
},
// Storage configuration
storage: {
providerType: 'local', // 'local' or 's3'
// Local storage options (when providerType is 'local')
local: {
basePath: './storage',
baseUrl: 'http://localhost:3000/files',
},
// S3 storage options (when providerType is 's3')
s3: {
bucket: 'my-bucket',
region: 'us-east-1',
accessKeyId: 'YOUR_ACCESS_KEY_ID',
secretAccessKey: 'YOUR_SECRET_ACCESS_KEY',
endpoint: 'https://custom-endpoint.com', // Optional
forcePathStyle: true, // Optional
baseUrl: 'https://cdn.example.com', // Optional
},
},
});
// Reconfigure later if needed
utils.configure({
logger: {
type: 'winston',
level: 'info',
},
});// utils.module.ts
import { Module, Global } from '@nestjs/common';
import { Utils } from '@brmorillo/utils';
@Global()
@Module({
providers: [
{
provide: 'UTILS',
useFactory: () => {
return Utils.getInstance({
logger: {
type: 'pino',
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
prettyPrint: process.env.NODE_ENV !== 'production',
},
http: {
clientType: 'axios',
baseUrl: process.env.API_BASE_URL,
defaultHeaders: {
Authorization: `Bearer ${process.env.API_TOKEN}`,
},
timeout: 10000,
},
storage: {
providerType: process.env.STORAGE_PROVIDER || 'local',
local: {
basePath: './storage',
baseUrl: `${process.env.APP_URL}/files`,
},
s3: {
bucket: process.env.S3_BUCKET,
region: process.env.AWS_REGION,
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
},
},
});
},
},
],
exports: ['UTILS'],
})
export class UtilsModule {}
// app.module.ts
import { Module } from '@nestjs/common';
import { UtilsModule } from './utils.module';
@Module({
imports: [UtilsModule],
})
export class AppModule {}
// users.service.ts
import { Injectable, Inject } from '@nestjs/common';
import { Utils } from '@brmorillo/utils';
@Injectable()
export class UsersService {
private logger;
private http;
private storage;
constructor(@Inject('UTILS') private utils: Utils) {
this.logger = utils.getLogger();
this.http = utils.getHttpService();
this.storage = utils.getStorageService();
}
async getUsers() {
this.logger.info('Fetching users');
const response = await this.http.get('/users');
return response.data;
}
async uploadAvatar(userId: string, avatar: Buffer) {
this.logger.info('Uploading avatar', { userId });
const path = `avatars/${userId}.jpg`;
const url = await this.storage.uploadFile(path, avatar, {
contentType: 'image/jpeg',
});
return url;
}
}import { ArrayUtils, StringUtils, HashUtils } from '@brmorillo/utils';
// Array operations
const numbers = [1, 2, 2, 3, 4, 4, 5];
const unique = ArrayUtils.removeDuplicates(numbers);
console.log(unique); // [1, 2, 3, 4, 5]
// String operations
const text = "hello world";
const camelCase = StringUtils.toCamelCase(text);
console.log(camelCase); // "helloWorld"
// Hashing
const hash = HashUtils.sha256Hash("sensitive data");
console.log(hash); // SHA-256 hash stringImport only what you need for optimal bundle size:
// Instead of importing everything
import * as utils from '@brmorillo/utils';
// Import only specific utilities
import { ArrayUtils } from '@brmorillo/utils';
import { StringUtils } from '@brmorillo/utils';For detailed documentation and examples for each utility, visit our documentation.
- π Array Utils - Array manipulation and processing
- π Security Utils - Cryptography, hashing, and JWT
- π HTTP Utils - HTTP client and request utilities
- π Storage Utils - File storage abstraction
- π Logging - Structured logging
- β‘ Performance - Benchmarking and optimization
- Node.js >= 16
- pnpm >= 8
# Clone the repository
git clone https://github.com/brmorillo/utils.git
cd utils
# Install dependencies
pnpm install
# Run tests
pnpm test
# Build the project
pnpm buildpnpm build- Build the librarypnpm test- Run all testspnpm test:coverage- Run tests with coveragepnpm lint- Lint the codepnpm format- Format the code
Contributions are welcome! Please read our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- Luxon for date manipulation
- Axios for HTTP client
- Pino and Winston for logging
- AWS SDK for S3 storage
- All the amazing open-source contributors
Made with β€οΈ by Bruno Morillo
- ConvertUtils - Data type conversion utilities
- RequestUtils - HTTP request data extraction utilities
- FileUtils - File system utilities
For detailed documentation and examples, see the docs directory.
MIT
Bruno Morillo