JSPM

intl-timeago

1.0.2
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • 0
    • Score
      100M100P100Q43605F
    • License ISC

    A relative time formatter based on Intl.RelativeTimeFormat for JS and React

    Package Exports

    • intl-timeago
    • intl-timeago/useTimeAgo

    Readme

    intl-timeago

    Installation

    npm install intl-timeago

    Usage

    Function

    import { timeAgo } from "intl-timeago";
    
    const date = new Date();
    const timeAgo = timeAgo(date, "en-US");
    console.log(timeAgo); // now

    React

    Options

    • date - Date object
    • options.locale - Locale string, optional, default is inferred from the browser
    • options.live - Boolean or Number, default is true, if true the timeago will update every second, if false the timeago will not update, if a number the timeago will update every number of milliseconds
    import { useTimeAgo } from "intl-timeago/useTimeAgo";
    
    const date = new Date();
    
    const TimeAgo = () => {
      const timeAgo = useTimeAgo(date);
      return <span>{timeAgo}</span>;
    };
    
    export default TimeAgo;

    Formatting

    • now
    • x seconds ago
    • x minutes ago
    • x hours ago
    • today/yesterday
    • x days ago
    • this week/last week
    • x weeks ago
    • this month/last month
    • x months ago
    • this year/last year
    • x years ago

    License

    MIT