Package Exports
- @iota/validators
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@iota/validators) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@iota/validators
Collection of guards and validators, useful in IOTA development.
Installation
Instal using npm:
npm install @iota/validatorsor using yarn:
yarn add @iota/validatorsAPI Reference
validators~isTrytes(trytes, [length])
| Param | Type | Default |
|---|---|---|
| trytes | string |
|
| [length] | string | number |
"'1,'" |
Checks if input is correct trytes consisting of [9A-Z]; optionally validate length
validators~isTrytesOfExactLength(trytes, length)
| Param | Type |
|---|---|
| trytes | string |
| length | number |
validators~isTrytesOfMaxLength(trytes, length)
| Param | Type |
|---|---|
| trytes | string |
| length | number |
validators~isEmpty(hash)
| Param | Type |
|---|---|
| hash | string |
Checks if input contains 9s only.
validators~isHash(hash)
| Param | Type |
|---|---|
| hash | string |
Checks if input is correct hash (81 trytes) or address with checksum (90 trytes)
validators~isInput(address)
| Param | Type |
|---|---|
| address | string |
Checks if input is valid input object. Address can be passed with or without checksum. It does not validate the checksum.
validators~isTag(tag)
| Param | Type |
|---|---|
| tag | string |
Checks that input is valid tag trytes.
validators~isTransfer(transfer)
| Param | Type |
|---|---|
| transfer | Transfer |
Checks if input is valid transfer object.
validators~isUri(uri)
| Param | Type |
|---|---|
| uri | string |
Checks that a given URI is valid
Valid Examples:
udp://[2001:db8:a0b:12f0::1]:14265udp://[2001:db8:a0b:12f0::1]udp://8.8.8.8:14265udp://domain.comudp://domain2.com:14265
validators~validate()
Throws:
Errorerror
Runs each validator in sequence, and throws on the first occurence of invalid data.
Validators are passed as arguments and executed in given order.
You might want place validate() in promise chains before operations that require valid inputs,
taking advantage of built-in promise branching.
Example
try {
validate([
value, // Given value
isTrytes, // Validator function
'Invalid trytes' // Error message
])
} catch (err) {
console.log(err.message) // 'Invalid trytes'
}validators~isAddress(address)
| Param | Type | Description |
|---|---|---|
| address | string |
Address trytes, with checksum |
Checks integrity of given address by validating the checksum.