Nocturnal Pajama Mutants

    @yaireo/relative-time
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    Transform timestamp or date to local relative-time


    Features:

    • Super lightweight (< 500 bytes minified)
    • Uses native browser API

    Install:

    Use from CDN / Download from this repo / NPM

    npm i @yaireo/relative-time -S

    Usage:

    Import CSS file via JS

    import RelativeTime from '@yaireo/relative-time'

    And use

    const relativeTime = new RelativeTime(); // defaults to OS locale
    const relativeTimeSpanish = new RelativeTime({ locale: 'es' }); // set locale to Spanish
    
    console.log(   relativeTime.from(new Date('2015'))  )  // "6 years ago"
    console.log(   relativeTimeSpanish.from(new Date('2015'))  )  // "hace 6 años"

    Live demo

    Install

    npm i @yaireo/relative-time

    DownloadsWeekly Downloads

    417

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    5.95 kB

    Total Files

    5

    Last publish

    Collaborators

    • vsync