📝Random

The module provides a set of functions to generate random values.

Imports

import { RandomService } from 'niro-health';

Method of Use

To use this module, you need to inject it into the desired service.

import { Module } from '@nestjs/common';
import {
  RandomService,
  StringExService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IRandomService',
      useClass: RandomService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
  ],
})
export class AppModule {}

Injecting the module into our service.

import { Inject, Injectable } from '@nestjs/common';
import type { IRandomService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IRandomService')
    private readonly randomService: IRandomService,
  ) {}

  public integer() {
    return this.randomService.int(100);
  }
}

With dependencies

You will need to inject the following interfaces.

Interface
Service

IStringExService

Methods

Method
Scope
Description

int

public

Returns a random integer between min and max.

hash

public

Returns a random string format of HASH.

uuid

public

Returns a random string format of UUID.

password

public

Returns a random password.

string

public

Returns a random string of characters.

Last updated