@betgames/bg-countdown
TypeScript icon, indicating that this package has built-in type declarations

0.1.7 • Public • Published

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 reaces 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @betgames/bg-countdown

Weekly Downloads

12

Version

0.1.7

License

ISC

Unpacked Size

230 kB

Total Files

31

Last publish

Collaborators

  • betgames