@betgames/bg-countdown
v1.1.2
Published
Betgames countdown
Downloads
78
Readme
TESTS
- Run
yarn test
in command line to run tests
USAGE
- In the root directory
index.js
exposes public API - Webpack must be configured in your project
- First, need to call
setup
once at app start to be setup unit duration units:import { setup } from '@betgames/bg-countdown'; setup([ 'years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', ]);
- For usage simply import the timer:
import { createTimer } from '@betgames/bg-countdown';
- To import interfaces:
import { ITimerOptions, ITimerInstance } from '@betgames/bg-countdown';
API
createTimer(options)
interface ITimerOptions {
until: number;
format?: string | Record<number, string>;
onTick?: (timeString: string, secondsLeft: number) => void;
onFinish?(): void;
onAfterExactSecond?: {
second: number;
callback: {
(): void;
called?: boolean;
};
};
showDurationUnits?: boolean;
}
Timer instance
interface ITimerUpdateOptions {
until?: number;
onFinish?(): void;
}
interface ITimerInstance {
stop(): void;
update(options: ITimerUpdateOptions): void;
}
format
Parameter format
can be used as string, e.g.: HMS
,
or object: { 60: 'HM', 0: 'S' }
,
which means: "show hours and minutes until countdown reaches 60 seconds, then show seconds until reaches 0 seconds".
Supported format values: Y
(year), O
(month), D
(day), H
(hour), M
(minute), S
(second), also lowercase letters.
showDurationUnits
If parameter showDurationUnits
value is set to true
, then units for each period are displayed:
e.g.: 1h 5min 30s
, 6h 20min
, 25s
.