@joshkaki00/js-date-library
v1.0.1
Published
A JavaScript date manipulation library
Readme
JavaScript Date Library
A simple and powerful JavaScript date manipulation library that provides an easy-to-use interface for common date operations.
Installation
npm install @joshkaki00/js-date-libraryUsage
CommonJS (Node.js)
const DateLib = require('js-date-library');ES Modules
import DateLib from 'js-date-library';Browser (UMD)
<script src="https://unpkg.com/js-date-library"></script>
<script>
const date = new DateLib();
</script>Examples
// Create a new instance with current date
const date = new DateLib();
// Or with a specific date
const specificDate = new DateLib('2024-03-15');
// Format date as YYYY-MM-DD
console.log(date.format()); // e.g., "2024-03-15"
// Add days
const futureDate = date.addDays(5);
// Subtract days
const pastDate = date.subtractDays(5);
// Get difference in days
const daysDiff = date.diffInDays(otherDate);
// Check date relationships
const isBefore = date.isBefore(otherDate);
const isAfter = date.isAfter(otherDate);
const isBetween = date.isBetween(startDate, endDate);
// Get day and month information
const dayOfWeek = date.getDayOfWeek(); // 0-6 (Sunday-Saturday)
const dayName = date.getDayName(); // e.g., "Friday"
const monthName = date.getMonthName(); // e.g., "March"API Reference
Constructor
new DateLib(date?)- Creates a new instance with optional date parameter
Methods
getDate()- Returns the underlying Date objectformat()- Returns date in YYYY-MM-DD formataddDays(days)- Adds specified number of dayssubtractDays(days)- Subtracts specified number of daysdiffInDays(otherDate)- Calculates difference in days between datesisBefore(otherDate)- Checks if date is before another dateisAfter(otherDate)- Checks if date is after another dateisBetween(startDate, endDate)- Checks if date is between two datesgetDayOfWeek()- Returns day of week (0-6)getDayName()- Returns name of daygetMonthName()- Returns name of month
Development
# Run tests
npm test
# Run tests in watch mode
npm run test:watch
# Build the library
npm run build
# Build in watch mode
npm run build:watchBuild Output
The library is built in multiple formats:
dist/date-lib.cjs.js- CommonJS format (Node.js)dist/date-lib.esm.js- ES Modules formatdist/date-lib.umd.js- UMD format (Browser)dist/date-lib.min.js- Minified UMD format (Browser)
License
MIT - Feel free to use
