https://github.com/arvindkumarbadwal/calculate-age
This package is use to calculate age of a given date of birth.
https://github.com/arvindkumarbadwal/calculate-age
age calculate calculate-age nodejs
Last synced: about 2 months ago
JSON representation
This package is use to calculate age of a given date of birth.
- Host: GitHub
- URL: https://github.com/arvindkumarbadwal/calculate-age
- Owner: arvindkumarbadwal
- License: mit
- Created: 2021-01-26T07:02:38.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-04-08T18:29:20.000Z (about 3 years ago)
- Last Synced: 2025-10-12T05:05:21.093Z (8 months ago)
- Topics: age, calculate, calculate-age, nodejs
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/calculate-age
- Size: 89.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# calculate-age
This package is use to calculate age of a given date of birth.


## Installation
```sh
npm install calculate-age
```
## Using
Function Parameter
```js
calculateAge(dateOfBirth: string | Date, compareDate?: string | Date)
```
Example
```js
import calculateAge from 'calculate-age'
// OR const calculateAge = require('calculate-age').default
const output = calculateAge('1988-10-26', '2021-01-26').getObject()
// output: { years: 32, months: 3, days: 10 }
const output = calculateAge('1988-10-26', '2021-01-26').getString()
// output: 32 years 3 months
```
## Output
```js
getObject() --> getString()
// { years: 5, months: 3, days: 2 } --> 5 years 3 months
// { years: 5, months: 0, days: 0 } --> 5 years
// { years: 0, months: 3, days: 2 } --> 3 months 2 days
// { years: 0, months: 3, days: 0 } --> 3 months
// { years: 0, months: 0, days: 2 } --> 2 days
// { years: 1, months: 2, days: 0 } --> 1 year 2 months
// { years: 1, months: 0, days: 0 } --> 1 year
// { years: 0, months: 1, days: 2 } --> 1 month 2 days
// { years: 0, months: 1, days: 0 } --> 1 month
// { years: 0, months: 0, days: 1 } --> 1 day
```
## Release Notes - Version 1.0.0
### Features
- Added TypeScript support to the package.
- Changed from class-based to function-based implementation for `calculateAge` method, removing the need for `new` keyword.
- Made `compareDate` optional in `calculateAge` method, defaulting it to today's date.
## Contributing
If you find a bug or willing to add some enhancement, pull requests are very welcome
## :copyright: License
[MIT](http://opensource.org/licenses/MIT)