I wrote moment.js, a date library that does this. It's about 5KB (2011) 52KB (2019), and works in browsers and in Node. It's also probably the most popular and famous date library for JavaScript.
It supports timeago, formatting, parsing, querying, manipulating, i18n, etc.
Timeago (relative time) for dates in the past is done with moment().fromNow(). For example, to display January 1, 2019 in the timeago format:
let date = moment("2019-01-01", "YYYY-MM-DD");
console.log(date.fromNow());
The timeago strings are customizable with moment.updateLocale(), so you can change them how you see fit.
The cutoffs are not what the question requests ("5 weeks" vs. "1 month"), but it is documented as to which strings are used for what time range.