1.3.29 • Published 6 months ago

coddyger v1.3.29

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

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('user@example.com'); // 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 grebejordan@gmail.com or create an issue in the GitHub repository.

1.3.29

6 months ago

1.3.28

7 months ago

1.3.27

7 months ago

1.3.26

8 months ago

1.3.24

10 months ago

1.3.25

10 months ago

1.3.13

10 months ago

1.3.14

10 months ago

1.3.12

10 months ago

1.3.17

10 months ago

1.3.18

10 months ago

1.3.15

10 months ago

1.3.16

10 months ago

1.3.19

10 months ago

1.3.20

10 months ago

1.3.21

10 months ago

1.3.22

10 months ago

1.3.23

10 months ago

1.3.10

10 months ago

1.3.11

10 months ago

1.3.9

10 months ago

1.3.8

10 months ago

1.3.7

10 months ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.2.0

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.1

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.3.2

1 year ago

1.1.4

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.9

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.2

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.0

1 year ago

0.1.1

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago