Skip to content

Commit 17a1f04

Browse files
Merge pull request #12 from bchainhub/update/functions-06
Update/functions 06
2 parents a90651f + 0ed10fc commit 17a1f04

File tree

6 files changed

+716
-123
lines changed

6 files changed

+716
-123
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package-lock.json
1010

1111
/dist-test/
1212
/dist/
13+
/coverage/
1314

1415
.DS_Store
1516
.AppleDouble

README.md

+65-23
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,33 @@
22

33
`payto-rl` is a TypeScript library for handling Payto Resource Locators (PRLs). This library is based on the [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) API and provides additional functionality for managing PRLs.
44

5+
[![npm](https://img.shields.io/npm/v/payto-rl?label=npm&color=cb3837&logo=npm)](https://www.npmjs.com/package/payto-rl)
6+
[![License: CORE](https://img.shields.io/badge/License-CORE-yellow?logo=googledocs)](LICENSE)
7+
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/payto-rl?label=Size&logo=tsnode)](https://bundlephobia.com/package/payto-rl@latest)
8+
[![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue?logo=typescript)](https://www.typescriptlang.org/)
9+
[![GitHub Sponsors](https://img.shields.io/github/sponsors/bchainhub?label=Sponsors&logo=githubsponsors&color=EA4AAA)](https://github.com/sponsors/bchainhub)
10+
11+
## Features
12+
13+
- 🐥 **Small**: **[![Bundle Size](https://img.shields.io/bundlephobia/minzip/payto-rl?label=&color=6ead0a)](https://bundlephobia.com/package/payto-rl@latest)** gzipped, distributed as minified ES modules.
14+
- 📜 **Standardized**: Based on the [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) Web API.
15+
- 🏗️ **Simple**: Easy to implement.
16+
- 🗂 **Typed**: Ships with types included.
17+
- 🧪 **Tested**: Robust test coverage.
18+
- 🌲 **Tree Shaking**: Zero dependencies, no side effects.
19+
520
## Installation
621

7-
Install the `payto-rl` package using npm or yarn:
22+
Install the `payto-rl` package using your package manager:
823

924
```sh
1025
npm i payto-rl
1126
```
1227

28+
```sh
29+
pnpm add payto-rl
30+
```
31+
1332
```sh
1433
yarn add payto-rl
1534
```
@@ -37,6 +56,11 @@ payto.value = 20.02;
3756
console.log(payto.amount); // 'ctn:20.02'
3857
console.log(payto.fiat); // 'eur'
3958

59+
// Color customization
60+
payto.colorBackground = 'ff0000'; // Red background (6-character hex)
61+
payto.colorForeground = '000000'; // Black foreground
62+
console.log(payto.colorBackground); // 'ff0000'
63+
4064
// ACH payment examples
4165
const achPayto1 = new Payto('payto://ach/123456789/1234567'); // With routing number
4266
console.log(achPayto1.routingNumber); // 123456789
@@ -45,11 +69,11 @@ console.log(achPayto1.accountNumber); // 1234567
4569
const achPayto2 = new Payto('payto://ach/1234567'); // Account number only
4670
console.log(achPayto2.accountNumber); // 1234567
4771

48-
// UPI/PIX payment examples
49-
const upiPayto = new Payto('payto://upi/user@example.com');
72+
// UPI/PIX payment examples (case-insensitive email)
73+
const upiPayto = new Payto('payto://upi/USER@example.com');
5074
console.log(upiPayto.accountAlias); // 'user@example.com'
5175

52-
const pixPayto = new Payto('payto://pix/user@example.com');
76+
const pixPayto = new Payto('payto://pix/user@EXAMPLE.com');
5377
console.log(pixPayto.accountAlias); // 'user@example.com'
5478

5579
// Geo location example
@@ -64,12 +88,22 @@ plusPayto.location = '8FVC9G8V+R9'; // Valid plus code
6488
console.log(plusPayto.void); // 'plus'
6589
console.log(plusPayto.location); // '8FVC9G8V+R9'
6690

67-
// Bank details example
68-
const bankPayto = new Payto('payto://bic/DEUTDEFF500');
91+
// Bank details example (case-insensitive BIC)
92+
const bankPayto = new Payto('payto://bic/deutdeff500');
6993
console.log(bankPayto.bic); // 'DEUTDEFF500'
7094
bankPayto.routingNumber = 123456789; // Valid 9-digit routing number
7195
console.log(bankPayto.routingNumber); // 123456789
7296

97+
// Value handling examples
98+
const numericPayto = new Payto('payto://example/address?amount=10.5');
99+
console.log(numericPayto.value); // 10.5
100+
console.log(numericPayto.amount); // '10.5'
101+
102+
const tokenPayto = new Payto('payto://example/address?amount=token:10.5');
103+
console.log(tokenPayto.value); // 10.5
104+
console.log(tokenPayto.amount); // 'token:10.5'
105+
console.log(tokenPayto.asset); // 'token'
106+
73107
// Convert to JSON object
74108
const jsonObj = payto.toJSONObject();
75109
console.log(jsonObj.colorForeground); // Access typed properties
@@ -90,28 +124,28 @@ Creates a new Payto instance from a payto URL string.
90124

91125
| Property | Type | Description |
92126
|----------|------|-------------|
93-
| `accountAlias` | `string \| null` | Email address for UPI/PIX payments |
127+
| `accountAlias` | `string \| null` | Email address for UPI/PIX payments (case-insensitive) |
94128
| `accountNumber` | `number \| null` | Account number (7-14 digits) for ACH payments |
95129
| `address` | `string \| null` | Payment address |
96-
| `amount` | `string \| null` | Payment amount with currency |
130+
| `amount` | `string \| null` | Payment amount with optional currency prefix |
97131
| `asset` | `string \| null` | Asset type or contract address |
98132
| `barcode` | `'qr' \| 'pdf417' \| 'aztec' \| 'code128' \| null` | Barcode format |
99-
| `bic` | `string \| null` | Bank Identifier Code (8 or 11 characters) |
100-
| `colorBackground` | `string \| null` | Background color in hex format |
101-
| `colorForeground` | `string \| null` | Foreground color in hex format |
102-
| `currency` | `[string \| null, string \| null]` | Currency codes array |
133+
| `bic` | `string \| null` | Bank Identifier Code (8 or 11 characters, case-insensitive) |
134+
| `colorBackground` | `string \| null` | Background color in 6-character hex format |
135+
| `colorForeground` | `string \| null` | Foreground color in 6-character hex format |
136+
| `currency` | `[string \| null, string \| null]` | Currency codes array [asset, fiat] |
103137
| `deadline` | `number \| null` | Payment deadline (Unix timestamp) |
104138
| `donate` | `boolean \| null` | Donation flag |
105-
| `fiat` | `string \| null` | Fiat currency code |
139+
| `fiat` | `string \| null` | Fiat currency code (case-insensitive) |
106140
| `hash` | `string` | URL hash component |
107141
| `host` | `string` | Complete host (hostname:port) |
108-
| `hostname` | `string` | Host without port |
142+
| `hostname` | `string` | Host without port (case-insensitive) |
109143
| `href` | `string` | Complete URL string |
110-
| `iban` | `string \| null` | International Bank Account Number |
144+
| `iban` | `string \| null` | International Bank Account Number (case-insensitive) |
111145
| `item` | `string \| null` | Item description (max 40 chars) |
112146
| `location` | `string \| null` | Location data (format depends on void type) |
113147
| `message` | `string \| null` | Payment message |
114-
| `network` | `string` | Network identifier |
148+
| `network` | `string` | Network identifier (case-insensitive) |
115149
| `organization` | `string \| null` | Organization name (max 25 chars) |
116150
| `origin` | `string \| null` | URL origin |
117151
| `password` | `string` | URL password component |
@@ -120,14 +154,14 @@ Creates a new Payto instance from a payto URL string.
120154
| `protocol` | `string` | URL protocol (always 'payto:') |
121155
| `receiverName` | `string \| null` | Receiver's name |
122156
| `recurring` | `string \| null` | Recurring payment details |
123-
| `route` | `string \| null` | Additional routing information |
124157
| `routingNumber` | `number \| null` | Bank routing number (9 digits) |
158+
| `rtl` | `boolean \| null` | right-to-left layout |
125159
| `search` | `string` | URL search component |
126160
| `searchParams` | `URLSearchParams` | URL search parameters |
127161
| `split` | `[string, string, boolean] \| null` | Payment split information |
128162
| `swap` | `string \| null` | Swap transaction details |
129163
| `username` | `string` | URL username component |
130-
| `value` | `number \| null` | Numeric amount value |
164+
| `value` | `number \| null` | Numeric amount value (extracted from both simple and token:amount formats) |
131165
| `void` | `string \| null` | Void path type (e.g., 'geo', 'plus') |
132166

133167
### Methods
@@ -142,18 +176,26 @@ Creates a new Payto instance from a payto URL string.
142176

143177
The library includes TypeScript type definitions and runtime validation for:
144178

145-
- Bank Identifier Codes (BIC)
179+
- Bank Identifier Codes (BIC) - 8 or 11 characters, case-insensitive
146180
- Routing numbers (9 digits)
147181
- Account numbers (7-14 digits)
148-
- Email addresses (for UPI/PIX)
182+
- Email addresses (for UPI/PIX, case-insensitive)
149183
- Geographic coordinates
150184
- Plus codes
151185
- Unix timestamps
152186
- Barcode formats
153-
- IBAN format
187+
- IBAN format (case-insensitive)
188+
- Color formats (6-character hex)
154189

155190
## Payment System Support
156191

192+
### IBAN
193+
194+
Supports two formats (case-insensitive):
195+
196+
- `payto://iban/iban` (without BIC)
197+
- `payto://iban/bic/iban` (with BIC)
198+
157199
### ACH Payments
158200

159201
Supports two formats:
@@ -163,7 +205,7 @@ Supports two formats:
163205

164206
### UPI/PIX Payments
165207

166-
Email-based payment identifiers:
208+
Email-based payment identifiers (case-insensitive):
167209

168210
- `payto://upi/email@example.com`
169211
- `payto://pix/email@example.com`
@@ -190,4 +232,4 @@ If you find this project useful, please consider supporting it:
190232
- [Bitcoin](https://www.blockchain.com/explorer/addresses/btc/bc1pd8guxjkr2p6n2kl388fdj2trete9w2fr89xlktdezmcctxvtzm8qsymg0d)
191233
- [Litecoin](https://www.blockchain.com/explorer/addresses/ltc/ltc1ql8dvx0wv0nh2vncpt9j3zqefaehsd25cwp7pfx)
192234

193-
List of sponsors: [![GitHub Sponsors](https://img.shields.io/github/sponsors/bchainhub)](https://github.com/sponsors/bchainhub)
235+
List of sponsors: [![GitHub Sponsors](https://img.shields.io/github/sponsors/bchainhub?label=Sponsors&logo=githubsponsors&color=EA4AAA)](https://github.com/sponsors/bchainhub)

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "payto-rl",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "PayTo Resource Locator",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -9,6 +9,7 @@
99
"sideEffects": false,
1010
"scripts": {
1111
"test": "npm run build && node --no-deprecation --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ./node_modules/uvu/bin.js test",
12+
"test:coverage": "c8 npm test",
1213
"build": "tsc --declaration --declarationDir ./dist",
1314
"dev": "node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' --inspect src/index.ts"
1415
},
@@ -47,7 +48,8 @@
4748
".": "./dist/index.js"
4849
},
4950
"devDependencies": {
50-
"@types/node": "^22.10.7",
51+
"@types/node": "^22.10.9",
52+
"c8": "^9.1.0",
5153
"esm": "^3.2.25",
5254
"ts-node": "^10.9.2",
5355
"typescript": "^5.7.3",

0 commit comments

Comments
 (0)