Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
The 'last-run' npm package is primarily used to record and retrieve the last time a function was executed. This is particularly useful in build tools and task runners where it's important to know when a task was last run to optimize build processes and avoid unnecessary work.
Recording last execution time
This feature allows you to capture the last time a specific task was executed. In this example, the 'last-run' package is used with Gulp to record the last execution time of 'example' task.
const lastRun = require('last-run');
const gulp = require('gulp');
function exampleTask(done) {
// task operations
done();
}
gulp.task('example', exampleTask);
lastRun.capture('example', Date.now());
Retrieving last execution time
This feature enables retrieving the last recorded execution time of a task. Here, the last execution time of the 'example' task is retrieved and logged.
const lastRun = require('last-run');
const lastExecutionTime = lastRun('example');
console.log('The last execution time of the example task was:', lastExecutionTime);
While 'date-fns' does not directly track function executions, it provides comprehensive date utilities that can be used to manipulate and format dates, which can be helpful in calculating time differences since the last run. It differs from 'last-run' as it's a general-purpose date utility library rather than specifically designed for tracking task executions.
Similar to 'date-fns', 'moment' is another robust date handling library which can be used in conjunction with task management to track and display times. It does not inherently track the last run times but can be used to format and calculate time since last execution, offering broader functionality in date manipulation compared to 'last-run'.
Capture and retrieve the last time a function was run.
var lastRun = require('last-run');
function myFunc() {}
myFunc();
// capture the run after (or before) calling the function
lastRun.capture(myFunc);
// retrieve the last run time
lastRun(myFunc);
//-> outputs the Date.now() when capture was called
Takes a function (fn
) and returns a timestamp of the last time the function was captured.
Returns undefined if the function has not been captured.
The timestamp is always given in millisecond but the time resolution can be reduced (rounded down).
The use case is to be able to compare a build time to a file time attribute.
On some file systems, fs.stat
time attributes like mtime
might have one second precision.
Takes a function (fn
) and captures the current timestamp with Date.now()
.
If passed the optional timestamp, captures that time instead of Date.now()
.
The captured timestamp can then be retrieved using the lastRun
function.
Takes a function (fn
) and removes the last run timestamp for it.
MIT
FAQs
Capture and retrieve the last time a function was run
We found that last-run demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.