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

nest-toolkit

v1.0.11

Published

NestJS useful toolkit

Downloads

1,256

Readme

NestJS Useful Toolkit

Useful tools for the NestJs framework based on Express.js . The tools are listed below:‌

Crypto, Decorators, Error Methods, Filters, Interceptors, Middlewares, Providers, Sha256, Swagger, Helpers, ...

Installation

# npm
$ npm install --save nest-toolkit

# yarn
$ yarn add nest-toolkit

Security Middlewares

// before use you must install required packages
$ npm i --save compression helmet morgan
// or
$ yarn add compression helmet morgan
// main.ts
import { UseCorsConfig, UseMainMiddlewares } from 'nest-toolkit';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    logger: ['error', 'warn', 'log', 'verbose'],
  });

  UseCorsConfig.use(app, {
    // CorsOptions
  });
  UseMainMiddlewares.use(app);

  await app.listen(3000);
}

bootstrap();

Prisma module

This module is used to work with Prisma ORM.

// before use you must install prisma
$ npm i --save prisma @prisma/client
// or
$ yarn add prisma @prisma/client
// app.module.ts
import { PrismaModule } from 'nest-toolkit';

@Module({
  imports: [PrismaModule],
})
export class AppModule {}
// your.service.ts
import { PrismaService, PaginatedResult } from 'nest-toolkit';

export class YourService {
  constructor(private readonly prisma: PrismaService) {}

  async firstUser(): Promise<any> {
    return await this.prisma.user.findFirst();
  }

  async paginate(meta: { page?: string; take?: string } = {}): Promise<PaginatedResult> {
    const query = {
      where: { ... },
      select: { ... },
      orderBy: { ... },
    };
    // paginate('model': string, meta: object, query: object)
    return await this.prisma.paginate('user', meta, query);
  }
}

Crypto module

This module is used to encrypt and decrypt strings. For this purpose, a hash is taken as a secret key.

// app.module.ts
import { CryptoModule } from 'nest-toolkit';

@Module({
  imports: [
    CryptoModule.register({
      secret: 'your secret key',
    }),
  ],
})
export class AppModule {}
// your.service.ts
import { CryptoService, TextEncrypt } from 'nest-toolkit';

export class YourService {
  constructor(private readonly crypto: CryptoService) {}

  testCrypto() {
    const encryptValue: TextEncrypt = this.crypto.encrypt('Nestjs');
    // console.log(encryptValue) -> { iv: 'hash', content: 'hash' }

    const text: string = this.crypto.decrypt(encryptValue);
    // console.log(text) -> Nestjs
  }
}

Sha256 module

This module is used to hash strings. It receives a secret key, which must be in the format "prefix_key.suffix_key". Pay attention to the dot in the middle of the format. Or you can inject the prefix and suffix without referencing the secret to the module.

// app.module.ts
import { Sha256Module } from 'nest-toolkit';

@Module({
  imports: [
    Sha256Module.register({
      secret: 'prefix_key.suffix_key',
      // or
      prefix: 'your prefix key',
      suffix: 'your suffix key',
    }),
  ],
})
export class AppModule {}
// your.service.ts
import { Sha256Service } from 'nest-toolkit';

export class YourService {
  constructor(private readonly sha256: Sha256Service) {}

  testSha256() {
    const hash = this.sha256.strToSha256('Nestjs');
    // console.log(hash) -> 9Zzgx2HPoCk0yAlp8qB1jSOpmm/6khXYJnSyfYIakxU=

    const isValidHash = this.sha256.validateSha256('Nestjs', hash);
    // console.log(isValidHash) -> true
  }
}

Swagger Starter

This tools has custom styles

// main.ts
import { SwaggerStarter } from 'nest-toolkit';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  SwaggerStarter(app, 'docs');

  await app.listen(3000);
}

bootstrap();

Author

Mostafa Gholami (Github Page)