sri-lanka-banks
v1.0.0
Published
npm package to get and select Sri lankan banks and branch codes
Maintainers
Readme
sri-lanka-banks
A comprehensive npm package for Sri Lankan banks and their branches data. Perfect for building financial applications, forms, and services that need accurate bank and branch information for Sri Lanka.
Features
- ✅ Complete list of Sri Lankan banks
- ✅ Comprehensive branch data for each bank
- ✅ TypeScript support
- ✅ Framework agnostic (works with React, Vue, Angular, and vanilla JS)
- ✅ Lightweight and fast
- ✅ Easy-to-use API
- ✅ Regular updates with latest bank information
Installation
npm install sri-lanka-banksyarn add sri-lanka-bankspnpm add sri-lanka-banksQuick Start
import { bankOptions, branchOptions, getBranchesByBankId } from "sri-lanka-banks";
// Get all banks
console.log(bankOptions);
// Get all branches
console.log(branchOptions);
// Get branches for a specific bank
const bankId = 1;
const branches = getBranchesByBankId(bankId);
console.log(branches);API Reference
bankOptions
An array of all Sri Lankan banks.
type BankOption = {
value: number;
label: string;
};branchOptions
An array of all bank branches across Sri Lanka.
type BranchOption = {
id: number;
name: string;
};getBranchesByBankId(bankId: number)
Returns all branches for a specific bank.
Parameters:
bankId(number): The ID of the bank
Returns: Array of branch objects for the specified bank.
Framework Examples
React
import React from "react";
import { bankOptions, getBranchesByBankId } from "sri-lanka-banks";
export function BankSelect() {
const [bankId, setBankId] = React.useState(null);
return (
<div>
<select onChange={e => setBankId(Number(e.target.value))}>
<option value="">Select Bank</option>
{bankOptions.map(b => (
<option key={b.value} value={b.value}>{b.label}</option>
))}
</select>
{bankId && (
<select>
<option value="">Select Branch</option>
{getBranchesByBankId(bankId).map(br => (
<option key={br.id} value={br.id}>{br.name}</option>
))}
</select>
)}
</div>
);
}Vue 3 (Composition API)
<script setup>
import { bankOptions, getBranchesByBankId } from "sri-lanka-banks";
import { ref } from "vue";
const bankId = ref(null);
const branches = ref([]);
function onBankChange() {
branches.value = getBranchesByBankId(bankId.value);
}
</script>
<template>
<select v-model="bankId" @change="onBankChange">
<option disabled value="">Select Bank</option>
<option v-for="b in bankOptions" :key="b.value" :value="b.value">
{{ b.label }}
</option>
</select>
<select v-if="branches.length">
<option disabled value="">Select Branch</option>
<option v-for="br in branches" :key="br.id" :value="br.id">
{{ br.name }}
</option>
</select>
</template>Angular
import { Component } from '@angular/core';
import { bankOptions, getBranchesByBankId } from "sri-lanka-banks";
@Component({
selector: 'app-bank-select',
template: `
<select (change)="onBankSelect($event.target.value)">
<option value="">Select Bank</option>
<option *ngFor="let bank of banks" [value]="bank.value">
{{ bank.label }}
</option>
</select>
<select *ngIf="branches.length">
<option value="">Select Branch</option>
<option *ngFor="let branch of branches" [value]="branch.id">
{{ branch.name }}
</option>
</select>
`
})
export class BankSelectComponent {
banks = bankOptions;
branches = [];
onBankSelect(bankId: string) {
if (bankId) {
this.branches = getBranchesByBankId(Number(bankId));
} else {
this.branches = [];
}
}
}Vanilla JavaScript
<!DOCTYPE html>
<html>
<head>
<script type="module">
import { bankOptions, getBranchesByBankId } from "sri-lanka-banks";
const bankSelect = document.getElementById('bankSelect');
const branchSelect = document.getElementById('branchSelect');
// Populate banks
bankOptions.forEach(bank => {
const option = document.createElement('option');
option.value = bank.value;
option.textContent = bank.label;
bankSelect.appendChild(option);
});
// Handle bank selection
bankSelect.addEventListener('change', (e) => {
const bankId = Number(e.target.value);
branchSelect.innerHTML = '<option value="">Select Branch</option>';
if (bankId) {
const branches = getBranchesByBankId(bankId);
branches.forEach(branch => {
const option = document.createElement('option');
option.value = branch.id;
option.textContent = branch.name;
branchSelect.appendChild(option);
});
}
});
</script>
</head>
<body>
<select id="bankSelect">
<option value="">Select Bank</option>
</select>
<select id="branchSelect">
<option value="">Select Branch</option>
</select>
</body>
</html>Data Structure
Bank Object
{
value: number; // Unique bank ID
label: string; // Bank name
}Branch Object
{
id: number; // Unique branch ID
name: string; // Branch name
}Use Cases
- Banking Applications: Account opening forms, transfer forms
- E-commerce: Payment gateway integrations
- Financial Services: Loan applications, investment platforms
- Government Services: Tax filing, subsidy applications
- Remittance Services: Money transfer applications
- Insurance: Policy applications requiring bank details
TypeScript Support
This package includes TypeScript definitions out of the box:
import { BankOption, BranchOption } from "sri-lanka-banks";
export const banks: BANK[] = [
{ id: 7010, name: "Bank of Ceylon" },
{ id: 7038, name: "Standard Chartered Bank" },
{ id: 7047, name: "Citi Bank" },
{ id: 7056, name: "Commercial Bank PLC" },
{ id: 7074, name: "Habib Bank Ltd" },
{ id: 7083, name: "Hatton National Bank PLC" },
{ id: 7092, name: "Hongkong Shanghai Bank" },
{ id: 7108, name: "Indian Bank" },
{ id: 7117, name: "Indian Overseas Bank" },
{ id: 7135, name: "Peoples Bank" },
{ id: 7144, name: "State Bank of India" },
{ id: 7162, name: "Nations Trust Bank PLC" },
{ id: 7205, name: "Deutsche Bank" },
{ id: 7214, name: "National Development Bank PLC" },
{ id: 7269, name: "MCB Bank Ltd" },
{ id: 7278, name: "Sampath Bank PLC" },
{ id: 7287, name: "Seylan Bank PLC" },
{ id: 7296, name: "Public Bank" },
{ id: 7302, name: "Union Bank of Colombo PLC" },
{ id: 7311, name: "Pan Asia Banking Corporation PLC" },
{ id: 7384, name: "ICICI Bank Ltd" },
{ id: 7454, name: "DFCC Bank PLC" },
{ id: 7463, name: "Amana Bank PLC" },
{ id: 7472, name: "Axis Bank" },
{ id: 7481, name: "Cargills Bank Limited" },
{ id: 7719, name: "National Savings Bank" },
{ id: 7728, name: "Sanasa Development Bank" },
{ id: 7737, name: "HDFC Bank" },
{ id: 7746, name: "Citizen Development Business Finance PLC" },
{ id: 7755, name: "Regional Development Bank" },
{ id: 7764, name: "State Mortgage & Investment Bank" },
{ id: 7773, name: "LB Finance PLC" },
{ id: 7782, name: "Senkadagala Finance PLC" },
{ id: 7807, name: "Commercial Leasing and Finance" },
{ id: 7816, name: "Vallibel Finance PLC" },
{ id: 7825, name: "Central Finance PLC" },
{ id: 7834, name: "Kanrich Finance Limited" },
{ id: 7852, name: "Alliance Finance Company PLC" },
{ id: 7861, name: "LOLC Finance PLC" },
{ id: 7870, name: "Commercial Credit & Finance PLC" },
{ id: 7898, name: "Merchant Bank of Sri Lanka & Finance PLC" },
{ id: 7904, name: "HNB Grameen Finance Limited" },
{ id: 7913, name: "Mercantile Investment and Finance PLC" },
{ id: 7922, name: "People's Leasing & Finance PLC" },
{ id: 8004, name: "Central Bank of Sri Lanka" }
]
export const branches: Record<number, BRANCH[]> = {
7010: [
{ "id": 1, "name": "City Office" },
{ "id": 2, "name": "Kandy" },
{ "id": 3, "name": "Galle Fort" },
{ "id": 4, "name": "Pettah" },
{ "id": 5, "name": "Jaffna" },
...
],
}Contributing
We welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Guidelines
- Ensure data accuracy
- Add tests for new features
- Update documentation
- Follow existing code style
Data Updates
Bank and branch data is regularly updated to reflect:
- New bank establishments
- Branch openings and closures
- Name changes and mergers
- Regulatory updates
License
MIT License - see the LICENSE file for details.
Support
Changelog
See CHANGELOG.md for a detailed list of changes and updates.
