Socket
Book a DemoInstallSign in
Socket

nestjs-cashify

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestjs-cashify

Currency conversion module for nest

1.0.3
Source
npmnpm
Version published
Weekly downloads
776
-9.66%
Maintainers
1
Weekly downloads
 
Created
Source

Description

Currency conversion module for nestjs framework.

Installation

npm install nestjs-cashify

Usage

Basic Usage

Import CashifyModule in the main module with configuration

import { CashifyModule } from 'nestjs-cashify';

const rates = {
  GBP: 0.92,
  EUR: 1.00,
  USD: 1.12
};

@Module({
  imports: [CashifyModule.forRoot({base: 'EUR', rates})],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

forRootAsync with configuration

@Module({
  imports: [
    CashifyModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        base: configService.get<string>('BASE'), rates
      }),
      inject: [ConfigService]
    })
  ]
})
export class AppModule {}

Convert

In order to convert currencies to each other in controllers or services, we have two approaches:

Method 1: service method

import { CashifyService } from 'nestjs-cashify';

constructor(private cashifyService: CashifyService) {
  const result = this.cashifyService.convert(10, {from: 'EUR', to: 'GBP'});
  console.log(result);
}

Method 2: injecting instance of cashify class

Note: Since this module is based on nodejs cashify library, in case there can be more methods added to the core library, you can inject the instance and use it as following:

import { Cashify } from 'cashify';
import { CASHIFY } from 'nestjs-cashify';

constructor(@Inject(CASHIFY) private cashify: Cashify) {
  const result2 = this.cashify.convert(10, {from: 'EUR', to: 'GBP'});
  console.log(result2);
}

Parsing

Cashify supports parsing, so you can pass a string to the amount argument and the from and/or to currency will be automatically detected:

// Basic parsing
this.cashifyService.convert('€10 EUR', {to: 'GBP'});

// Full parsing
this.cashifyService.convert('10 EUR to GBP');

Support

Any support is welcome. You can give the project a star, if you liked it ⭐

Contribute

Feel free to contribute.

License

MIT

Keywords

nestjs

FAQs

Package last updated on 21 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.