finprim 0.1.0 → 0.1.2
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 +21 -0
- package/README.md +276 -0
- package/dist/card-D2-7wbam.d.mts +57 -0
- package/dist/card-D2-7wbam.d.ts +57 -0
- package/dist/index.d.mts +19 -113
- package/dist/index.d.ts +19 -113
- package/dist/index.js +228 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +220 -42
- package/dist/index.mjs.map +1 -1
- package/dist/nest/index.d.mts +18 -0
- package/dist/nest/index.d.ts +18 -0
- package/dist/nest/index.js +448 -0
- package/dist/nest/index.js.map +1 -0
- package/dist/nest/index.mjs +438 -0
- package/dist/nest/index.mjs.map +1 -0
- package/dist/react/index.d.mts +5 -46
- package/dist/react/index.d.ts +5 -46
- package/dist/react/index.js +105 -28
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +105 -29
- package/dist/react/index.mjs.map +1 -1
- package/dist/zod/index.d.mts +3 -36
- package/dist/zod/index.d.ts +3 -36
- package/dist/zod/index.js +150 -42
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +149 -43
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +43 -14
- package/dist/types-KG-eFvWt.d.mts +0 -32
- package/dist/types-KG-eFvWt.d.ts +0 -32
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Oluwatosin Adelaja
|
|
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,276 @@
|
|
|
1
|
+
# finprim
|
|
2
|
+
|
|
3
|
+
**Financial primitives for modern TypeScript applications.**
|
|
4
|
+
|
|
5
|
+
A unified, production-grade TypeScript library for validating and formatting financial data. No more stitching together five different packages. No more custom glue code. Just clean, typed, fintech-first utilities that work anywhere TypeScript runs.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Why finprim?
|
|
10
|
+
|
|
11
|
+
Every fintech team builds this internally. Sort code validation here, an IBAN check there, a custom currency formatter somewhere else. It's fragmented, inconsistent, and expensive to maintain.
|
|
12
|
+
|
|
13
|
+
finprim is the open source version of what your team has already written three times.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- ✅ IBAN validation and formatting (80+ countries, with country code)
|
|
20
|
+
- ✅ UK sort code and account number validation
|
|
21
|
+
- ✅ BIC/SWIFT validation
|
|
22
|
+
- ✅ Card number validation (Luhn, network detection, formatting)
|
|
23
|
+
- ✅ EU VAT number format validation (member states)
|
|
24
|
+
- ✅ US ABA routing number validation
|
|
25
|
+
- ✅ Loan/EMI calculation and schedule
|
|
26
|
+
- ✅ Format-only helpers (IBAN, sort code, account number) for display
|
|
27
|
+
- ✅ Currency validation and formatting with locale support
|
|
28
|
+
- ✅ Branded types for compile-time correctness
|
|
29
|
+
- ✅ Zod schemas out of the box
|
|
30
|
+
- ✅ Optional React hooks for form inputs
|
|
31
|
+
- ✅ Optional NestJS validation pipes
|
|
32
|
+
- ✅ Zero dependencies at the core
|
|
33
|
+
- ✅ Tree-shakeable ESM and CJS builds
|
|
34
|
+
- ✅ Fully typed
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npm install finprim
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For Zod integration:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install finprim zod
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
### Validation
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import {
|
|
58
|
+
validateIBAN,
|
|
59
|
+
validateUKSortCode,
|
|
60
|
+
validateUKAccountNumber,
|
|
61
|
+
validateBIC,
|
|
62
|
+
validateCardNumber,
|
|
63
|
+
validateCurrencyCode,
|
|
64
|
+
validateEUVAT,
|
|
65
|
+
validateUSRoutingNumber,
|
|
66
|
+
formatIBAN,
|
|
67
|
+
formatSortCode,
|
|
68
|
+
formatUKAccountNumber,
|
|
69
|
+
calculateEMI,
|
|
70
|
+
getLoanSchedule,
|
|
71
|
+
} from 'finprim'
|
|
72
|
+
|
|
73
|
+
const iban = validateIBAN('GB29NWBK60161331926819')
|
|
74
|
+
// { valid: true, value: 'GB29NWBK60161331926819', formatted: 'GB29 NWBK 6016 1331 9268 19', countryCode: 'GB' }
|
|
75
|
+
|
|
76
|
+
const sortCode = validateUKSortCode('60-16-13')
|
|
77
|
+
// { valid: true, value: '601613', formatted: '60-16-13' }
|
|
78
|
+
|
|
79
|
+
const account = validateUKAccountNumber('31926819')
|
|
80
|
+
// { valid: true, value: '31926819', formatted: '3192 6819' }
|
|
81
|
+
|
|
82
|
+
const card = validateCardNumber('4532015112830366')
|
|
83
|
+
// { valid: true, value: '...', formatted: '4532 0151 1283 0366', network: 'Visa', last4: '0366' }
|
|
84
|
+
|
|
85
|
+
const vat = validateEUVAT('DE123456789')
|
|
86
|
+
// { valid: true, value: 'DE123456789', formatted: 'DE 123456789', countryCode: 'DE' }
|
|
87
|
+
|
|
88
|
+
const routing = validateUSRoutingNumber('021000021')
|
|
89
|
+
// { valid: true, value: '021000021', formatted: '021000021' }
|
|
90
|
+
|
|
91
|
+
formatIBAN('GB29NWBK60161331926819') // 'GB29 NWBK 6016 1331 9268 19'
|
|
92
|
+
formatSortCode('601613') // '60-16-13'
|
|
93
|
+
formatUKAccountNumber('31926819') // '3192 6819'
|
|
94
|
+
|
|
95
|
+
const emi = calculateEMI(100_000, 10, 12) // monthly payment
|
|
96
|
+
const schedule = getLoanSchedule(100_000, 10, 12) // array of { month, payment, principal, interest, balance }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Currency Formatting
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { formatCurrency, parseMoney } from 'finprim'
|
|
103
|
+
|
|
104
|
+
formatCurrency(1000.5, 'GBP', 'en-GB') // '£1,000.50'
|
|
105
|
+
formatCurrency(1000.5, 'EUR', 'de-DE') // '1.000,50 €'
|
|
106
|
+
formatCurrency(1000.5, 'USD', 'en-US') // '$1,000.50'
|
|
107
|
+
|
|
108
|
+
parseMoney('£1,000.50') // { valid: true, amount: 1000.50, currency: 'GBP', formatted: '£1,000.50' }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Branded Types
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
import type { IBAN, SortCode, AccountNumber, CurrencyCode } from 'finprim'
|
|
115
|
+
|
|
116
|
+
// Invalid data cannot be passed where valid data is expected
|
|
117
|
+
function processPayment(iban: IBAN, amount: number) { ... }
|
|
118
|
+
|
|
119
|
+
// This forces validation before use
|
|
120
|
+
const iban = validateIBAN(input)
|
|
121
|
+
if (iban.valid) {
|
|
122
|
+
processPayment(iban.value, 100) // iban.value is typed as IBAN
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Zod Schemas
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { ibanSchema, sortCodeSchema, accountNumberSchema, currencySchema, vatSchema, routingNumberSchema } from 'finprim/zod'
|
|
130
|
+
|
|
131
|
+
const PaymentSchema = z.object({
|
|
132
|
+
iban: ibanSchema,
|
|
133
|
+
sortCode: sortCodeSchema,
|
|
134
|
+
accountNumber: accountNumberSchema,
|
|
135
|
+
amount: z.number().positive(),
|
|
136
|
+
currency: currencySchema,
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### React Hooks
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { useIBANInput, useCardNumberInput, useCurrencyInput } from 'finprim/react'
|
|
144
|
+
|
|
145
|
+
function PaymentForm() {
|
|
146
|
+
const iban = useIBANInput()
|
|
147
|
+
const card = useCardNumberInput()
|
|
148
|
+
const { rawValue, formatted, onChange } = useCurrencyInput('GBP', 'en-GB')
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<>
|
|
152
|
+
<input value={iban.value} onChange={iban.onChange} aria-invalid={iban.valid === false} />
|
|
153
|
+
<input value={card.formatted} onChange={card.onChange} aria-invalid={card.valid === false} />
|
|
154
|
+
<input value={formatted} onChange={onChange} />
|
|
155
|
+
</>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### NestJS Pipes
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
import { IbanValidationPipe, SortCodeValidationPipe, createValidationPipe } from 'finprim/nest'
|
|
164
|
+
import { validateIBAN } from 'finprim'
|
|
165
|
+
|
|
166
|
+
@Get('iban/:iban')
|
|
167
|
+
findByIban(@Param('iban', IbanValidationPipe) iban: string) {
|
|
168
|
+
return this.service.findByIban(iban)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const MyPipe = createValidationPipe(validateIBAN)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## API Reference
|
|
177
|
+
|
|
178
|
+
### Validation
|
|
179
|
+
|
|
180
|
+
| Function | Input | Returns |
|
|
181
|
+
|----------|-------|---------|
|
|
182
|
+
| `validateIBAN(input)` | `string` | `IBANValidationResult` (includes `countryCode` when valid) |
|
|
183
|
+
| `validateUKSortCode(input)` | `string` | `ValidationResult<SortCode>` |
|
|
184
|
+
| `validateUKAccountNumber(input)` | `string` | `ValidationResult<AccountNumber>` |
|
|
185
|
+
| `validateCurrencyCode(input)` | `string` | `ValidationResult<CurrencyCode>` |
|
|
186
|
+
| `validateBIC(input)` | `string` | `ValidationResult<BIC>` |
|
|
187
|
+
| `validateCardNumber(input)` | `string` | `CardValidationResult` (includes `network`, `last4` when valid) |
|
|
188
|
+
| `validateEUVAT(input)` | `string` | `VATValidationResult` (includes `countryCode` when valid) |
|
|
189
|
+
| `validateUSRoutingNumber(input)` | `string` | `ValidationResult<RoutingNumber>` |
|
|
190
|
+
|
|
191
|
+
### Formatting & display
|
|
192
|
+
|
|
193
|
+
| Function | Input | Returns |
|
|
194
|
+
|----------|-------|---------|
|
|
195
|
+
| `formatIBAN(input)` | `string` | `string` (space-separated, no validation) |
|
|
196
|
+
| `formatSortCode(input)` | `string` | `string` (XX-XX-XX) |
|
|
197
|
+
| `formatUKAccountNumber(input)` | `string` | `string` (XXXX XXXX) |
|
|
198
|
+
|
|
199
|
+
### Loan
|
|
200
|
+
|
|
201
|
+
| Function | Input | Returns |
|
|
202
|
+
|----------|-------|---------|
|
|
203
|
+
| `calculateEMI(principal, annualRatePercent, months)` | `number`, `number`, `number` | `number` |
|
|
204
|
+
| `getLoanSchedule(principal, annualRatePercent, months)` | `number`, `number`, `number` | `LoanScheduleEntry[]` |
|
|
205
|
+
|
|
206
|
+
### Formatting (currency)
|
|
207
|
+
|
|
208
|
+
| Function | Input | Returns |
|
|
209
|
+
|----------|-------|---------|
|
|
210
|
+
| `formatCurrency(amount, currency, locale?)` | `number`, `SupportedCurrency`, `string?` | `string` |
|
|
211
|
+
| `parseMoney(input)` | `string` | `MoneyResult` |
|
|
212
|
+
|
|
213
|
+
Validation results include a `formatted` string when valid (e.g. IBAN and card numbers are space-separated).
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Packages
|
|
218
|
+
|
|
219
|
+
| Import path | What it contains | Extra dependency |
|
|
220
|
+
|---|---|---|
|
|
221
|
+
| `finprim` | Core validators and formatters | none |
|
|
222
|
+
| `finprim/zod` | Zod schemas | `zod` |
|
|
223
|
+
| `finprim/react` | React hooks | `react` |
|
|
224
|
+
| `finprim/nest` | NestJS validation pipes | `@nestjs/common` |
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Tech Stack
|
|
229
|
+
|
|
230
|
+
- TypeScript
|
|
231
|
+
- tsup (build)
|
|
232
|
+
- Vitest (testing)
|
|
233
|
+
- React (optional hooks subpath)
|
|
234
|
+
- Zod (optional schema subpath)
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Roadmap
|
|
239
|
+
|
|
240
|
+
- [x] SWIFT / BIC validation
|
|
241
|
+
- [x] Luhn algorithm for card number validation
|
|
242
|
+
- [x] EU VAT number validation
|
|
243
|
+
- [x] NestJS pipe integration
|
|
244
|
+
- [x] US routing number validation
|
|
245
|
+
- [x] Loan/EMI calculation
|
|
246
|
+
- [x] Format-only helpers
|
|
247
|
+
- [ ] More locale coverage
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Contributing
|
|
252
|
+
|
|
253
|
+
Contributions are welcome. Please open an issue before submitting a pull request so we can discuss the change.
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
git clone https://github.com/YOUR_USERNAME/finprim
|
|
257
|
+
cd finprim
|
|
258
|
+
npm install
|
|
259
|
+
npm test
|
|
260
|
+
npm run dev
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Security
|
|
266
|
+
|
|
267
|
+
- **Input length**: All string validators reject input longer than 256 characters to limit memory and CPU use.
|
|
268
|
+
- **Type checking**: Validators require non-empty strings; numeric helpers (e.g. loan/currency) require finite numbers and sane bounds.
|
|
269
|
+
- **No sensitive logging**: The library does not log or persist input; use it in a way that avoids logging full card or account numbers.
|
|
270
|
+
- **Format helpers**: `formatIBAN`, `formatSortCode`, and `formatUKAccountNumber` cap input length and accept only strings to avoid abuse.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## License
|
|
275
|
+
|
|
276
|
+
MIT
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
declare const __brand: unique symbol;
|
|
2
|
+
type Brand<T, B> = T & {
|
|
3
|
+
readonly [__brand]: B;
|
|
4
|
+
};
|
|
5
|
+
type IBAN = Brand<string, 'IBAN'>;
|
|
6
|
+
type SortCode = Brand<string, 'SortCode'>;
|
|
7
|
+
type AccountNumber = Brand<string, 'AccountNumber'>;
|
|
8
|
+
type CurrencyCode = Brand<string, 'CurrencyCode'>;
|
|
9
|
+
type BIC = Brand<string, 'BIC'>;
|
|
10
|
+
type CardNumber = Brand<string, 'CardNumber'>;
|
|
11
|
+
type VATNumber = Brand<string, 'VATNumber'>;
|
|
12
|
+
type RoutingNumber = Brand<string, 'RoutingNumber'>;
|
|
13
|
+
type SupportedCurrency = 'GBP' | 'EUR' | 'USD' | 'JPY' | 'CHF' | 'CAD' | 'AUD' | 'NZD';
|
|
14
|
+
type ValidationSuccess<T> = {
|
|
15
|
+
valid: true;
|
|
16
|
+
value: T;
|
|
17
|
+
formatted: string;
|
|
18
|
+
};
|
|
19
|
+
type ValidationFailure = {
|
|
20
|
+
valid: false;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
24
|
+
declare function isValidationSuccess<T>(result: ValidationResult<T>): result is ValidationSuccess<T>;
|
|
25
|
+
declare function isValidationFailure<T>(result: ValidationResult<T>): result is ValidationFailure;
|
|
26
|
+
type IBANValidationSuccess = ValidationSuccess<IBAN> & {
|
|
27
|
+
countryCode: string;
|
|
28
|
+
};
|
|
29
|
+
type IBANValidationResult = IBANValidationSuccess | ValidationFailure;
|
|
30
|
+
type MoneyResult = {
|
|
31
|
+
valid: true;
|
|
32
|
+
amount: number;
|
|
33
|
+
currency: SupportedCurrency;
|
|
34
|
+
formatted: string;
|
|
35
|
+
} | {
|
|
36
|
+
valid: false;
|
|
37
|
+
error: string;
|
|
38
|
+
};
|
|
39
|
+
type VATValidationSuccess = ValidationSuccess<VATNumber> & {
|
|
40
|
+
countryCode: string;
|
|
41
|
+
};
|
|
42
|
+
type VATValidationResult = VATValidationSuccess | ValidationFailure;
|
|
43
|
+
|
|
44
|
+
type CardNetwork = 'Visa' | 'Mastercard' | 'Amex' | 'Discover' | 'Unknown';
|
|
45
|
+
type CardValidationResult = {
|
|
46
|
+
valid: true;
|
|
47
|
+
value: CardNumber;
|
|
48
|
+
formatted: string;
|
|
49
|
+
network: CardNetwork;
|
|
50
|
+
last4: string;
|
|
51
|
+
} | {
|
|
52
|
+
valid: false;
|
|
53
|
+
error: string;
|
|
54
|
+
};
|
|
55
|
+
declare function validateCardNumber(input: string): CardValidationResult;
|
|
56
|
+
|
|
57
|
+
export { type AccountNumber as A, type BIC as B, type CurrencyCode as C, type IBANValidationResult as I, type MoneyResult as M, type RoutingNumber as R, type SortCode as S, type ValidationResult as V, type SupportedCurrency as a, type VATValidationResult as b, type CardNetwork as c, type CardNumber as d, type CardValidationResult as e, type IBAN as f, type IBANValidationSuccess as g, type VATNumber as h, type VATValidationSuccess as i, type ValidationFailure as j, type ValidationSuccess as k, isValidationFailure as l, isValidationSuccess as m, validateCardNumber as v };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
declare const __brand: unique symbol;
|
|
2
|
+
type Brand<T, B> = T & {
|
|
3
|
+
readonly [__brand]: B;
|
|
4
|
+
};
|
|
5
|
+
type IBAN = Brand<string, 'IBAN'>;
|
|
6
|
+
type SortCode = Brand<string, 'SortCode'>;
|
|
7
|
+
type AccountNumber = Brand<string, 'AccountNumber'>;
|
|
8
|
+
type CurrencyCode = Brand<string, 'CurrencyCode'>;
|
|
9
|
+
type BIC = Brand<string, 'BIC'>;
|
|
10
|
+
type CardNumber = Brand<string, 'CardNumber'>;
|
|
11
|
+
type VATNumber = Brand<string, 'VATNumber'>;
|
|
12
|
+
type RoutingNumber = Brand<string, 'RoutingNumber'>;
|
|
13
|
+
type SupportedCurrency = 'GBP' | 'EUR' | 'USD' | 'JPY' | 'CHF' | 'CAD' | 'AUD' | 'NZD';
|
|
14
|
+
type ValidationSuccess<T> = {
|
|
15
|
+
valid: true;
|
|
16
|
+
value: T;
|
|
17
|
+
formatted: string;
|
|
18
|
+
};
|
|
19
|
+
type ValidationFailure = {
|
|
20
|
+
valid: false;
|
|
21
|
+
error: string;
|
|
22
|
+
};
|
|
23
|
+
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
24
|
+
declare function isValidationSuccess<T>(result: ValidationResult<T>): result is ValidationSuccess<T>;
|
|
25
|
+
declare function isValidationFailure<T>(result: ValidationResult<T>): result is ValidationFailure;
|
|
26
|
+
type IBANValidationSuccess = ValidationSuccess<IBAN> & {
|
|
27
|
+
countryCode: string;
|
|
28
|
+
};
|
|
29
|
+
type IBANValidationResult = IBANValidationSuccess | ValidationFailure;
|
|
30
|
+
type MoneyResult = {
|
|
31
|
+
valid: true;
|
|
32
|
+
amount: number;
|
|
33
|
+
currency: SupportedCurrency;
|
|
34
|
+
formatted: string;
|
|
35
|
+
} | {
|
|
36
|
+
valid: false;
|
|
37
|
+
error: string;
|
|
38
|
+
};
|
|
39
|
+
type VATValidationSuccess = ValidationSuccess<VATNumber> & {
|
|
40
|
+
countryCode: string;
|
|
41
|
+
};
|
|
42
|
+
type VATValidationResult = VATValidationSuccess | ValidationFailure;
|
|
43
|
+
|
|
44
|
+
type CardNetwork = 'Visa' | 'Mastercard' | 'Amex' | 'Discover' | 'Unknown';
|
|
45
|
+
type CardValidationResult = {
|
|
46
|
+
valid: true;
|
|
47
|
+
value: CardNumber;
|
|
48
|
+
formatted: string;
|
|
49
|
+
network: CardNetwork;
|
|
50
|
+
last4: string;
|
|
51
|
+
} | {
|
|
52
|
+
valid: false;
|
|
53
|
+
error: string;
|
|
54
|
+
};
|
|
55
|
+
declare function validateCardNumber(input: string): CardValidationResult;
|
|
56
|
+
|
|
57
|
+
export { type AccountNumber as A, type BIC as B, type CurrencyCode as C, type IBANValidationResult as I, type MoneyResult as M, type RoutingNumber as R, type SortCode as S, type ValidationResult as V, type SupportedCurrency as a, type VATValidationResult as b, type CardNetwork as c, type CardNumber as d, type CardValidationResult as e, type IBAN as f, type IBANValidationSuccess as g, type VATNumber as h, type VATValidationSuccess as i, type ValidationFailure as j, type ValidationSuccess as k, isValidationFailure as l, isValidationSuccess as m, validateCardNumber as v };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,127 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { c as
|
|
1
|
+
import { I as IBANValidationResult, V as ValidationResult, A as AccountNumber, S as SortCode, a as SupportedCurrency, M as MoneyResult, C as CurrencyCode, B as BIC, b as VATValidationResult, R as RoutingNumber } from './card-D2-7wbam.mjs';
|
|
2
|
+
export { c as CardNetwork, d as CardNumber, e as CardValidationResult, f as IBAN, g as IBANValidationSuccess, h as VATNumber, i as VATValidationSuccess, j as ValidationFailure, k as ValidationSuccess, l as isValidationFailure, m as isValidationSuccess, v as validateCardNumber } from './card-D2-7wbam.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Accepts IBANs with or without spaces.
|
|
7
|
-
* Validates: country code, expected length, characters, and mod97 checksum.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* validateIBAN('GB29NWBK60161331926819')
|
|
11
|
-
* // { valid: true, value: 'GB29NWBK60161331926819', formatted: 'GB29 NWBK 6016 1331 9268 19' }
|
|
12
|
-
*
|
|
13
|
-
* validateIBAN('GB00NWBK60161331926819')
|
|
14
|
-
* // { valid: false, error: 'IBAN checksum is invalid' }
|
|
15
|
-
*/
|
|
16
|
-
declare function validateIBAN(input: string): ValidationResult<IBAN>;
|
|
4
|
+
declare function formatIBAN(input: string): string;
|
|
5
|
+
declare function validateIBAN(input: string): IBANValidationResult;
|
|
17
6
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* Accepts formats: 60-16-13, 601613, 60 16 13
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* validateUKSortCode('60-16-13')
|
|
24
|
-
* // { valid: true, value: '601613', formatted: '60-16-13' }
|
|
25
|
-
*
|
|
26
|
-
* validateUKSortCode('999')
|
|
27
|
-
* // { valid: false, error: 'Sort code must be 6 digits...' }
|
|
28
|
-
*/
|
|
7
|
+
declare function formatSortCode(input: string): string;
|
|
8
|
+
declare function formatUKAccountNumber(input: string): string;
|
|
29
9
|
declare function validateUKSortCode(input: string): ValidationResult<SortCode>;
|
|
30
|
-
/**
|
|
31
|
-
* Validates a UK bank account number.
|
|
32
|
-
* Must be exactly 8 digits.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* validateUKAccountNumber('31926819')
|
|
36
|
-
* // { valid: true, value: '31926819', formatted: '3192 6819' }
|
|
37
|
-
*
|
|
38
|
-
* validateUKAccountNumber('1234')
|
|
39
|
-
* // { valid: false, error: 'UK account number must be exactly 8 digits' }
|
|
40
|
-
*/
|
|
41
10
|
declare function validateUKAccountNumber(input: string): ValidationResult<AccountNumber>;
|
|
42
11
|
|
|
43
12
|
declare const SUPPORTED_CURRENCIES: SupportedCurrency[];
|
|
44
|
-
/**
|
|
45
|
-
* Validates a currency code against supported ISO 4217 codes.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* validateCurrencyCode('GBP')
|
|
49
|
-
* // { valid: true, value: 'GBP', formatted: 'GBP' }
|
|
50
|
-
*
|
|
51
|
-
* validateCurrencyCode('XYZ')
|
|
52
|
-
* // { valid: false, error: 'Unsupported currency code: XYZ' }
|
|
53
|
-
*/
|
|
54
13
|
declare function validateCurrencyCode(input: string): ValidationResult<CurrencyCode>;
|
|
55
|
-
/**
|
|
56
|
-
* Formats a number as a locale-aware currency string.
|
|
57
|
-
* Uses the built-in Intl.NumberFormat API — zero dependencies.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* formatCurrency(1000.5, 'GBP') // '£1,000.50'
|
|
61
|
-
* formatCurrency(1000.5, 'EUR', 'de-DE') // '1.000,50 €'
|
|
62
|
-
* formatCurrency(1000.5, 'USD', 'en-US') // '$1,000.50'
|
|
63
|
-
* formatCurrency(1000, 'JPY') // '¥1,000'
|
|
64
|
-
*/
|
|
65
14
|
declare function formatCurrency(amount: number, currency: SupportedCurrency, locale?: string): string;
|
|
66
|
-
/**
|
|
67
|
-
* Parses a formatted currency string back into a structured money object.
|
|
68
|
-
* Detects the currency from the symbol prefix.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* parseMoney('£1,000.50')
|
|
72
|
-
* // { valid: true, amount: 1000.5, currency: 'GBP', formatted: '£1,000.50' }
|
|
73
|
-
*
|
|
74
|
-
* parseMoney('not money')
|
|
75
|
-
* // { valid: false, error: 'Could not detect currency from input' }
|
|
76
|
-
*/
|
|
77
15
|
declare function parseMoney(input: string): MoneyResult;
|
|
78
16
|
|
|
79
|
-
/**
|
|
80
|
-
* Validates a BIC (Bank Identifier Code) / SWIFT code.
|
|
81
|
-
* Accepts both 8-character and 11-character BIC codes.
|
|
82
|
-
*
|
|
83
|
-
* Format: AAAABBCCXXX
|
|
84
|
-
* - AAAA = Bank code (4 letters)
|
|
85
|
-
* - BB = Country code (2 letters, ISO 3166-1)
|
|
86
|
-
* - CC = Location code (2 alphanumeric)
|
|
87
|
-
* - XXX = Branch code (3 alphanumeric, optional — 'XXX' means head office)
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* validateBIC('NWBKGB2L')
|
|
91
|
-
* // { valid: true, value: 'NWBKGB2L', formatted: 'NWBKGB2L' }
|
|
92
|
-
*
|
|
93
|
-
* validateBIC('DEUTDEDB')
|
|
94
|
-
* // { valid: true, value: 'DEUTDEDB', formatted: 'DEUTDEDB' }
|
|
95
|
-
*/
|
|
96
17
|
declare function validateBIC(input: string): ValidationResult<BIC>;
|
|
97
18
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
19
|
+
declare function validateEUVAT(input: string): VATValidationResult;
|
|
20
|
+
|
|
21
|
+
declare function validateUSRoutingNumber(input: string): ValidationResult<RoutingNumber>;
|
|
22
|
+
|
|
23
|
+
type LoanScheduleEntry = {
|
|
24
|
+
month: number;
|
|
25
|
+
payment: number;
|
|
26
|
+
principal: number;
|
|
27
|
+
interest: number;
|
|
28
|
+
balance: number;
|
|
108
29
|
};
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
* Accepts digits with or without spaces and hyphens.
|
|
112
|
-
*
|
|
113
|
-
* The Luhn algorithm:
|
|
114
|
-
* 1. Double every second digit from the right
|
|
115
|
-
* 2. If doubling produces a number > 9, subtract 9
|
|
116
|
-
* 3. Sum all digits — result must be divisible by 10
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* validateCardNumber('4532015112830366')
|
|
120
|
-
* // { valid: true, value: '...', formatted: '4532 0151 1283 0366', network: 'Visa', last4: '0366' }
|
|
121
|
-
*
|
|
122
|
-
* validateCardNumber('1234567890123456')
|
|
123
|
-
* // { valid: false, error: 'Card number failed Luhn check' }
|
|
124
|
-
*/
|
|
125
|
-
declare function validateCardNumber(input: string): CardValidationResult;
|
|
30
|
+
declare function calculateEMI(principal: number, annualRatePercent: number, months: number): number;
|
|
31
|
+
declare function getLoanSchedule(principal: number, annualRatePercent: number, months: number): LoanScheduleEntry[];
|
|
126
32
|
|
|
127
|
-
export { AccountNumber, BIC,
|
|
33
|
+
export { AccountNumber, BIC, CurrencyCode, IBANValidationResult, type LoanScheduleEntry, MoneyResult, RoutingNumber, SUPPORTED_CURRENCIES, SortCode, SupportedCurrency, VATValidationResult, ValidationResult, calculateEMI, formatCurrency, formatIBAN, formatSortCode, formatUKAccountNumber, getLoanSchedule, parseMoney, validateBIC, validateCurrencyCode, validateEUVAT, validateIBAN, validateUKAccountNumber, validateUKSortCode, validateUSRoutingNumber };
|