Skip to content

Repository files navigation

ESLint logo

@avenue3-dev/format-age

format-age is a tiny, dependency-free package for formatting age in clinical or health-related contexts. It displays age with appropriate granularity for different life stages—down to minutes for newborns and more concise formats for older individuals.

Examples

  • 21y – 21 years
  • 2y 2m – 2 years, 2 months
  • 21m 29d – 21 months, 29 days
  • 30w 4d – 30 weeks, 4 days
  • 26d – 26 days
  • 30mins – 30 minutes

Install

format-age is available as an npm package can be installed with one of the following commands:

npm
npm install @avenue3-dev/format-age
pnpm
pnpm add @avenue3-dev/format-age

Example

// Birth date as a Date object
formatAge(new Date('2003-05-09'));
// → '21y'

// Birth date ISO 8601 string input
formatAge('2022-03-01');
// → '2y 2m'

// Calculating relative age or age of death
formatAge(new Date('2002-03-01'), new Date('2022-03-01'));
// → '20y'

Changelog

Check out our changelog for key highlights, performance improvements, new features, and notable bugfixes.

License

Licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages