0.1.1 • Published 5 years ago

@dikman/ngx-tools v0.1.1

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

NgxTools

Usefull decorators and helpers for Angular project.

npm version

Install

npm install --save @dikman/ngx-tools

Usage

Decorators are exported as start case.

import { Debounce } from '@dikman/ngx-tools';

Decorators

These decorators are included in the package.

  • Debounce
  • Singleton

Debounce

Decorator that creates a debounced function that delays invoking function until after wait milliseconds have elapsed since the last time the debounced function was invoked.

import { Debounce } from '@dikman/ngx-tools';

export class ExampleComponent {
    @Debounce() protected searchSomeData(): void {
        ...
    }
}

Singleton

Decorator that restricts the instantiation of a class to one "single" instance. This is useful when exactly one object is needed to coordinate actions across the system.

    import { Singleton } from '@dikman/ngx-tools';

    @Injectable({
        providedIn: 'root'
    })
    @Singleton()
    export class ExampleService {
        constructor() {
            ...
        }
    }

Random Helper

Collection of functions for generating a random value of primitive types.

number(min, max)

Generates a random integer from a given range (a result can include at both the minimum and the maximum of the range).

    import { Random } from '@dikman/ngx-tools';

    console.log(Random.number(5, 25));

color()

Generates a random color as a string starts with the '#' char.

    import { Random } from '@dikman/ngx-tools';

    console.log(Random.color());

string(length)

Generates a random string of a given length.

    import { Random } from '@dikman/ngx-tools';

    console.log(Random.string(32));