
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Lightweight JavaScript library for automatic relative time updates with intelligent shared timer
tempo-sync is a lightweight (3KB) JavaScript library that automatically updates all relative time elements on your page ("2 hours ago", "just now", etc.) using a single, intelligent shared timer.
npm install tempo-sync
Or use via CDN:
<script src="https://unpkg.com/tempo-sync@latest/dist/tempo-sync.min.js"></script>
<!-- Add data-tempo attribute to any element -->
<span data-tempo="2024-01-15T10:30:00Z">2 hours ago</span>
<div data-tempo="2024-01-15T08:00:00Z">4 hours ago</div>
<time data-tempo="2024-01-14T12:00:00Z">Yesterday</time>
<script>
// Initialize once
tempoSync.observe();
</script>
That's it! All timestamps will now update automatically at intelligent intervals.
tempoSync.observe()
Starts observing elements with data-tempo
attributes and begins automatic updates.
tempoSync.observe();
tempoSync.disconnect()
Stops observing and cleans up all timers and observers.
tempoSync.disconnect();
tempoSync.addElement(element)
Manually add an element to be tracked (usually not needed as observe() handles this automatically).
const element = document.querySelector('[data-tempo]');
tempoSync.addElement(element);
tempoSync.removeElement(element)
Manually remove an element from tracking.
tempoSync.removeElement(element);
<div class="post">
<h3>John shared a photo</h3>
<span data-tempo="2024-01-15T14:30:00Z">2 hours ago</span>
</div>
<div class="comment">
<p>Great photo!</p>
<small data-tempo="2024-01-15T15:45:00Z">45 minutes ago</small>
</div>
<div class="metrics">
<div class="metric">
<span>Last backup:</span>
<span data-tempo="2024-01-15T12:00:00Z">4 hours ago</span>
</div>
<div class="metric">
<span>Server restart:</span>
<span data-tempo="2024-01-15T06:30:00Z">10 hours ago</span>
</div>
</div>
import { useEffect } from 'react';
function App() {
useEffect(() => {
// Initialize tempo-sync when component mounts
tempoSync.observe();
// Cleanup when component unmounts
return () => tempoSync.disconnect();
}, []);
return (
<div>
<span data-tempo={new Date(Date.now() - 300000).toISOString()}>
5 minutes ago
</span>
</div>
);
}
<template>
<div>
<span :data-tempo="timestamp">{{ relativeTime }}</span>
</div>
</template>
<script>
export default {
data() {
return {
timestamp: new Date(Date.now() - 600000).toISOString(), // 10 minutes ago
relativeTime: '10 minutes ago'
};
},
mounted() {
tempoSync.observe();
},
beforeUnmount() {
tempoSync.disconnect();
}
};
</script>
Most relative time libraries create multiple timers (one per element) that update inefficiently:
// ❌ Traditional approach - wasteful
setInterval(() => updateElement1(), 1000); // Updates "3 days ago" every second
setInterval(() => updateElement2(), 1000); // Updates "1 year ago" every second
setInterval(() => updateElement3(), 1000); // Updates "just now" every second
tempo-sync uses one intelligent timer that knows when each element actually needs updating:
// ✅ tempo-sync approach - efficient
// "just now" updates every second
// "5 minutes ago" updates every minute
// "3 hours ago" updates every hour
// "2 days ago" updates daily
Elements | Traditional | tempo-sync | CPU Savings |
---|---|---|---|
10 | 10 timers | 1 timer | 90% |
100 | 100 timers | 1 timer | 99% |
1000 | 1000 timers | 1 timer | 99.9% |
tempo-sync automatically formats time differences into human-readable strings:
Time Difference | Output | Update Frequency |
---|---|---|
< 1 minute | "just now" | Every second |
1-59 minutes | "X minutes ago" | Every minute |
1-23 hours | "X hours ago" | Every hour |
1-6 days | "X days ago" | Every day |
1-4 weeks | "X weeks ago" | Every day |
1-11 months | "X months ago" | Every day |
1+ years | "X years ago" | Every day |
tempo-sync also supports future timestamps:
// Start/stop as needed
tempoSync.observe();
// Later...
tempoSync.disconnect();
// Restart
tempoSync.observe();
tempo-sync automatically detects new elements added to the DOM:
// This will be automatically tracked
const newElement = document.createElement('span');
newElement.setAttribute('data-tempo', new Date().toISOString());
newElement.textContent = 'just now';
document.body.appendChild(newElement);
// Any valid ISO 8601 timestamp works
const timestamps = [
'2024-01-15T10:30:00Z', // UTC
'2024-01-15T10:30:00-05:00', // With timezone
'2024-01-15T10:30:00.123Z', // With milliseconds
new Date().toISOString() // Current time
];
tempo-sync supports all module systems:
import tempoSync from 'tempo-sync';
const tempoSync = require('tempo-sync');
define(['tempo-sync'], function(tempoSync) {
// Use tempoSync
});
<script src="tempo-sync.min.js"></script>
<script>
// tempoSync is available globally
tempoSync.observe();
</script>
Run the test suite:
npm test
Or with Jest:
npm run test:jest
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
FAQs
Lightweight JavaScript library for automatic relative time updates with intelligent shared timer
The npm package tempo-sync receives a total of 0 weekly downloads. As such, tempo-sync popularity was classified as not popular.
We found that tempo-sync demonstrated a healthy version release cadence and project activity because the last version was released less than 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.