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 🙏

© 2025 – Pkg Stats / Ryan Hefner

tcmb-xml-rates

v1.0.2

Published

A modern, type-safe TCMB (Central Bank of Turkey) XML exchange rates client for Node.js and Next.js with built-in caching and last business day fallback.

Downloads

296

Readme

tcmb-xml-rates (Türkçe)

npm version License: MIT

tcmb-xml-rates, TCMB’nin (Türkiye Cumhuriyet Merkez Bankası) yayınladığı XML döviz kurlarını
Node.js ve Next.js projelerinde modern, güvenilir ve TypeScript destekli bir yapıyla kullanmanı sağlar.

  • Dahili önbellekleme (in-memory cache)
  • Otomatik son iş günü fallback (hafta sonu / resmi tatil)
  • Promise tabanlı, TypeScript tipleri hazır bir API

Neden bu paket?

Piyasada TCMB için yazılmış bazı npm paketleri var; ancak çoğu:

  • çok eski (callback veya sadece CommonJS),
  • TypeScript tipi sunmuyor,
  • hafta sonu / resmi tatil mantığını ya hiç düşünmüyor ya da zayıf uyguluyor.

tcmb-xml-rates ile amaç:

  • Modern (ESM + CJS, TS-first),
  • Güvenilir (iş günü fallback + cache),
  • Kolay entegre edilebilir (Next.js route handler, server component, cron script)
    bir çözüm sunmak.

Özellikler

  • Modern & Hafif
    Promise tabanlı API, ESM + CJS desteği, minimum bağımlılık.

  • TypeScript Dostu
    Tam tip tanımları ile geliyor.

  • Güvenilir
    İstenilen tarihte veri yoksa (hafta sonu / resmi tatil), otomatik olarak bir önceki iş gününün kurlarını getirir (isteğe bağlı kapatılabilir).

  • Hızlı
    Aynı URL için gereksiz istekleri engelleyen dahili in-memory cache.

  • Kullanışlı yardımcılar
    Kolay kur dönüştürme (convert) ve döviz listesi alma (listCurrencies) fonksiyonları.


Kurulum

npm install tcmb-xml-rates
# veya
yarn add tcmb-xml-rates
# veya
pnpm add tcmb-xml-rates

Hızlı Başlangıç

import { getRate, convert } from 'tcmb-xml-rates';

// Bugünkü USD kurunu al (gerekirse son iş gününe fallback yapar)
const usd = await getRate('USD');

console.log('USD Alış:', usd?.forexBuying);
console.log('USD Satış:', usd?.forexSelling);

// 100 USD'yi TL'ye çevir
const tryAmount = await convert(100, 'USD', 'TRY');
console.log(`100 USD = ${tryAmount} TL`);

Kullanım

1. Bugünkü Kurları Getir

import { getRates } from 'tcmb-xml-rates';

const rates = await getRates();
console.log(rates);
// Örnek: [{ code: 'USD', forexBuying: 28.61, ... }, ...]
  • Bugün veri yoksa (örneğin Pazar günü) otomatik olarak bir önceki iş günü kullanılır.

2. Tek Bir Dövizin Kurunu Getir

import { getRate } from 'tcmb-xml-rates';

const eur = await getRate('EUR');

console.log('EUR Alış:', eur?.forexBuying);
console.log('EUR Satış:', eur?.forexSelling);

3. Kur Dönüştürme

import { convert } from 'tcmb-xml-rates';

// 100 EUR → TL
const tryAmount = await convert(100, 'EUR', 'TRY');

// 500 TL → USD
const usdAmount = await convert(500, 'TRY', 'USD');

// 200 EUR → USD (önce TL, sonra USD üzerinden çapraz kur)
const eurToUsd = await convert(200, 'EUR', 'USD');

console.log({ tryAmount, usdAmount, eurToUsd });

İstersen hangi alanı kullanacağını (forexSelling, banknoteBuying vs.) opsiyonlarla belirleyebilirsin.


4. Tarihli Veri & İş Günü Fallback

import { getRates } from 'tcmb-xml-rates';

const istediginTarih = '2025-11-16'; // Pazar diyelim

const rates = await getRates({ date: istediginTarih });

const actualDate = rates[0].date; // Örn: '2025-11-14' (Cuma)

if (actualDate !== istediginTarih) {
  console.log(
    `${istediginTarih} için veri yok. Son iş günü ${actualDate} kullanıldı.`
  );
}

Fallback’i kapatmak istersen:

const rates = await getRates({
  date: '2025-11-16',
  fallbackToLastBusinessDay: false,
}); // Veri yoksa hata fırlatır

Opsiyonlar

export interface GetRatesOptions {
  date?: Date | string;          // Belirli gün. Örn: '2025-11-19'
  rateType?: 'forex' | 'banknote' | 'all';
  fallbackToLastBusinessDay?: boolean; // Varsayılan: true
  cache?: boolean;               // Varsayılan: true
}

Next.js ile Kullanım (App Router)

Bu paket, Next.js içinde server-side kullanım için tasarlanmıştır (Server Components, Route Handlers, Server Actions). Böylece:

  • CORS problemleri yaşamazsın,
  • iç ağ mantığını / config’ini client tarafına sızdırmamış olursun.

Server Component Örneği

// app/page.tsx
import { getRate } from 'tcmb-xml-rates';

export default async function Page() {
  const usd = await getRate('USD');

  return (
    <main>
      <h1>Döviz Kurları</h1>
      <p>1 USD = {usd?.forexSelling} TL</p>
    </main>
  );
}

Route Handler Örneği

// app/api/rates/route.ts
import { getRates } from 'tcmb-xml-rates';
import { NextResponse } from 'next/server';

export async function GET() {
  try {
    const rates = await getRates();
    return NextResponse.json(rates);
  } catch (error) {
    console.error(error);
    return NextResponse.json(
      { error: 'Kurlar alınırken bir hata oluştu' },
      { status: 500 }
    );
  }
}

En İyi Pratikler

  • Her istekte TCMB’ye gitme. Dahili cache’i ve/veya kendi cache katmanını (Redis, KV, veritabanı) kullan.

  • Server-side kullan. Tarayıcıdan doğrudan TCMB endpoint’ine çağrı yapmak yerine, backend veya Next.js API route üzerinden çağır.

  • TCMB güncellemelerini gerçek zamanlı değil, günlük düşün. Bu veri daha çok günlük raporlama ve fiyatlama için uygundur, high-frequency trading için değil. 🙂


Uyarı & Teşekkür

Bu paket resmi değildir ve TCMB (Türkiye Cumhuriyet Merkez Bankası) ile hiçbir bağlantısı yoktur.

  • Veri kaynağı: Tüm kurlar doğrudan TCMB’nin resmi XML servisinden çekilir.
  • Kullanım koşulları: Lütfen TCMB’nin sitesindeki resmi şartları ve yasal uyarıları inceleyin.
  • Teşekkür: Bu veriyi kamuya açık sunduğu için TCMB’ye teşekkürler.

Lisans

MIT