@peterest/shared-utils
v1.0.0
Published
Shared utilities for My PaaS applications
Readme
Shared Utils Library
A collection of common utilities that can be shared across all applications in the My PaaS monorepo.
Installation
This library is part of the monorepo and can be used by other applications by adding it as a dependency.
Available Utilities
CryptoService
Password hashing and verification using bcrypt.
import { CryptoService } from '@my-paas/shared-utils';
// Hash a password
const hashedPassword = await CryptoService.hashPassword('myPassword123');
// Compare passwords
const isValid = await CryptoService.comparePassword('myPassword123', hashedPassword);
// Generate salt
const salt = await CryptoService.generateSalt(10);
// Get salt rounds from hash
const rounds = CryptoService.getSaltRounds(hashedPassword);ValidationService
Common validation functions for data validation.
import { ValidationService } from '@my-paas/shared-utils';
// Email validation
const isValidEmail = ValidationService.isValidEmail('[email protected]');
// Password strength validation
const isValidPassword = ValidationService.isValidPassword('MyPassword123');
// UUID validation
const isValidUUID = ValidationService.isValidUUID('123e4567-e89b-12d3-a456-426614174000');
// URL validation
const isValidURL = ValidationService.isValidURL('https://example.com');
// Phone number validation
const isValidPhone = ValidationService.isValidPhoneNumber('+1234567890');StringUtils
String manipulation and formatting utilities.
import { StringUtils } from '@my-paas/shared-utils';
// Generate random string
const randomString = StringUtils.generateRandomString(10);
// Case conversions
const camelCase = StringUtils.toCamelCase('hello world');
const kebabCase = StringUtils.toKebabCase('HelloWorld');
const snakeCase = StringUtils.toSnakeCase('Hello World');
// String manipulation
const capitalized = StringUtils.capitalize('hello');
const truncated = StringUtils.truncate('Very long string', 10);
const slugified = StringUtils.slugify('Hello World!');Development
Building the library
cd libs/shared-utils
npm install
npm run buildRunning tests
npm testDevelopment mode
npm run devUsage in other applications
To use this library in other applications within the monorepo:
- Add it as a dependency in the application's
package.json:
{
"dependencies": {
"@my-paas/shared-utils": "file:../libs/shared-utils"
}
}- Import and use the utilities:
import { CryptoService, ValidationService, StringUtils } from '@my-paas/shared-utils';