persian-bank-react 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mahdi Tasha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,528 @@
1
+ # Persian Bank React
2
+
3
+ [![npm version](https://img.shields.io/npm/v/persian-bank-react)](https://www.npmjs.com/package/persian-bank-react)
4
+ [![npm downloads](https://img.shields.io/npm/dm/persian-bank-react)](https://www.npmjs.com/package/persian-bank-react)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-first-3178C6)](https://www.typescriptlang.org/)
6
+ [![License](https://img.shields.io/npm/l/persian-bank-react)](LICENSE)
7
+
8
+ A lightweight, TypeScript-first React library for **Iranian bank icons and bank identification utilities**.
9
+
10
+ Identify Iranian banks from card numbers or SHEBA/IBAN values, and render their bank icons with a simple, type-safe API.
11
+
12
+ ```bash
13
+ npm install persian-bank-react
14
+ ```
15
+
16
+ ---
17
+
18
+ ## Why Persian Bank React?
19
+
20
+ Building Iranian financial interfaces often means maintaining the same bank mappings and icons across multiple projects.
21
+
22
+ This package brings those pieces into one small, reusable API:
23
+
24
+ - 🎨 **Bank icons** as scalable inline SVGs
25
+ - 💳 **Card → bank identification** using card BINs
26
+ - 🏦 **SHEBA → bank identification**
27
+ - 🧩 **TypeScript-first** API with autocomplete
28
+ - ⚡ **Zero runtime dependencies** beyond React
29
+ - 🪶 **Lightweight and tree-shakable**
30
+ - 🔒 **No network requests** for bank identification
31
+ - 🌐 Designed for financial products, SaaS applications, dashboards, checkout flows, and internal tools
32
+
33
+ Instead of maintaining your own bank database and SVG collection:
34
+
35
+ ```tsx
36
+ <BankIcon name="mellat" />
37
+ ```
38
+
39
+ or:
40
+
41
+ ```ts
42
+ const bank = getBankFromCard("6104 3300 0000 0000");
43
+
44
+ console.log(bank);
45
+ // {
46
+ // type: "mellat",
47
+ // name: "بانک ملت"
48
+ // }
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Installation
54
+
55
+ ```bash
56
+ npm install persian-bank-react
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Quick Start
62
+
63
+ ### Render a bank icon
64
+
65
+ ```tsx
66
+ import { BankIcon } from "persian-bank-react";
67
+
68
+ export function PaymentMethod() {
69
+ return (
70
+ <BankIcon name="mellat" width={48} height={48} aria-label="Bank Mellat" />
71
+ );
72
+ }
73
+ ```
74
+
75
+ Because the icon component accepts standard SVG props, you can style it with your existing UI system:
76
+
77
+ ```tsx
78
+ <BankIcon name="mellat" className="h-10 w-10" />
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Identify a Bank from a Card Number
84
+
85
+ Use `getBankFromCard()` to identify the issuing bank from an Iranian card number.
86
+
87
+ ```ts
88
+ import { getBankFromCard } from "persian-bank-react";
89
+
90
+ const bank = getBankFromCard("6037-9900-1234-5678");
91
+
92
+ if (bank) {
93
+ console.log(bank.type);
94
+ console.log(bank.name);
95
+ }
96
+ ```
97
+
98
+ Result:
99
+
100
+ ```ts
101
+ {
102
+ type: "melli",
103
+ name: "بانک ملی ایران"
104
+ }
105
+ ```
106
+
107
+ Formatted card numbers are supported:
108
+
109
+ ```ts
110
+ getBankFromCard("6037 9900 1234 5678");
111
+ getBankFromCard("6037-9900-1234-5678");
112
+ getBankFromCard(6037990012345678);
113
+ ```
114
+
115
+ If the bank cannot be identified:
116
+
117
+ ```ts
118
+ const bank = getBankFromCard("123456");
119
+
120
+ console.log(bank);
121
+ // null
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Identify a Bank from SHEBA
127
+
128
+ Use `getBankFromSheba()` to identify the bank from an Iranian SHEBA/IBAN.
129
+
130
+ ```ts
131
+ import { getBankFromSheba } from "persian-bank-react";
132
+
133
+ const bank = getBankFromSheba("IR123456789012345678901234");
134
+
135
+ if (bank) {
136
+ console.log(bank.type);
137
+ console.log(bank.name);
138
+ }
139
+ ```
140
+
141
+ Whitespace is automatically ignored:
142
+
143
+ ```ts
144
+ getBankFromSheba("IR12 3456 7890 1234 5678 9012 34");
145
+ ```
146
+
147
+ ### SHEBA without `IR`
148
+
149
+ If your data source provides the 24-digit numeric portion without the `IR` prefix:
150
+
151
+ ```ts
152
+ const bank = getBankFromSheba("123456789012345678901234", true);
153
+ ```
154
+
155
+ ---
156
+
157
+ ## Using Icons with Bank Detection
158
+
159
+ The utilities and icon component are designed to work together.
160
+
161
+ For example, a payment card component can identify the bank and render its icon:
162
+
163
+ ```tsx
164
+ import { BankIcon, getBankFromCard } from "persian-bank-react";
165
+
166
+ const bank = getBankFromCard(cardNumber);
167
+
168
+ return bank ? (
169
+ <BankIcon name={bank.type} width={40} height={40} aria-label={bank.name} />
170
+ ) : null;
171
+ ```
172
+
173
+ This makes it easy to build:
174
+
175
+ - Payment forms
176
+ - Wallet interfaces
177
+ - Banking dashboards
178
+ - Transaction lists
179
+ - Card selectors
180
+ - Checkout experiences
181
+ - Account management screens
182
+ - Financial SaaS products
183
+
184
+ ---
185
+
186
+ ## API
187
+
188
+ ### `BankIcon`
189
+
190
+ ```tsx
191
+ <BankIcon name="mellat" width={48} height={48} />
192
+ ```
193
+
194
+ #### Props
195
+
196
+ | Prop | Type | Required |
197
+ | -------------- | ------------------------- | -------- |
198
+ | `name` | `BankNameType` | Yes |
199
+ | SVG attributes | `SVGProps<SVGSVGElement>` | No |
200
+
201
+ All standard React SVG properties are supported.
202
+
203
+ ```tsx
204
+ <BankIcon
205
+ name="pasargad"
206
+ className="size-8"
207
+ aria-label="Bank Pasargad"
208
+ role="img"
209
+ />
210
+ ```
211
+
212
+ ---
213
+
214
+ ### `getBankFromCard`
215
+
216
+ ```ts
217
+ getBankFromCard(cardNumber: string | number): BankInfo | null
218
+ ```
219
+
220
+ Returns the bank associated with the first six digits of an Iranian payment card.
221
+
222
+ ```ts
223
+ const bank = getBankFromCard("6274121234567890");
224
+ ```
225
+
226
+ Returns:
227
+
228
+ ```ts
229
+ {
230
+ type: "eghtesaade-novin",
231
+ name: "بانک اقتصاد نوین"
232
+ }
233
+ ```
234
+
235
+ Returns `null` when the card BIN is not supported.
236
+
237
+ ---
238
+
239
+ ### `getBankFromSheba`
240
+
241
+ ```ts
242
+ getBankFromSheba(
243
+ sheba: string,
244
+ useIR?: boolean
245
+ ): BankInfo | null
246
+ ```
247
+
248
+ Identifies the bank from the four-digit bank code contained in an Iranian SHEBA/IBAN.
249
+
250
+ ```ts
251
+ const bank = getBankFromSheba("IR...");
252
+ ```
253
+
254
+ Returns `null` when the input format is invalid or the bank code is not supported.
255
+
256
+ ---
257
+
258
+ ## Types
259
+
260
+ The package exposes its main types for TypeScript applications.
261
+
262
+ ```ts
263
+ import type {
264
+ BankNameType,
265
+ BankInfo,
266
+ BankIconPropsType,
267
+ } from "persian-bank-react";
268
+ ```
269
+
270
+ ### `BankInfo`
271
+
272
+ ```ts
273
+ interface BankInfo {
274
+ type: BankNameType;
275
+ name: string;
276
+ }
277
+ ```
278
+
279
+ ### `BankNameType`
280
+
281
+ `BankNameType` is a union of supported bank identifiers:
282
+
283
+ ```ts
284
+ type BankNameType =
285
+ | "ayandeh"
286
+ | "mellat"
287
+ | "melli"
288
+ | "parsian"
289
+ | "pasargad"
290
+ | "saman"
291
+ | "tejarat"
292
+ // ...
293
+ | "unknown";
294
+ ```
295
+
296
+ Using a union instead of arbitrary strings provides autocomplete and compile-time validation:
297
+
298
+ ```ts
299
+ <BankIcon name="mellat" /> // ✅
300
+ <BankIcon name="pasargad" /> // ✅
301
+ <BankIcon name="something" /> // ❌ TypeScript error
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Supported Banks
307
+
308
+ The package currently includes icons and/or identification mappings for a broad range of Iranian banks and financial institutions, including:
309
+
310
+ - بانک آینده
311
+ - بانک مرکزی
312
+ - بانک صنعت و معدن
313
+ - بانک ملت
314
+ - بانک رفاه کارگران
315
+ - بانک مسکن
316
+ - بانک سپه
317
+ - بانک کشاورزی
318
+ - بانک ملی ایران
319
+ - بانک تجارت
320
+ - بانک صادرات ایران
321
+ - بانک توسعه صادرات ایران
322
+ - پست بانک
323
+ - بانک توسعه تعاون
324
+ - مؤسسه اعتباری توسعه
325
+ - بانک کارآفرین
326
+ - بانک پارسیان
327
+ - بانک اقتصاد نوین
328
+ - بانک سامان
329
+ - بانک پاسارگاد
330
+ - بانک سرمایه
331
+ - بانک سینا
332
+ - بانک قرض‌الحسنه مهر ایران
333
+ - بانک شهر
334
+ - بانک انصار
335
+ - بانک گردشگری
336
+ - بانک حکمت ایرانیان
337
+ - بانک دی
338
+ - بانک ایران زمین
339
+ - بانک قرض‌الحسنه رسالت
340
+ - بانک خاورمیانه
341
+ - بانک ایران و ونزوئلا
342
+ - بانک قوامین
343
+ - مؤسسه مالی و اعتباری کوثر
344
+ - مؤسسه مالی و اعتباری نور
345
+
346
+ > Bank coverage may differ between icon availability, card BIN mappings, and SHEBA mappings.
347
+
348
+ ---
349
+
350
+ ## Design & Technical Decisions
351
+
352
+ ### Inline SVG
353
+
354
+ Bank logos are rendered as inline SVG rather than external image files.
355
+
356
+ This means icons:
357
+
358
+ - Scale without losing quality
359
+ - Work well on high-DPI displays
360
+ - Can receive standard SVG attributes
361
+ - Don't require additional image requests
362
+ - Integrate naturally with React component systems
363
+
364
+ ### Local Bank Resolution
365
+
366
+ Bank identification is performed using local lookup tables.
367
+
368
+ There are:
369
+
370
+ - No API calls
371
+ - No external services
372
+ - No network dependency
373
+ - No user data sent anywhere
374
+
375
+ This makes the utilities predictable and suitable for client-side applications.
376
+
377
+ ### TypeScript-first
378
+
379
+ The public API is strongly typed so invalid bank identifiers are caught during development rather than at runtime.
380
+
381
+ ### Small API Surface
382
+
383
+ The package intentionally exposes a small set of focused primitives:
384
+
385
+ ```ts
386
+ BankIcon;
387
+ getBankFromCard;
388
+ getBankFromSheba;
389
+ ```
390
+
391
+ The goal is to make the library easy to learn and difficult to misuse.
392
+
393
+ ---
394
+
395
+ ## Accessibility
396
+
397
+ Because `BankIcon` renders a native SVG, standard accessibility attributes can be passed directly:
398
+
399
+ ```tsx
400
+ <BankIcon name="mellat" role="img" aria-label="Bank Mellat" />
401
+ ```
402
+
403
+ For decorative icons, hide them from assistive technologies:
404
+
405
+ ```tsx
406
+ <BankIcon name="mellat" aria-hidden="true" />
407
+ ```
408
+
409
+ ---
410
+
411
+ ## Example: Card Input
412
+
413
+ A practical example using the package with a React card input:
414
+
415
+ ```tsx
416
+ import { useState } from "react";
417
+ import { BankIcon, getBankFromCard } from "persian-bank-react";
418
+
419
+ export function CardInput() {
420
+ const [cardNumber, setCardNumber] = useState("");
421
+
422
+ const bank = getBankFromCard(cardNumber);
423
+
424
+ return (
425
+ <div>
426
+ <input
427
+ value={cardNumber}
428
+ onChange={(event) => setCardNumber(event.target.value)}
429
+ placeholder="Card number"
430
+ inputMode="numeric"
431
+ />
432
+
433
+ {bank && (
434
+ <div>
435
+ <BankIcon
436
+ name={bank.type}
437
+ width={32}
438
+ height={32}
439
+ aria-hidden="true"
440
+ />
441
+
442
+ <span>{bank.name}</span>
443
+ </div>
444
+ )}
445
+ </div>
446
+ );
447
+ }
448
+ ```
449
+
450
+ ---
451
+
452
+ ## Important: Identification ≠ Validation
453
+
454
+ `getBankFromCard()` identifies a bank from the card's BIN.
455
+
456
+ It does **not** verify that:
457
+
458
+ - The card number is currently active
459
+ - The card belongs to the person using it
460
+ - The card is valid according to banking infrastructure
461
+ - The card can perform transactions
462
+
463
+ Likewise, `getBankFromSheba()` identifies the bank from the SHEBA structure; it is **not a complete SHEBA validation service**.
464
+
465
+ Use dedicated validation logic when your application requires full financial-data validation.
466
+
467
+ ---
468
+
469
+ ## Contributing
470
+
471
+ Contributions are welcome.
472
+
473
+ If you find:
474
+
475
+ - A missing bank
476
+ - An incorrect bank mapping
477
+ - An outdated BIN
478
+ - An incorrect SHEBA code
479
+ - A broken icon
480
+ - A TypeScript/API issue
481
+
482
+ please open an issue or submit a pull request.
483
+
484
+ When contributing a new bank icon, please keep the implementation consistent with the existing SVG and component conventions.
485
+
486
+ ---
487
+
488
+ ## Development
489
+
490
+ Clone the repository and install dependencies:
491
+
492
+ ```bash
493
+ git clone <repository-url>
494
+
495
+ cd persian-bank-react
496
+
497
+ npm install
498
+ ```
499
+
500
+ Run the development environment:
501
+
502
+ ```bash
503
+ npm run dev
504
+ ```
505
+
506
+ Build the package:
507
+
508
+ ```bash
509
+ npm run build
510
+ ```
511
+
512
+ Run tests:
513
+
514
+ ```bash
515
+ npm test
516
+ ```
517
+
518
+ ---
519
+
520
+ ## License
521
+
522
+ MIT © Mahdi Tasha
523
+
524
+ ---
525
+
526
+ ## Author
527
+
528
+ Built and maintained by **Mahdi Tasha**.
@@ -0,0 +1,87 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { HTMLAttributes } from 'react';
3
+
4
+ /**
5
+ * Identifiers for supported Iranian banks and financial institutions.
6
+ *
7
+ * The values are intentionally kept as stable, lowercase identifiers
8
+ * so they can safely be used as component props, lookup keys, and
9
+ * serialized values.
10
+ */
11
+ type BankNameType$1 = "ayandeh" | "markazi" | "blue" | "caspian" | "dey" | "eghtesaade-novin" | "future" | "gardeshgari" | "iran-europe" | "iran-venezuela" | "iran-zamin" | "karafarin" | "keshavarzi" | "khavar-mianeh" | "maskan" | "mehr-iran" | "melall" | "mellat" | "melli" | "noor" | "parsian" | "pasargad" | "post" | "refah" | "resalat" | "saderat" | "saman" | "sanat-madan" | "sarmayeh" | "sepah" | "shahr" | "sina" | "standard-chartered" | "taavon-eslami" | "tejarat" | "tosee" | "tosee-sedarat" | "tossee-taavon" | "kosar" | "mehr-eghtesaad" | "ghavamin" | "hekmat" | "ansar" | "unknown";
12
+ /**
13
+ * Props shared by the BankIcon component.
14
+ *
15
+ * Extending SVG HTML attributes allows consumers to use standard
16
+ * SVG properties such as className, aria-label, width, height,
17
+ * and other native React SVG attributes.
18
+ */
19
+ interface BankIconPropsType extends HTMLAttributes<SVGElement> {
20
+ /** Identifier of the bank whose icon should be rendered. */
21
+ name: BankNameType$1;
22
+ }
23
+ /**
24
+ * Metadata associated with a bank.
25
+ *
26
+ * `type` is the stable identifier used internally by the icon system,
27
+ * while `name` represents the human-readable bank name.
28
+ */
29
+ interface BankInfo$1 {
30
+ type: BankNameType$1;
31
+ name: string;
32
+ }
33
+
34
+ type bankType_BankIconPropsType = BankIconPropsType;
35
+ declare namespace bankType {
36
+ export type { bankType_BankIconPropsType as BankIconPropsType, BankInfo$1 as BankInfo, BankNameType$1 as BankNameType };
37
+ }
38
+
39
+ /**
40
+ * Renders the icon for a supported Iranian bank.
41
+ *
42
+ * Each bank icon is kept as an inline SVG so it:
43
+ * - Scales cleanly at any size.
44
+ * - Inherits standard SVG/React props from the caller.
45
+ * - Doesn't require an additional image request.
46
+ */
47
+ declare function BankIcon({ name, ...props }: BankIconPropsType): false | react_jsx_runtime.JSX.Element;
48
+
49
+ type BankNameType = "ayandeh" | "markazi" | "blue" | "caspian" | "dey" | "eghtesaade-novin" | "future" | "gardeshgari" | "iran-europe" | "iran-venezuela" | "iran-zamin" | "karafarin" | "keshavarzi" | "khavar-mianeh" | "maskan" | "mehr-iran" | "melall" | "mellat" | "melli" | "noor" | "parsian" | "pasargad" | "post" | "refah" | "resalat" | "saderat" | "saman" | "sanat-madan" | "sarmayeh" | "sepah" | "shahr" | "sina" | "standard-chartered" | "taavon-eslami" | "tejarat" | "tosee" | "tosee-sedarat" | "tossee-taavon" | "kosar" | "mehr-eghtesaad" | "ghavamin" | "hekmat" | "ansar" | "unknown";
50
+ interface BankInfo {
51
+ type: BankNameType;
52
+ name: string;
53
+ }
54
+
55
+ /**
56
+ * Resolves the issuing bank from an Iranian card number.
57
+ *
58
+ * The function accepts both string and numeric input and normalizes
59
+ * formatting characters such as spaces or hyphens before performing
60
+ * the BIN lookup.
61
+ *
62
+ * @returns Bank metadata when the BIN is recognized; otherwise `null`.
63
+ */
64
+ declare function getBankFromCard(cardNumber: string | number): BankInfo | null;
65
+ /**
66
+ * Resolves the issuing bank from an Iranian SHEBA/IBAN number.
67
+ *
68
+ * Both formats are supported:
69
+ * - `IR` prefixed: `IRxxxxxxxxxxxxxxxxxxxxxxxx`
70
+ * - 24-digit numeric value when `useIR` is enabled
71
+ *
72
+ * Whitespace is ignored, making formatted SHEBA values safe to pass
73
+ * directly to the function.
74
+ *
75
+ * @param sheba - Iranian SHEBA/IBAN value.
76
+ * @param useIR - Whether the supplied value omits the `IR` prefix.
77
+ * @returns Bank metadata when the bank code is recognized; otherwise `null`.
78
+ */
79
+ declare function getBankFromSheba(sheba: string, useIR?: boolean): BankInfo | null;
80
+
81
+ declare const bankUtil_getBankFromCard: typeof getBankFromCard;
82
+ declare const bankUtil_getBankFromSheba: typeof getBankFromSheba;
83
+ declare namespace bankUtil {
84
+ export { bankUtil_getBankFromCard as getBankFromCard, bankUtil_getBankFromSheba as getBankFromSheba };
85
+ }
86
+
87
+ export { BankIcon, bankType as Types, bankUtil as Utils };