Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
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
The npm package last-run receives a total of 813,372 weekly downloads. As such, last-run popularity was classified as popular.
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.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.