Socket
Book a DemoInstallSign in
Socket

shopify-currencies.js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shopify-currencies.js

Simple wrapper to access Shopify's currency conversion rates from Node.js

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

Shopify Currencies.js

This package provides a simple wrapper to access Shopify's currency conversion rates from Node.js.

Installation

npm install shopify-currencies.js

Usage

import { loadCurrencies } from 'shopify-currencies.js';

const currencies = await loadCurrencies();

// Conversion rates for EUR
console.log(`Conversion rates for EUR: ${currencies.rates.EUR}`);

// Convert 1 USD to EUR
console.log(`1 USD is ${currencies.convert(1, 'USD', 'EUR')} EUR`);

API

loadCurrencies

Loads the current currency conversion rates from the Shopify CDN. Every call to this function will fetch the latest rates from the Shopify CDN, so cache the result if you need to.

const currencies = await loadCurrencies();

currencies.rates

The rates object contains the conversion rates for the currencies Shopify supports. The currency codes are three-letter ISO codes.

type Rates = {
  [currencyCode: string]: number;
};

const { rates } = await loadCurrencies();

// Conversion rates for EUR
console.log(`Conversion rates for EUR: ${rates.EUR}`);

currencies.convert

The convert function converts an amount from one currency to another. The conversion is implemented as amount * rates[from] / rates[to].

type Convert = (amount: number, from: string, to: string) => number;

const { convert } = await loadCurrencies();

const dollars = 5;
const euros = convert(dollars, 'USD', 'EUR');

Keywords

shopify

FAQs

Package last updated on 24 Apr 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