npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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.