finprim 0.1.1 → 0.1.3
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/README.md +164 -76
- package/dist/{card-D3WC2rzV.d.mts → card-D2-7wbam.d.mts} +8 -1
- package/dist/{card-D3WC2rzV.d.ts → card-D2-7wbam.d.ts} +8 -1
- package/dist/index.d.mts +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +207 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +200 -30
- 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 +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +36 -20
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +36 -20
- package/dist/react/index.mjs.map +1 -1
- package/dist/zod/index.d.mts +3 -1
- package/dist/zod/index.d.ts +3 -1
- package/dist/zod/index.js +124 -25
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +123 -26
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +30 -4
package/README.md
CHANGED
|
@@ -1,50 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<h1 align="center">finprim</h1>
|
|
3
|
+
<p align="center">Financial primitives for modern TypeScript applications.</p>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/finprim"><img src="https://img.shields.io/npm/v/finprim.svg" alt="npm version"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/finprim"><img src="https://img.shields.io/npm/dm/finprim.svg" alt="npm downloads"></a>
|
|
9
|
+
<a href="https://github.com/tintolee/finprim/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/finprim.svg" alt="license"></a>
|
|
10
|
+
<a href="https://github.com/tintolee/finprim"><img src="https://img.shields.io/github/stars/tintolee/finprim?style=social" alt="GitHub stars"></a>
|
|
11
|
+
<img src="https://img.shields.io/badge/dependencies-0-brightgreen" alt="zero dependencies">
|
|
12
|
+
<img src="https://img.shields.io/badge/TypeScript-strict-blue" alt="TypeScript strict">
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<b>IBAN · BIC/SWIFT · Card · Sort Code · VAT · Routing Number · Loan/EMI · Currency</b><br/>
|
|
17
|
+
One library. Zero dependencies. Fully typed.
|
|
18
|
+
</p>
|
|
2
19
|
|
|
3
|
-
|
|
20
|
+
---
|
|
4
21
|
|
|
5
|
-
|
|
22
|
+
> 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. **finprim is the open source version of what your team has already written three times.**
|
|
6
23
|
|
|
7
24
|
---
|
|
8
25
|
|
|
9
|
-
##
|
|
26
|
+
## Quick Start
|
|
10
27
|
|
|
11
|
-
|
|
28
|
+
```bash
|
|
29
|
+
npm install finprim
|
|
30
|
+
```
|
|
12
31
|
|
|
13
|
-
|
|
32
|
+
```ts
|
|
33
|
+
import { validateIBAN, validateCardNumber, formatCurrency } from 'finprim'
|
|
34
|
+
|
|
35
|
+
const iban = validateIBAN('GB29NWBK60161331926819')
|
|
36
|
+
// { valid: true, value: 'GB29NWBK60161331926819', formatted: 'GB29 NWBK 6016 1331 9268 19', countryCode: 'GB' }
|
|
37
|
+
|
|
38
|
+
const card = validateCardNumber('4532015112830366')
|
|
39
|
+
// { valid: true, formatted: '4532 0151 1283 0366', network: 'Visa', last4: '0366' }
|
|
40
|
+
|
|
41
|
+
formatCurrency(1000.5, 'GBP', 'en-GB')
|
|
42
|
+
// '£1,000.50'
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
**That's it.** No config. No setup. Just import and use.
|
|
14
46
|
|
|
15
47
|
---
|
|
16
48
|
|
|
17
|
-
##
|
|
49
|
+
## Why finprim?
|
|
18
50
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- ✅ Optional React hooks for form inputs
|
|
27
|
-
- ✅ Zero dependencies at the core
|
|
28
|
-
- ✅ Tree-shakeable ESM and CJS builds
|
|
29
|
-
- ✅ Fully typed
|
|
51
|
+
| Problem | finprim |
|
|
52
|
+
|---|---|
|
|
53
|
+
| 5 different npm packages for financial validation | **One unified library** |
|
|
54
|
+
| Custom glue code between validators | **Consistent API across all validators** |
|
|
55
|
+
| Runtime type confusion | **Branded TypeScript types** for compile-time safety |
|
|
56
|
+
| No framework integration | **Built-in Zod schemas, React hooks, NestJS pipes** |
|
|
57
|
+
| Heavy dependency trees | **Zero runtime dependencies** |
|
|
30
58
|
|
|
31
59
|
---
|
|
32
60
|
|
|
33
|
-
##
|
|
61
|
+
## Features
|
|
34
62
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
- **Validators** - IBAN (80+ countries), BIC/SWIFT, UK sort code & account number, card number (Luhn + network detection), EU VAT, US ABA routing number
|
|
64
|
+
- **Loan math** - EMI calculation and full amortization schedules
|
|
65
|
+
- **Formatting** - Display-ready IBAN, sort code, account number, and multi-locale currency formatting
|
|
66
|
+
- **Branded types** - Compile-time correctness that prevents invalid data from flowing through your system
|
|
67
|
+
- **Framework integrations** - Zod schemas, React hooks, NestJS pipes (all optional)
|
|
68
|
+
- **Production-ready** - Input length guards, type checking, no sensitive data logging
|
|
69
|
+
- **Lightweight** - Zero dependencies, tree-shakeable ESM + CJS
|
|
38
70
|
|
|
39
|
-
|
|
71
|
+
---
|
|
40
72
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
## Integrations
|
|
74
|
+
|
|
75
|
+
finprim works standalone or plugs into your existing stack:
|
|
76
|
+
|
|
77
|
+
| Import path | What it contains | Extra dependency |
|
|
78
|
+
|---|---|---|
|
|
79
|
+
| `finprim` | Core validators, formatters, loan math | none |
|
|
80
|
+
| `finprim/zod` | Zod schemas for validation pipelines | `zod` |
|
|
81
|
+
| `finprim/react` | React hooks for form inputs | `react` |
|
|
82
|
+
| `finprim/nest` | NestJS validation pipes | `@nestjs/common` |
|
|
44
83
|
|
|
45
84
|
---
|
|
46
85
|
|
|
47
|
-
## Usage
|
|
86
|
+
## Usage Examples
|
|
48
87
|
|
|
49
88
|
### Validation
|
|
50
89
|
|
|
@@ -56,51 +95,76 @@ import {
|
|
|
56
95
|
validateBIC,
|
|
57
96
|
validateCardNumber,
|
|
58
97
|
validateCurrencyCode,
|
|
98
|
+
validateEUVAT,
|
|
99
|
+
validateUSRoutingNumber,
|
|
59
100
|
} from 'finprim'
|
|
60
101
|
|
|
61
|
-
|
|
102
|
+
validateIBAN('GB29NWBK60161331926819')
|
|
62
103
|
// { valid: true, value: 'GB29NWBK60161331926819', formatted: 'GB29 NWBK 6016 1331 9268 19', countryCode: 'GB' }
|
|
63
104
|
|
|
64
|
-
|
|
105
|
+
validateUKSortCode('60-16-13')
|
|
65
106
|
// { valid: true, value: '601613', formatted: '60-16-13' }
|
|
66
107
|
|
|
67
|
-
|
|
108
|
+
validateUKAccountNumber('31926819')
|
|
68
109
|
// { valid: true, value: '31926819', formatted: '3192 6819' }
|
|
69
110
|
|
|
70
|
-
|
|
71
|
-
// { valid: true,
|
|
111
|
+
validateCardNumber('4532015112830366')
|
|
112
|
+
// { valid: true, formatted: '4532 0151 1283 0366', network: 'Visa', last4: '0366' }
|
|
113
|
+
|
|
114
|
+
validateEUVAT('DE123456789')
|
|
115
|
+
// { valid: true, value: 'DE123456789', formatted: 'DE 123456789', countryCode: 'DE' }
|
|
116
|
+
|
|
117
|
+
validateUSRoutingNumber('021000021')
|
|
118
|
+
// { valid: true, value: '021000021', formatted: '021000021' }
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Formatting & Display
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { formatIBAN, formatSortCode, formatUKAccountNumber, formatCurrency, parseMoney } from 'finprim'
|
|
125
|
+
|
|
126
|
+
formatIBAN('GB29NWBK60161331926819') // 'GB29 NWBK 6016 1331 9268 19'
|
|
127
|
+
formatSortCode('601613') // '60-16-13'
|
|
128
|
+
formatUKAccountNumber('31926819') // '3192 6819'
|
|
129
|
+
|
|
130
|
+
formatCurrency(1000.5, 'GBP', 'en-GB') // '£1,000.50'
|
|
131
|
+
formatCurrency(1000.5, 'EUR', 'de-DE') // '1.000,50 €'
|
|
132
|
+
formatCurrency(1000.5, 'USD', 'en-US') // '$1,000.50'
|
|
133
|
+
|
|
134
|
+
parseMoney('£1,000.50')
|
|
135
|
+
// { valid: true, amount: 1000.50, currency: 'GBP', formatted: '£1,000.50' }
|
|
72
136
|
```
|
|
73
137
|
|
|
74
|
-
###
|
|
138
|
+
### Loan / EMI Calculation
|
|
75
139
|
|
|
76
140
|
```ts
|
|
77
|
-
import {
|
|
141
|
+
import { calculateEMI, getLoanSchedule } from 'finprim'
|
|
78
142
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
formatCurrency(1000.5, 'USD', 'en-US') // '$1,000.50'
|
|
143
|
+
calculateEMI(100_000, 10, 12)
|
|
144
|
+
// Monthly payment amount
|
|
82
145
|
|
|
83
|
-
|
|
146
|
+
getLoanSchedule(100_000, 10, 12)
|
|
147
|
+
// [{ month, payment, principal, interest, balance }, ...]
|
|
84
148
|
```
|
|
85
149
|
|
|
86
150
|
### Branded Types
|
|
87
151
|
|
|
88
152
|
```ts
|
|
89
|
-
import type { IBAN, SortCode, AccountNumber
|
|
153
|
+
import type { IBAN, SortCode, AccountNumber } from 'finprim'
|
|
90
154
|
|
|
91
155
|
// Invalid data cannot be passed where valid data is expected
|
|
92
|
-
function processPayment(iban: IBAN, amount: number) { ... }
|
|
156
|
+
function processPayment(iban: IBAN, amount: number) { /* ... */ }
|
|
93
157
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
processPayment(iban.value, 100) // iban.value is typed as IBAN
|
|
158
|
+
const result = validateIBAN(input)
|
|
159
|
+
if (result.valid) {
|
|
160
|
+
processPayment(result.value, 100) // result.value is typed as IBAN
|
|
98
161
|
}
|
|
99
162
|
```
|
|
100
163
|
|
|
101
164
|
### Zod Schemas
|
|
102
165
|
|
|
103
166
|
```ts
|
|
167
|
+
import { z } from 'zod'
|
|
104
168
|
import { ibanSchema, sortCodeSchema, accountNumberSchema, currencySchema } from 'finprim/zod'
|
|
105
169
|
|
|
106
170
|
const PaymentSchema = z.object({
|
|
@@ -114,24 +178,39 @@ const PaymentSchema = z.object({
|
|
|
114
178
|
|
|
115
179
|
### React Hooks
|
|
116
180
|
|
|
117
|
-
```
|
|
181
|
+
```tsx
|
|
118
182
|
import { useIBANInput, useCardNumberInput, useCurrencyInput } from 'finprim/react'
|
|
119
183
|
|
|
120
184
|
function PaymentForm() {
|
|
121
185
|
const iban = useIBANInput()
|
|
122
186
|
const card = useCardNumberInput()
|
|
123
|
-
const
|
|
187
|
+
const currency = useCurrencyInput('GBP', 'en-GB')
|
|
124
188
|
|
|
125
189
|
return (
|
|
126
|
-
|
|
190
|
+
<form>
|
|
127
191
|
<input value={iban.value} onChange={iban.onChange} aria-invalid={iban.valid === false} />
|
|
128
192
|
<input value={card.formatted} onChange={card.onChange} aria-invalid={card.valid === false} />
|
|
129
|
-
<input value={formatted} onChange={onChange} />
|
|
130
|
-
|
|
193
|
+
<input value={currency.formatted} onChange={currency.onChange} />
|
|
194
|
+
</form>
|
|
131
195
|
)
|
|
132
196
|
}
|
|
133
197
|
```
|
|
134
198
|
|
|
199
|
+
### NestJS Pipes
|
|
200
|
+
|
|
201
|
+
```ts
|
|
202
|
+
import { IbanValidationPipe, SortCodeValidationPipe, createValidationPipe } from 'finprim/nest'
|
|
203
|
+
import { validateIBAN } from 'finprim'
|
|
204
|
+
|
|
205
|
+
@Get('iban/:iban')
|
|
206
|
+
findByIban(@Param('iban', IbanValidationPipe) iban: string) {
|
|
207
|
+
return this.service.findByIban(iban)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Create a custom pipe from any validator
|
|
211
|
+
const MyPipe = createValidationPipe(validateIBAN)
|
|
212
|
+
```
|
|
213
|
+
|
|
135
214
|
---
|
|
136
215
|
|
|
137
216
|
## API Reference
|
|
@@ -140,64 +219,73 @@ function PaymentForm() {
|
|
|
140
219
|
|
|
141
220
|
| Function | Input | Returns |
|
|
142
221
|
|----------|-------|---------|
|
|
143
|
-
| `validateIBAN(input)` | `string` | `IBANValidationResult` (includes `countryCode`
|
|
222
|
+
| `validateIBAN(input)` | `string` | `IBANValidationResult` (includes `countryCode`) |
|
|
144
223
|
| `validateUKSortCode(input)` | `string` | `ValidationResult<SortCode>` |
|
|
145
224
|
| `validateUKAccountNumber(input)` | `string` | `ValidationResult<AccountNumber>` |
|
|
146
225
|
| `validateCurrencyCode(input)` | `string` | `ValidationResult<CurrencyCode>` |
|
|
147
226
|
| `validateBIC(input)` | `string` | `ValidationResult<BIC>` |
|
|
148
|
-
| `validateCardNumber(input)` | `string` | `CardValidationResult` (includes `network`, `last4`
|
|
227
|
+
| `validateCardNumber(input)` | `string` | `CardValidationResult` (includes `network`, `last4`) |
|
|
228
|
+
| `validateEUVAT(input)` | `string` | `VATValidationResult` (includes `countryCode`) |
|
|
229
|
+
| `validateUSRoutingNumber(input)` | `string` | `ValidationResult<RoutingNumber>` |
|
|
149
230
|
|
|
150
231
|
### Formatting
|
|
151
232
|
|
|
152
233
|
| Function | Input | Returns |
|
|
153
234
|
|----------|-------|---------|
|
|
235
|
+
| `formatIBAN(input)` | `string` | `string` (space-separated) |
|
|
236
|
+
| `formatSortCode(input)` | `string` | `string` (XX-XX-XX) |
|
|
237
|
+
| `formatUKAccountNumber(input)` | `string` | `string` (XXXX XXXX) |
|
|
154
238
|
| `formatCurrency(amount, currency, locale?)` | `number`, `SupportedCurrency`, `string?` | `string` |
|
|
155
239
|
| `parseMoney(input)` | `string` | `MoneyResult` |
|
|
156
240
|
|
|
157
|
-
|
|
241
|
+
### Loan
|
|
158
242
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
| Import path | What it contains | Extra dependency |
|
|
164
|
-
|---|---|---|
|
|
165
|
-
| `finprim` | Core validators and formatters | none |
|
|
166
|
-
| `finprim/zod` | Zod schemas | `zod` |
|
|
167
|
-
| `finprim/react` | React hooks | `react` |
|
|
243
|
+
| Function | Input | Returns |
|
|
244
|
+
|----------|-------|---------|
|
|
245
|
+
| `calculateEMI(principal, rate, months)` | `number`, `number`, `number` | `number` |
|
|
246
|
+
| `getLoanSchedule(principal, rate, months)` | `number`, `number`, `number` | `LoanScheduleEntry[]` |
|
|
168
247
|
|
|
169
248
|
---
|
|
170
249
|
|
|
171
|
-
##
|
|
250
|
+
## Roadmap
|
|
172
251
|
|
|
173
|
-
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
177
|
-
-
|
|
252
|
+
- [x] IBAN validation (80+ countries)
|
|
253
|
+
- [x] BIC/SWIFT validation
|
|
254
|
+
- [x] Card number validation (Luhn + network detection)
|
|
255
|
+
- [x] EU VAT number validation
|
|
256
|
+
- [x] US routing number validation
|
|
257
|
+
- [x] UK sort code and account number validation
|
|
258
|
+
- [x] Loan/EMI calculation
|
|
259
|
+
- [x] Format-only helpers
|
|
260
|
+
- [x] Currency formatting with locale support
|
|
261
|
+
- [x] Branded TypeScript types
|
|
262
|
+
- [x] Zod schema integration
|
|
263
|
+
- [x] React hooks
|
|
264
|
+
- [x] NestJS pipes
|
|
265
|
+
- [ ] More locale coverage
|
|
266
|
+
- [ ] SEPA credit transfer XML generation
|
|
267
|
+
- [ ] ACH file format support
|
|
178
268
|
|
|
179
269
|
---
|
|
180
270
|
|
|
181
|
-
##
|
|
271
|
+
## Security
|
|
182
272
|
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
-
|
|
186
|
-
-
|
|
187
|
-
- [ ] More locale coverage
|
|
273
|
+
- **Input length** - All string validators reject input longer than 256 characters
|
|
274
|
+
- **Type checking** - Validators require non-empty strings; numeric helpers require finite numbers and sane bounds
|
|
275
|
+
- **No sensitive logging** - The library does not log or persist input
|
|
276
|
+
- **Format helpers** - Cap input length and accept only strings
|
|
188
277
|
|
|
189
278
|
---
|
|
190
279
|
|
|
191
280
|
## Contributing
|
|
192
281
|
|
|
193
|
-
Contributions are welcome
|
|
282
|
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
194
283
|
|
|
195
284
|
```bash
|
|
196
|
-
git clone https://github.com/
|
|
285
|
+
git clone https://github.com/tintolee/finprim.git
|
|
197
286
|
cd finprim
|
|
198
287
|
npm install
|
|
199
288
|
npm test
|
|
200
|
-
npm run dev
|
|
201
289
|
```
|
|
202
290
|
|
|
203
291
|
---
|
|
@@ -8,6 +8,8 @@ type AccountNumber = Brand<string, 'AccountNumber'>;
|
|
|
8
8
|
type CurrencyCode = Brand<string, 'CurrencyCode'>;
|
|
9
9
|
type BIC = Brand<string, 'BIC'>;
|
|
10
10
|
type CardNumber = Brand<string, 'CardNumber'>;
|
|
11
|
+
type VATNumber = Brand<string, 'VATNumber'>;
|
|
12
|
+
type RoutingNumber = Brand<string, 'RoutingNumber'>;
|
|
11
13
|
type SupportedCurrency = 'GBP' | 'EUR' | 'USD' | 'JPY' | 'CHF' | 'CAD' | 'AUD' | 'NZD';
|
|
12
14
|
type ValidationSuccess<T> = {
|
|
13
15
|
valid: true;
|
|
@@ -20,6 +22,7 @@ type ValidationFailure = {
|
|
|
20
22
|
};
|
|
21
23
|
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
22
24
|
declare function isValidationSuccess<T>(result: ValidationResult<T>): result is ValidationSuccess<T>;
|
|
25
|
+
declare function isValidationFailure<T>(result: ValidationResult<T>): result is ValidationFailure;
|
|
23
26
|
type IBANValidationSuccess = ValidationSuccess<IBAN> & {
|
|
24
27
|
countryCode: string;
|
|
25
28
|
};
|
|
@@ -33,6 +36,10 @@ type MoneyResult = {
|
|
|
33
36
|
valid: false;
|
|
34
37
|
error: string;
|
|
35
38
|
};
|
|
39
|
+
type VATValidationSuccess = ValidationSuccess<VATNumber> & {
|
|
40
|
+
countryCode: string;
|
|
41
|
+
};
|
|
42
|
+
type VATValidationResult = VATValidationSuccess | ValidationFailure;
|
|
36
43
|
|
|
37
44
|
type CardNetwork = 'Visa' | 'Mastercard' | 'Amex' | 'Discover' | 'Unknown';
|
|
38
45
|
type CardValidationResult = {
|
|
@@ -47,4 +54,4 @@ type CardValidationResult = {
|
|
|
47
54
|
};
|
|
48
55
|
declare function validateCardNumber(input: string): CardValidationResult;
|
|
49
56
|
|
|
50
|
-
export { type AccountNumber as A, type BIC as B, type CurrencyCode as C, type IBANValidationResult as I, type MoneyResult as M, type SortCode as S, type ValidationResult as V, type SupportedCurrency as a, type
|
|
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 };
|
|
@@ -8,6 +8,8 @@ type AccountNumber = Brand<string, 'AccountNumber'>;
|
|
|
8
8
|
type CurrencyCode = Brand<string, 'CurrencyCode'>;
|
|
9
9
|
type BIC = Brand<string, 'BIC'>;
|
|
10
10
|
type CardNumber = Brand<string, 'CardNumber'>;
|
|
11
|
+
type VATNumber = Brand<string, 'VATNumber'>;
|
|
12
|
+
type RoutingNumber = Brand<string, 'RoutingNumber'>;
|
|
11
13
|
type SupportedCurrency = 'GBP' | 'EUR' | 'USD' | 'JPY' | 'CHF' | 'CAD' | 'AUD' | 'NZD';
|
|
12
14
|
type ValidationSuccess<T> = {
|
|
13
15
|
valid: true;
|
|
@@ -20,6 +22,7 @@ type ValidationFailure = {
|
|
|
20
22
|
};
|
|
21
23
|
type ValidationResult<T> = ValidationSuccess<T> | ValidationFailure;
|
|
22
24
|
declare function isValidationSuccess<T>(result: ValidationResult<T>): result is ValidationSuccess<T>;
|
|
25
|
+
declare function isValidationFailure<T>(result: ValidationResult<T>): result is ValidationFailure;
|
|
23
26
|
type IBANValidationSuccess = ValidationSuccess<IBAN> & {
|
|
24
27
|
countryCode: string;
|
|
25
28
|
};
|
|
@@ -33,6 +36,10 @@ type MoneyResult = {
|
|
|
33
36
|
valid: false;
|
|
34
37
|
error: string;
|
|
35
38
|
};
|
|
39
|
+
type VATValidationSuccess = ValidationSuccess<VATNumber> & {
|
|
40
|
+
countryCode: string;
|
|
41
|
+
};
|
|
42
|
+
type VATValidationResult = VATValidationSuccess | ValidationFailure;
|
|
36
43
|
|
|
37
44
|
type CardNetwork = 'Visa' | 'Mastercard' | 'Amex' | 'Discover' | 'Unknown';
|
|
38
45
|
type CardValidationResult = {
|
|
@@ -47,4 +54,4 @@ type CardValidationResult = {
|
|
|
47
54
|
};
|
|
48
55
|
declare function validateCardNumber(input: string): CardValidationResult;
|
|
49
56
|
|
|
50
|
-
export { type AccountNumber as A, type BIC as B, type CurrencyCode as C, type IBANValidationResult as I, type MoneyResult as M, type SortCode as S, type ValidationResult as V, type SupportedCurrency as a, type
|
|
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,8 +1,11 @@
|
|
|
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 } from './card-
|
|
2
|
-
export {
|
|
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
|
+
declare function formatIBAN(input: string): string;
|
|
4
5
|
declare function validateIBAN(input: string): IBANValidationResult;
|
|
5
6
|
|
|
7
|
+
declare function formatSortCode(input: string): string;
|
|
8
|
+
declare function formatUKAccountNumber(input: string): string;
|
|
6
9
|
declare function validateUKSortCode(input: string): ValidationResult<SortCode>;
|
|
7
10
|
declare function validateUKAccountNumber(input: string): ValidationResult<AccountNumber>;
|
|
8
11
|
|
|
@@ -13,4 +16,18 @@ declare function parseMoney(input: string): MoneyResult;
|
|
|
13
16
|
|
|
14
17
|
declare function validateBIC(input: string): ValidationResult<BIC>;
|
|
15
18
|
|
|
16
|
-
|
|
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;
|
|
29
|
+
};
|
|
30
|
+
declare function calculateEMI(principal: number, annualRatePercent: number, months: number): number;
|
|
31
|
+
declare function getLoanSchedule(principal: number, annualRatePercent: number, months: number): LoanScheduleEntry[];
|
|
32
|
+
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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 } from './card-
|
|
2
|
-
export {
|
|
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.js';
|
|
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.js';
|
|
3
3
|
|
|
4
|
+
declare function formatIBAN(input: string): string;
|
|
4
5
|
declare function validateIBAN(input: string): IBANValidationResult;
|
|
5
6
|
|
|
7
|
+
declare function formatSortCode(input: string): string;
|
|
8
|
+
declare function formatUKAccountNumber(input: string): string;
|
|
6
9
|
declare function validateUKSortCode(input: string): ValidationResult<SortCode>;
|
|
7
10
|
declare function validateUKAccountNumber(input: string): ValidationResult<AccountNumber>;
|
|
8
11
|
|
|
@@ -13,4 +16,18 @@ declare function parseMoney(input: string): MoneyResult;
|
|
|
13
16
|
|
|
14
17
|
declare function validateBIC(input: string): ValidationResult<BIC>;
|
|
15
18
|
|
|
16
|
-
|
|
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;
|
|
29
|
+
};
|
|
30
|
+
declare function calculateEMI(principal: number, annualRatePercent: number, months: number): number;
|
|
31
|
+
declare function getLoanSchedule(principal: number, annualRatePercent: number, months: number): LoanScheduleEntry[];
|
|
32
|
+
|
|
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 };
|