# last-run

> Capture and retrieve the last time a function was run

Latest version **2.0.0** (published 2022-01-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install last-run
pnpm add last-run
yarn add last-run
bun add last-run
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-01-10 |
| First published | 2015-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.13.0 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Gulp Team |
| Maintainers | yocontra, phated |
| Keywords | execution, function, last run, timing |

## Links

- npm: https://www.npmjs.com/package/last-run
- Repository: https://github.com/gulpjs/last-run
- Homepage: https://github.com/gulpjs/last-run#readme
- Issues: https://github.com/gulpjs/last-run/issues
- npm.io page: https://npm.io/package/last-run

## Recent versions

- 2.0.0 (latest) — 2022-01-10
- 1.1.1 — 2016-06-11
- 1.1.0 — 2015-06-12
- 1.0.0 — 2015-04-15
- 0.2.0 — 2015-04-12
- 0.1.1 — 2015-04-12
- 0.1.0 — 2015-04-11

## README

<p align="center">
  <a href="https://gulpjs.com">
    <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  </a>
</p>

# last-run

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]

Capture and retrieve the last time a function was run.

## Usage

```js
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
```

## API

### lastRun(fn, [timeResolution]) => [Timestamp]

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.

### lastRun.capture(fn, [timestamp])

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.

### lastRun.release(fn)

Takes a function (`fn`) and removes the last run timestamp for it.

## License

MIT

<!-- prettier-ignore-start -->
[downloads-image]: https://img.shields.io/npm/dm/last-run.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/last-run
[npm-image]: https://img.shields.io/npm/v/last-run.svg?style=flat-square

[ci-url]: https://github.com/gulpjs/last-run/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/last-run/dev?style=flat-square

[coveralls-url]: https://coveralls.io/r/gulpjs/last-run
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/last-run/master.svg?style=flat-square
<!-- prettier-ignore-end -->

---
_Source: https://npm.io/package/last-run · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
