timeago.js

  • Version 4.0.2
  • Published
  • 262 kB
  • No dependencies
  • MIT license

Install

npm i timeago.js
yarn add timeago.js
pnpm add timeago.js

Overview

timeago.js is a simple library (only 1kb) to used to format datetime with `*** time ago` statement. eg: '3 hours ago'. localization supported.

Index

Functions

function cancel

cancel: (node?: HTMLElement) => void;
  • cancel a timer or all timers

    Parameter node

    node hosting the time string

function format

format: (date: TDate, locale?: string, opts?: Opts) => string;
  • format a TDate into string

    Parameter date

    Parameter locale

    Parameter opts

function register

register: (locale: string, func: LocaleFunc) => void;
  • register a locale

    Parameter locale

    Parameter func

function render

render: (
nodes: HTMLElement | HTMLElement[] | NodeList,
locale?: string,
opts?: Opts
) => HTMLElement[];
  • render a dom realtime

    Parameter nodes

    Parameter locale

    Parameter opts

Type Aliases

type LocaleFunc

type LocaleFunc = (diff: number, idx: number, totalSec?: number) => [string, string];

    type LocaleMap

    type LocaleMap = Record<string, LocaleFunc>;

      type Opts

      type Opts = {
      /** the relative date */
      readonly relativeDate?: TDate;
      /** the realtime */
      readonly minInterval?: number;
      };
      • render / format options

      type TDate

      type TDate = Date | string | number;

        type TimerPool

        type TimerPool = Record<number, number>;

          Package Files (5)

          Dependencies (0)

          No dependencies.

          Dev Dependencies (23)

          Peer Dependencies (0)

          No peer dependencies.

          Badge

          To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

          You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/timeago.js.

          • Markdown
            [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/timeago.js)
          • HTML
            <a href="https://www.jsdocs.io/package/timeago.js"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>