npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@betgames/bg-tools

v2.1.1

Published

Sharable Hooks and Utils

Downloads

436

Readme

bg-tools

This package has a lot of common features for all projects.

Hooks /
    useAfterUpdate
    useFade
    useFont
    useLandscape
    useMobileView
    useMounted
    useMutableState
    useOrientationAngle
    useRefCallback
    useScrollbar
    useUnmount
    useWindowsSize
    useScreenOrientation
    useTimerFinished
    useSecondsLeft

Utils /
    amountTok
    calcSecondsLeft
    camelCaseKeys
    forceCast
    formatAmount
    formatBettingOptions
    formatToCurrency
    getLocationOrigin
    getValidUrl
    isInputNumber
    isLandscape
    parseQuery
    roundToSeconds
    roundValue
    setImmediateTimeout
    sortBy
    templateReplace
    visibility
    timersRegistry

Repository /
    Storage

Styles / 
    base
    functions
    mixins
    variables
    
Services /
   audioService

Usage

import { useMobileView } from '@betgames/bg-tools';

const Component = () => {
    useMobileView(320);
    ...
};

Example how to use z-indexes-root function from functions.scss:

@import '~@betgames/bg-tools/src/styles/functions';

$z-indexes-list: (
    example1: (),
    example2: (),
);

@function z(layers...){
    $z-indexes-constructor($z-indexes-list, layers...)
}

Example how to use RadioButton from bg-tools

  1. Create your scss file with styles for RadioButton, by default this component haven't color, width, height, only common styles
  2. For customizing RadioButton, create some variables in scss file. Like here .radio-button { --radio-width: 3.5em; --radio-height: 2em; --radio-border-color: $dark-purple; --radio-icon-height: 1.5em; --radio-icon-width: 1.5em; --radio-icon-bottom-pos: 0.18em; --radio-icon-color: $dark-purple; --radio-background-enabled: $radio-success; --radio-border-color-enabled: $radio-border; --radio-box-shadow-enabled: 0px 0px 4px $radio-success; --radio-icon-transform-x-pos: 1.3em; --radio-icon-color-enabled: $white; }
  3. Description about each variable --radio-width - Width of Radio button --radio-height - Height of Radio button --radio-border-color - border color of Radio button --radio-icon-height - Height of circle icon in Radio button --radio-icon-width - Width of circle icon in Radio button --radio-icon-bottom-pos - This property needed for setting position of circle-icon by Y axis if you changed height of Radio button --radio-icon-color - Color of circle-icon in Radio button --radio-background-enabled - Background color of Radio button when it enabled --radio-border-color-enabled - Border color of Radio button when it enabled --radio-box-shadow-enabled - Box shadow of Radio button when it enabled --radio-icon-transform-x-pos - This property needed for setting position by X axis of circle-icon when it enabled --radio-icon-color-enabled - Color of circle-icon when it enabled

Usage Timer class.

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 durations.setup once at app start to be setup unit duration units:
    import { durations } from '@betgames/bg-tools';
    
    durations.setup([
        'years',
        'months',
        'weeks',
        'days',
        'hours',
        'minutes',
        'seconds',
    ]);
  • For usage simply import the timer: import { timersRegistry } from '@betgames/bg-tools';

API

const { instance, destroy } = timersRegistry.create(options)

interface ITimerOptions {
    id?: number | string; // use it to create shared intances, otherwise random will be generated
    seconds: number;
    offsetSeconds?: number;
    format?: string | Record<number, string>;
    onTick?: (timeString: string, secondsLeft: number) => void;
    onFinish?(): void;
    onUpdate?(): void;
    onAfterExactSecond?: {
        second: number;
        callback: {
            (): void;
            called?: boolean;
        };
    };
    showDurationUnits?: boolean;
}

Timer instance


interface ITimerInstance {
    stop(): void;
    subscribe(options: ITimerSubscribeOptions): () => void;
    update(seconds: number): 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.