joi-multiaddr

4.0.0 • Public • Published

joi-multiaddr

Build Status dependencies Status JavaScript Style Guide

Validate a multiaddr and common formats.

Install

npm install joi-multiaddr

Usage

const Joi = require('joi').extend(require('joi-multiaddr'))
 
/**
 * Validate a String or Buffer is in multiaddr format:
 */
 
const schema = Joi.multiaddr()
const result = schema.validate('/ip4/0.0.7.6/tcp/1234')
 
console.log(result.error) // null
// Note, successful validation converts to a Multiaddr instance:
console.log(result.value) // <Multiaddr 04000007060604d2 - /ip4/0.0.7.6/tcp/1234>
 
/**
 * Validate formats using mafmt (https://github.com/multiformats/js-mafmt):
 */
 
const dnsSchema = Joi.multiaddr().DNS()
const tcpSchema = Joi.multiaddr().TCP()
const ipfsSchema = Joi.multiaddr().IPFS()
/* etc. */
 
ipfsSchema.validate('/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4') // Success!
ipfsSchema.validate('/ip4/0.0.7.6/tcp/1234') // Failure :(

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

Package Sidebar

Install

npm i joi-multiaddr

Weekly Downloads

25

Version

4.0.0

License

MIT

Unpacked Size

8.06 kB

Total Files

6

Last publish

Collaborators

  • alanshaw