Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

calculate-age

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculate-age

Calculate age of given date of birth and some other useful function

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by11.11%
Maintainers
1
Weekly downloads
 
Created
Source

calculate-age

This package is use to calculate age of a given date of birth.

npm npm

Installation

npm install calculate-age

Using

Function Parameter

    calculateAge(dateOfBirth: string | Date, compareDate?: string | Date)

Example

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

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

MIT

FAQs

Package last updated on 08 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc