npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

humanize-age

v1.0.0

Published

Convert differences of dates into human-readable strings.

Downloads

5

Readme

humanize-age

Convert differences of dates into human-readable strings.

What is humanize-age?

humanize-age is a very simple npm package which makes human-readable strings like "2 years and 3 months old" from the birthday and a specifed date.

How to Use

const humanizeAge = require('humanize-age');

const myBirthday = new Date('1984-09-24');

/* How old were I on the first new year's day? */
const newYearsDay = new Date('1985-01-01');
console.log(`I was ${humanizeAge.getHumanizedAge(myBirthday, newYearsDay)} on my first new year's day.`);

/* How old were I when Atlanta Olympic started? */
const atlantaOlympic = new Date('1996-07-19');
console.log(`I was ${humanizeAge.getHumanizedAge(myBirthday, atlantaOlympic)} when the Olympic games were held in Atlanta.`);

/* And how old am I? */
const today = new Date();
console.log(`And today, I am ${humanizeAge.getHumanizedAge(myBirthday, today)}.`);

API

getHumanizedAge(birthday, date)

Returns string which represents the age in human-readable form. For example, first method call in the example code above returns "3 months and 8 days old".

If s/he is younger than 1 month old, this method returns age in days (e.g.: "Day 14").

If s/he is younger than 1 year old, this method returns age in months (e.g.: "3 months old").

If s/he is younger than 15 year old, this method returns age in years and months (e.g.: "8 years and 3 months old").

If s/he is older than or equal to 15 year old, this method returns age in years (e.g.: "30 years old").

difference(d1, d2)

Returns object which represents difference of specified two dates. d1 must be smaller than or equal to d2.

For example, humanizeAge.difference(new Date("1984-09-24"), new Date("2017-01-09")) returns { y: 32, m: 3, d: 16 }

Note

Ages will be calculated assuming that specified dates are 00:00 in UTC.

Author information

Programmed by kcrt (TAKAHASHI, Kyohei) http://profile.kcrt.net/

License

Copyright © 2016 kcrt (TAKAHASHI, Kyohei)
Released under the MIT license
http://opensource.org/licenses/mit-license.php

Reference

none