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 🙏

© 2026 – Pkg Stats / Ryan Hefner

bank-of-thailand

v1.0.1

Published

TypeScript/JavaScript client for Bank of Thailand API - Works with Node.js, Bun, and browsers

Readme

bank-of-thailand-js

TypeScript/JavaScript client for Bank of Thailand API - Works with Node.js, Bun, and browsers

NPM Version License TypeScript

Modern, type-safe client for the Bank of Thailand API with built-in analytics, CSV export, and universal runtime support (Node.js 20+, Bun 1.3+, browsers).

Features

  • 11 API Resources - Complete BOT API coverage
  • Rich Analytics - Built-in statistics, change analysis, volatility calculations
  • CSV Export - Save data to CSV (Node.js) or download in browser
  • Type-Safe - Full TypeScript 5.7 support with excellent IntelliSense
  • Universal - Works in Node.js, Bun, Deno, and browsers
  • Zero Dependencies - Lightweight and fast
  • Modern Stack - Built with 2025 best practices

Installation

# npm
npm install bank-of-thailand

# pnpm (recommended)
pnpm add bank-of-thailand

# yarn
yarn add bank-of-thailand

# bun
bun add bank-of-thailand

Quick Start

1. Get API Token

Get your API token from BOT API Portal

2. Set Up Environment

Create .env file:

BOT_API_TOKEN=your_api_token_here

For Bun: .env files are automatically loaded (no package needed)

For Node.js: Install dotenv:

npm install dotenv

Then import at the top of your file:

import 'dotenv/config';

Or use Node.js 20.6+ built-in:

node --env-file=.env your-script.js

3. Use the Client

import { createClient } from 'bank-of-thailand';

// Bun: .env automatically loaded
// Node.js: Make sure to import 'dotenv/config' first

const client = createClient({
  apiToken: process.env.BOT_API_TOKEN,
});

// Fetch exchange rates
const rates = await client.exchangeRate.daily({
  startPeriod: '2025-01-01',
  endPeriod: '2025-01-31',
});

// Use built-in analytics
console.log('Average:', rates.average('rate'));
console.log('Trend:', rates.trend('rate'));
console.log('Volatility:', rates.volatility('rate'));

// Export to CSV
await rates.saveCSV('rates.csv');

API Resources

1. Exchange Rate

// Daily weighted-average interbank exchange rate
const daily = await client.exchangeRate.daily({
  startPeriod: '2025-01-01',
  endPeriod: '2025-01-31',
});

// Monthly, quarterly, annual
const monthly = await client.exchangeRate.monthly({ ... });
const quarterly = await client.exchangeRate.quarterly({ ... });
const annual = await client.exchangeRate.annual({ ... });

2. Average Exchange Rate

const avgRates = await client.averageExchangeRate.daily({
  startPeriod: '2025-01-01',
  endPeriod: '2025-01-31',
});

See full documentation for all 11 API resources.

Response Analytics

All API responses include powerful analytics methods:

const rates = await client.exchangeRate.daily({ ... });

// Statistics
rates.min('rate');        // Minimum value
rates.max('rate');        // Maximum value
rates.average('rate');    // Average (mean)
rates.sum('rate');        // Sum of all values

// Change Analysis
const change = rates.change('rate');
console.log(change.percentage);  // Percentage change
console.log(change.absolute);    // Absolute change

// Volatility
const vol = rates.volatility('rate');

// Trend Detection
const trend = rates.trend('rate');  // 'up' | 'down' | 'flat'

// CSV Export
await rates.saveCSV('rates.csv');

See Analytics Guide for complete documentation.

Error Handling

import { 
  AuthenticationError,
  RateLimitError,
  NotFoundError 
} from 'bank-of-thailand';

try {
  const rates = await client.exchangeRate.daily({ ... });
} catch (error) {
  if (error instanceof AuthenticationError) {
    console.error('Invalid API token');
  } else if (error instanceof RateLimitError) {
    console.error(`Rate limited. Retry after ${error.retryAfter}s`);
  }
}

Environment Configuration

The library requires an API token which should be loaded from environment variables for security.

Quick Setup:

  1. Copy .env.example to .env
  2. Add your token: BOT_API_TOKEN=your_token_here
  3. Bun: Auto-loaded ✅ | Node.js: Use dotenv or --env-file

See the complete Environment Variables Guide for:

  • Node.js, Bun, Deno setup
  • Production deployment (Docker, Kubernetes, AWS, Vercel, etc.)
  • Best practices and security tips
  • Troubleshooting common issues

Requirements

  • Node.js: 20.0.0 or higher
  • Bun: 1.3.0 or higher
  • Browsers: Modern browsers with native fetch support

Development

Built with the 2025 modern stack:

  • Bun Test - 35x faster than Jest
  • Biome - All-in-one formatter & linter
  • tsup - Fast TypeScript bundler
  • pnpm - Efficient package management
# Install dependencies
pnpm install

# Run tests
bun test

# Build
pnpm build

# Lint and format
pnpm lint:fix

License

MIT

Links


Built with the 2025 modern JavaScript stack