0.1.1 • Published 10 months ago
@crowdlinker/nestjs-commons v0.1.1
NestJS Commons
Commons for NestJS
Packages
- Lodash - lodash (v4.17.21)
Installation
npm install --save @crowdlinker/nestjs-commons
// or
// yarn add @crowdlinker/nestjs-commons
Usage
Constants
Example
import dayjs from 'dayjs';
import { DATE_FORMAT } from '@crowdlinker/nestjs-commons/constants/date';
new days().format(DATE_FORMAT); // 2021-05-21
Helpers
Helpers are common functions used throughout the codebase for performing some basic operations.
Example
import { isLeapYear } from '@crowdlinker/nestjs-commons/helpers/date';
if (isLeapYear()) {
// const noOfDays = 366;
} else {
// const noOfDays = 365;
}
HttpExceptionFilter
To know about what an HttpExceptionFilter is, please read the NestJS documentation.
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { AppService } from './app.service';
import { AppController } from './app.controller';
import { AppConfigService } from './config/app/config.service';
import { HttpExceptionFilter } from '@crowdlinker/nestjs-commons/exceptions/filters/http-exception';
@Module({
imports: [
// ...
],
controllers: [AppController],
providers: [
AppService,
{
provide: APP_FILTER,
useFactory: async (appConfigService: AppConfigService) => {
return new HttpExceptionFilter(appConfigService);
},
},
],
})
export class AppModule {}
Note: AppConfigService should implement AppConfigServiceInterface provided in `@crowdlinker/nestjs-commons/interfaces/config.interface. See example below:
import { Injectable } from '@nestjs/common';
import { AppConfig } from './config.interface';
import { ConfigService } from '@nestjs/config';
import { AppConfigServiceInterface } from '@crowdlinker/nestjs-commons/interfaces/config';
@Injectable()
export class AppConfigService implements AppConfigServiceInterface {
// ....
}
Important Points To Note
- Code is written in Typescript (v5.4.3)
Contributors
0.1.1
10 months ago
0.1.0
1 year ago
0.0.18
1 year ago
0.0.19
1 year ago
0.0.17
1 year ago
0.0.16
2 years ago
0.0.13
4 years ago
0.0.14
4 years ago
0.0.15
4 years ago
0.0.12
4 years ago
0.0.11
4 years ago
0.0.10
4 years ago
0.0.9
4 years ago
0.0.8
4 years ago
0.0.7
4 years ago
0.0.6
4 years ago
0.0.5
4 years ago
0.0.4
4 years ago
0.0.3
4 years ago
0.0.2
4 years ago
0.0.1
4 years ago