New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

clever-date

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clever-date

A Javascript module to show an intelligent date refreshing at regular intervals.

1.0.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Clever Date

A javascript module to show an intelligent date refreshing at regular intervals. Light and zero dependency.

Languages supported

Languages defined bellow are fully supported but you can add your own rules with other languages.

  • English
  • Français

You can also contribute and suggest translations with a pull request.

Example

Add an attribute to your date with the corresponding timestamp.

<div data-clever-date="1579950627">26/01/2020 12h12</div>
<div data-clever-date="1580037027">26/01/2020 12h12</div>

Start the script:

CleverDate.start();

Let's see the result:

<div>2 minutes ago</div>
<div>Yesterday at 12:12</div>

Some possible results:

  • Just now / A l'instant
  • 2 minutes ago / Il y a 2 minutes
  • 2 hours ago / Il y a 2 heures
  • Today at 11:46 / Aujourd'hui à 11h46
  • Yesterday at 11:46 / Hier à 11h46

Install and use it

ES6

npm install clever-date
import CleverDate from 'clever-date';

CleverDate.start();

Otherwise

<script src="https://cdn.jsdelivr.net/npm/clever-date@1.0/dist/clever-date.js"></script>
CleverDate.start();

Customize it

You have the full possibility to customize your rules by passing your configuration.

var configuration = {
    refresh: 5, // The minimal refreshing time
    selector: 'data-clever-date', // Elements with this attribute will be parsed
    rules: [
        {
             condition: function(dateIntervalItem) { return dateIntervalItem.day >= 365*10; }, text: {
                 fr: "Il y a %dd jour{%dd||s} (année %Y)",
                 en: "%dd day{%dd||s} ago (year %Y)"
             }
        }
    ]
}

CleverDate.start(configuration);

Keywords

date

FAQs

Package last updated on 17 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts