payto-rl
is a TypeScript library for handling Payto resource locators (PRLs). This library is based on the URL API and provides additional functionality for managing PRLs.
You can install the payto-rl
package using npm or yarn:
npm install payto-rl
yarn add payto-rl
Here is an example of how to use the Payto-RL
package:
import Payto from 'payto-rl';
const paytoString = 'payto://xcb/cb7147879011ea207df5b35a24ca6f0859dcfb145999?amount=ctn:10.01&fiat=eur';
const payto = new Payto(paytoString);
console.log(payto.address); // Outputs: cb7147879011ea207df5b35a24ca6f0859dcfb145999
console.log(payto.amount); // Outputs: ctn:10.01
console.log(payto.value); // Outputs: 10.01
console.log(payto.network); // Outputs: xcb
console.log(payto.currency); // Outputs: ['ctn', 'eur']
payto.value = 20.02;
console.log(payto.amount); // Outputs: ctn:20.02
console.log(payto.value); // Outputs: 20.02
console.log(payto.fiat); // Outputs: eur
// Then it should be payed 20.02 EUR in CTN to the address cb7147879011ea207df5b35a24ca6f0859dcfb145999 on the XCB network.
console.log(payto.toJSONObject());
/*
Outputs:
{
address: 'cb7147879011ea207df5b35a24ca6f0859dcfb145999',
amount: 'ctn:20.02',
asset: 'ctn',
fiat: 'eur',
host: 'xcb',
hostname: 'xcb',
href: 'payto://xcb/cb7147879011ea207df5b35a24ca6f0859dcfb145999?amount=ctn:10.01&fiat=eur',
network: 'xcb',
pathname: '/cb7147879011ea207df5b35a24ca6f0859dcfb145999',
protocol: 'payto:',
search: '?amount=ctn:10.01&fiat=eur',
value: 20.02
}
*/
payto.currency = ['btc', 'usd', 12];
console.log(payto.currency); // Outputs: ['btc', 'usd']
console.log(payto.value); // Outputs: 12
constructor(paytoString: string)
Creates a new Payto
instance.
Gets or sets the address component of the PRL.
Gets or sets the amount component of the PRL. Amount consists of the number of units and the currency delimited by :
.
Gets or sets the asset component of the PRL. Asset is the currency in the amount field. Can be ticker or smart contract address.
Gets or sets the barcode component of the PRL. Values pdf417
, aztec
and 0
are supported, where 0
is the boolean value (false) to hide the barcode.
Gets or sets the BIC component of the PRL.
Gets or sets the currency component of the PRL.
Gets or sets the background color 6-hexcode component of the PRL.
Gets or sets the foreground color 6-hexcode component of the PRL.
Gets or sets the deadline component in Unix timestamp of the PRL.
Gets or sets the donate component of the PRL.
Gets or sets the fiat component of the PRL.
Gets or sets the hash component of the PRL.
Gets or sets the host component of the PRL.
Gets or sets the hostname component of the PRL.
Gets or sets the href component of the PRL.
Gets or sets the IBAN component of the PRL.
Gets or sets the item name component of the PRL.
Gets or sets the location component of the PRL.
Gets or sets the message component of the PRL.
Gets or sets the network component of the PRL.
Gets or sets the organization name component of the PRL.
Gets the origin component of the PRL.
Gets or sets the password component of the PRL.
Gets or sets the pathname component of the PRL.
Gets or sets the port component of the PRL.
Gets or sets the protocol component of the PRL.
Gets or sets the receiver name component of the PRL.
Gets or sets the recurring component of the PRL.
Gets or sets the route component of the PRL.
Gets or sets the routing number component of the PRL.
Gets or sets the search component of the PRL.
Gets the URLSearchParams object.
Gets or sets the split component of the PRL.
Gets or sets the username component of the PRL.
Gets or sets the amount component of the PRL. This contrasts with the amount
working only with the currency string and not the currency number itself.
Returns the string representation of the PRL.
Returns the JSON representation of the PRL.
Returns the PRL as a JSON object with all non-empty values.
This project is licensed under the CORE License - see the LICENSE file for details.
Feel free to contribute to this project. You can open issues for feature requests or bug fixes. Pull requests are also welcome.
This library is based on the URL API from MDN.