# sharp-timer

> Simple timers utility library with api (mostly) inspired by .NET equivalents

Latest version **0.1.6** (published 2019-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install sharp-timer
pnpm add sharp-timer
yarn add sharp-timer
bun add sharp-timer
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2019-09-10 |
| First published | 2017-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 62.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | afractal |
| Maintainers | afractal |
| Keywords | sharp-timer, sharp, timer, timers |

## Links

- npm: https://www.npmjs.com/package/sharp-timer
- Repository: https://github.com/afractal/SharpTimer
- Homepage: https://github.com/afractal/SharpTimer#readme
- Issues: https://github.com/afractal/SharpTimer/issues
- npm.io page: https://npm.io/package/sharp-timer

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.1.6 (latest) — 2019-09-10
- 0.1.5 — 2018-04-29
- 0.1.4 — 2018-02-19
- 0.1.3 — 2017-08-20
- 0.1.2 — 2017-08-20
- 0.1.1 — 2017-08-18
- 0.1.0-b — 2017-07-02
- 0.1.0-a — 2017-06-18
- 0.1.0 — 2017-06-18
- 0.0.5 — 2017-06-18
- 0.0.4 — 2017-06-15
- 0.0.3-d — 2017-06-01
- 0.0.3-c — 2017-05-31
- 0.0.3-a — 2017-05-28
- 0.0.3 — 2017-05-26
- … 16 more at https://npm.io/package/sharp-timer/versions

## README

# SharpTimer

[![npm version](https://badge.fury.io/js/sharp-timer.svg)](https://badge.fury.io/js/sharp-timer)
[![npm](https://img.shields.io/npm/dt/sharp-timer.svg)]()
[![Build Status](https://travis-ci.org/afractal/SharpTimer.svg?branch=master)](https://travis-ci.org/afractal/SharpTimer)
[![Coverage Status](https://coveralls.io/repos/github/afractal/SharpTimer/badge.svg?branch=master)](https://coveralls.io/github/afractal/SharpTimer?branch=master)
[![codebeat badge](https://codebeat.co/badges/4b996a15-b593-4b28-9c61-84e0029912fc)](https://codebeat.co/projects/github-com-afractal-sharptimer-master)
[![Maintainability](https://api.codeclimate.com/v1/badges/e50887c7ae8916778bfb/maintainability)](https://codeclimate.com/github/afractal/SharpTimer/maintainability)
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/grw42490qo9lnokb?svg=true)](https://ci.appveyor.com/project/hermesxgjini/sharptimer) -->
<!-- [![Test Coverage](https://api.codeclimate.com/v1/badges/e50887c7ae8916778bfb/test_coverage)](https://codeclimate.com/github/afractal/SharpTimer/test_coverage) -->

## Examples

### *Timer example*

Initializing a new timer and specifying an iterval of 5 min, specify the interval in seconds:

`let timer = new Timer(60 * 5);`

Register an interval elapsing event handler:
```javascript
timer.onIntervalElapsing(i => {
    console.log(`remaing time in seconds: ${i}`);
    console.log(`time is elapsing: ${timer.toString()}`);
});
```

Register an interval elapsed event handler.
```javascript
timer.onIntervalElapsed(() => {
    timer.stop();
    console.log('time completely elapsed');
});
```

Finally, call the start instance method.

`timer.start();`

### *Stopwatch example*

Initializing a new Stopwatch by calling the ctor

`let stopwatch = new Stopwatch();`

`stopwatch.start();`

or the static `startNew` function

`let stopwatch = Stopwatch.startNew();`

Remember to call dispose on the stopwatch after your done with that instance:
```javascript
const intervalId = setInterval(() => {
    console.log(`elapsedMilliseconds: ${stopwatch.elapsedMilliseconds}`);
}, 10);

setTimeout(() => {
    clearInterval(intervalId);
    stopwatch.dispose();
}, 100);
```

### *Timespan example*

Constructs a Timespan object by calling of its static functions
```javascript
const {
    days,
    hours,
    minutes,
    seconds,
    milliseconds
} = Timespan.fromDays(3);
```

and access its instance properties
```javascript
console.log(`milliseconds: ${milliseconds}`); // 259200000
console.log(`seconds: ${seconds}`); // 259200
console.log(`minutes: ${minutes}`); // 4320
console.log(`hours: ${hours}`); // 72
console.log(`days: ${days}`); // 3
```

## Changes

*v.0.1.**

- [x] timer feature
- [x] stopwatch feature
- [x] timespan feature
- [x] [type definitions](https://www.npmjs.com/package/@types/sharp-timer)
- [x] tests for timer, stopwatch and timespan

## License

This product is licensed under ther [MIT](./LICENSE.md) license.

---

<p align="center">
    made with :heart: by <a href="https://github.com/afractal">me</a>
</p>

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