Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bpm-counter

johanbaaij4MIT1.2.0TypeScript support: included

JavaScript library for calculating BPMs.

readme

bpm-counter

CI Workflow npm package MIT License semantic-release Maintainability Test Coverage

JavaScript library for calculating beats per minute.

:stopwatch: Uses performance.now() by default, override with your own timestamps if necessary
:recycle: Automatically resets when pausing between taps

Usage

import { Counter } from 'bpm-counter';
const counter = new Counter();

Call the tap() method with a touch or click event.

counter.tap();

Optionally you can pass timestamps in ms.

counter.tap(0);
counter.tap(500);
counter.tap(1000);
counter.tap(1500);

Or initialize with an array of timestamps in ms.

const counter = new Counter([0, 500, 1000, 1500]);

To read the BPM:

counter.bpm;

Waiting 1.5 * average interval length will reset the counter. To reset manually:

counter.reset();

Installation

yarn add bpm-counter

or

npm install bpm-counter

Credits

  • TSDX – Zero-config CLI for TypeScript package development

changelog

1.2.0 (2020-04-09)

Features

  • named export for the Counter class (be5e889)

1.1.0 (2020-04-09)

Features

  • reset for non chronological timestamps (eefddff)