New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@osskit/currencies

Package Overview
Dependencies
Maintainers
0
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@osskit/currencies

A TypeScript library for handling currency codes, symbols, and conversions.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-7.68%
Maintainers
0
Weekly downloads
 
Created
Source

@osskit/currencies

A TypeScript library for handling currency codes, symbols, and conversions.

Installation

yarn add @osskit/currencies

or

npm install @osskit/currencies

Usage

Importing the library

import { getByCode, getByNumber, isCurrencyCode, toMajorUnit, toMinorUnit, getSymbolByCode, isAmount, calculateRate } from '@osskit/currencies';

Examples

Get currency by code
const currency = getByCode('EUR');
console.log(currency);
Get currency by number
const currency = getByNumber('978');
console.log(currency);
Check if a string is a valid currency code
const isValid = isCurrencyCode('USD');
console.log(isValid); // true
Convert to major unit
const majorUnit = toMajorUnit({ value: 100_000, currency: 'USD' });
console.log(majorUnit); // 1000
Convert to minor unit
const minorUnit = toMinorUnit(1000, 'USD');
console.log(minorUnit); // 100_000
Get symbol by currency code
const symbol = getSymbolByCode('USD');
console.log(symbol); // $
Check if an object is a valid amount
const validAmount = isAmount({ value: 1000, currency: 'USD' });
console.log(validAmount); // true
Calculate exchange rate
const rate = calculateRate({ value: 1000, currency: 'USD' }, { value: 800, currency: 'EUR' });
console.log(rate); // 0.8

Running Tests

To run the tests, use the following command:

yarn test

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 17 Feb 2025

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc