1.0.3 • Published 4 years ago

time-ago-lite v1.0.3

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

time-ago-lite

A liteweight library to generate time ago string from a date

Installation

$ yarn add time-ago-lite

or

$ npm add time-ago-lite

Usage

English (default)

import { relativeTimeEn } from 'time-ago-lite';

const yourRelativeTimeString = relativeTimeEn(yourDate);

Other languages

import { relativeTime, wordsFn } from 'time-ago-lite';

/**
 * Words function based on your language rules
 * It needs to conform to the wordsFn interface
 */
const yourLangWords: wordsFn = (number = 1, unitKey = 'now', isInPast = true) => {
    // Your implementation here, see the `enWords` in the `index.ts`
    // or `srWords` in the `index.spec.ts`
};

const relativeTimeYourLang = relativeTime(yourLangWords);

const yourRelativeTimeStringInYourLang = relativeTimeYourLang(yourDate)