
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@date-js/clever-date
Advanced tools
A Javascript module to show an intelligent date refreshed at regular intervals.
A javascript library (<10kB) to show an intelligent date refreshed at regular intervals.
A demo is available here.
Languages defined bellow are fully supported but you can add your own rules with other languages.
You can also contribute and suggest translations with a pull request.
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">25/01/2020 12h12</div>
Start the script:
CleverDate.start();
Let's see the result:
<div title="26/01/2020 12h12">2 minutes ago</div>
<div title="25/01/2020 12h12">Yesterday at 12:12</div>
npm install @date-js/clever-date
import CleverDate from '@date-js/clever-date';
<script src="https://cdn.jsdelivr.net/npm/@date-js/clever-date@2.0"></script>
Start the process :
CleverDate.start();
Stop the process:
CleverDate.stop();
If you add element dynamically.
window.dispatch(new Event('clever-date.update'));
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);
You can see examples in default rules file.
A rule is composed of some elements:
A callback which returns true if the rule matches.
DateInterval is injected in the callback: see DateInterval.ts for more information.
For improving performances, it's not necessary to analyse and parse your rule each time.
An object with the text for each language that you want to target.
FAQs
A Javascript module to show an intelligent date refreshed at regular intervals.
The npm package @date-js/clever-date receives a total of 15 weekly downloads. As such, @date-js/clever-date popularity was classified as not popular.
We found that @date-js/clever-date demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.