Name: joi-multiaddr
Owner: TABLEFLIP
Description: Multiaddr validation with Joi
Created: 2018-02-28 09:43:25.0
Updated: 2018-04-06 16:25:35.0
Pushed: 2018-04-06 16:25:34.0
Homepage: null
Size: 162
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Validate a multiaddr and common formats.
install joi-multiaddr
t Joi = require('joi').extend(require('joi-multiaddr'))
alidate a String or Buffer is in multiaddr format:
t schema = Joi.multiaddr()
t result = schema.validate('/ip4/0.0.7.6/tcp/1234')
ole.log(result.error) // null
ote, successful validation converts to a Multiaddr instance:
ole.log(result.value) // <Multiaddr 04000007060604d2 - /ip4/0.0.7.6/tcp/1234>
alidate formats using mafmt (https://github.com/multiformats/js-mafmt):
t dnsSchema = Joi.multiaddr().DNS()
t tcpSchema = Joi.multiaddr().TCP()
t ipfsSchema = Joi.multiaddr().IPFS()
tc. */
Schema.validate('/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4') // Success!
Schema.validate('/ip4/0.0.7.6/tcp/1234') // Failure :(
Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw