@mdhsaikats/age-calculator
v1.0.0
Published
Calculate exact age in years/months/days, days until next birthday, and zodiac sign from a birth date.
Maintainers
Readme
@mdhsaikats/age-calculator
Zero-dependency age calculator for Node.js. Get exact age in years/months/days, total days lived, days until next birthday, and zodiac sign.
Install
npm install @mdhsaikats/age-calculatorUsage
const {
calculateAge,
ageInDays,
ageInYears,
nextBirthday,
isBirthday,
zodiacSign,
} = require("@mdhsaikats/age-calculator");
calculateAge("2000-05-15");
// { years: 26, months: 1, days: 23 } (relative to today)
calculateAge("2000-05-15", "2026-07-08");
// { years: 26, months: 1, days: 23 } (relative to a fixed reference date)
ageInYears("2000-05-15"); // 26
ageInDays("2000-05-15"); // 9550
nextBirthday("1990-08-01");
// { daysRemaining: 24, nextBirthday: 2026-08-01T00:00:00.000Z }
isBirthday("2000-07-08", "2026-07-08"); // true
zodiacSign("1990-08-01"); // 'Leo'All functions accept Date objects, ISO date strings ('YYYY-MM-DD'), or timestamps. The referenceDate parameter is optional everywhere and defaults to the current date/time.
API
| Function | Returns |
| ----------------------------------------- | --------------------------------------- |
| calculateAge(birthDate, referenceDate?) | { years, months, days } |
| ageInDays(birthDate, referenceDate?) | number — total whole days |
| ageInYears(birthDate, referenceDate?) | number — whole years |
| nextBirthday(birthDate, referenceDate?) | { daysRemaining, nextBirthday: Date } |
| isBirthday(birthDate, referenceDate?) | boolean |
| zodiacSign(birthDate) | string |
Invalid dates throw TypeError. A birthDate after referenceDate throws RangeError.
TypeScript types are included (index.d.ts) — no @types package needed.
Development
npm install
npm testPublishing to npm
npm login
npm publish --access publicnpm publish --access publicLicense
MIT
