coddyger
v1.3.25
Published
Commun javascript functions and plugins
Downloads
109
Readme
Coddyger Module
Overview
The coddyger
module provides a set of utility functions for common string operations, such as checking if a string is empty, validating email addresses, checking if a string is a number, validating dates, and more.
Installation
To use the coddyger
module in your project, you can install it via npm or yarn:
npm install coddyger
# or
yarn add coddyger
Features
- String manipulation and validation
- Date formatting and manipulation
- File operations
- MongoDB utilities
- API response handling
- Logging utilities
- Database access layer (MongoDB & Sequelize)
Usage
Basic Import
import coddyger from 'coddyger';
String Operations
// Check if string is empty
coddyger.string.isEmpty(''); // true
// Validate email
coddyger.string.isEmailAddress('[email protected]'); // true
// Check if string is number
coddyger.string.isNumber('123'); // true
// Validate date
coddyger.string.isDate('2024-03-20'); // true
Date Operations
// Format date
coddyger.dates.format(new Date(), 'dd/MM/yyyy'); // '20/03/2024'
// Add days to date
coddyger.dates.addDays(new Date(), 5);
// Check if date is within interval
coddyger.dates.isWithinInterval(
'2024-03-20',
'2024-03-01',
'2024-03-31'
); // true
File Operations
// Check if file exists
coddyger.file.exists('/path/to/file.txt');
// Get file extension
coddyger.file.extension('document.pdf'); // '.pdf'
// Convert file to Base64
coddyger.file.toBase64('/path/to/image.jpg');
MongoDB Utilities
// Check if string is valid ObjectId
coddyger.string.isValidObjectId('507f1f77bcf86cd799439011'); // true
// Generate new ObjectId
const newId = coddyger.string.generateObjectId();
API Response Handling
coddyger.api(context, promise)
.then(response => {
// Handle success
})
.catch(error => {
// Handle error
});
Logging
// Info log
coddyger.konsole('Operation successful');
// Error log
coddyger.konsole('Operation failed', 1);
File Inclusion
// Include all files with specific extension from directory
const controllers = coddyger.filesInclude('./controllers', 'controller');
Error Handling
// Standardized error handling
try {
// Your code here
} catch (error) {
return coddyger.catchReturn(error, 'UserController', 'createUser');
}
Phone Number and Country Operations
// Validate phone number
coddyger.string.isValidPhoneNumber('+33612345678', 'FR'); // true
// Get country from phone prefix
coddyger.string.getCountryCodeFromPrefix('+33'); // 'FR'
// Get list of countries with codes, names and flags
const countries = coddyger.string.getCountryList();
// Returns: [
// {
// code: 'FR',
// name: 'France',
// flag: '🇫🇷',
// phoneCode: '+33'
// },
// // ... more countries
// ]
Database Integration
MongoDB Connection
import { MongooseDataAccess } from 'coddyger';
const db = new MongooseDataAccess();
db.connect();
Data Access Layer
import { MongoDbDao } from 'coddyger';
class UserSet extends MongoDbDao<Document> {
// Your model implementation
}
Environment Configuration
Create a .env
file in your project root:
APP_NAME=Your App Name
ENV=development
DB_URI=mongodb://localhost:27017/your-database
SERVER_PORT=3000
API_VERSION=v1
TypeScript Support
This module includes TypeScript definitions. No additional @types packages are required.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Jordan Gnazalé
Support
For support, email [email protected] or create an issue in the GitHub repository.