is-ipfs
A set of utilities to help identify IPFS resources.
Install
npm i --save is-ipfs
Usage
const isIPFS = require('is-ipfs')
isIPFS.multihash('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.multihash('noop')
isIPFS.url('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.url('https://ipfs.io/ipns/github.com')
isIPFS.url('https://github.com/ipfs/js-ipfs/blob/master/README.md')
isIPFS.url('https://google.com')
isIPFS.path('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.path('/ipns/github.com')
isIPFS.path('/ipfs/js-ipfs/blob/master/README.md')
isIPFS.urlOrPath('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.urlOrPath('https://ipfs.io/ipns/github.com')
isIPFS.urlOrPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.urlOrPath('/ipns/github.com')
isIPFS.urlOrPath('https://google.com')
isIPFS.ipfsUrl('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.ipfsUrl('https://ipfs.io/ipfs/invalid-hash')
isIPFS.ipnsUrl('https://ipfs.io/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.ipnsUrl('https://ipfs.io/ipns/github.com')
isIPFS.ipfsPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.ipfsPath('/ipfs/invalid-hash')
isIPFS.ipnsPath('/ipfs/QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o')
isIPFS.ipnsPath('/ipns/github.com')
API
isIPFS.multihash(hash)
Returns true
if the provided string is a valid multihash
or false
otherwise.
isIPFS.url(url)
Returns true
if the provided string is a valid IPFS or IPNS url or false
otherwise.
isIPFS.path(path)
Returns true
if the provided string is a valid IPFS or IPNS path or false
otherwise.
isIPFS.urlOrPath(path)
Returns true
if the provided string is a valid IPFS or IPNS url or path or false
otherwise.
isIPFS.ipfsUrl(url)
Returns true
if the provided string is a valid IPFS url or false
otherwise.
isIPFS.ipnsUrl(url)
Returns true
if the provided string is a valid IPNS url or false
otherwise.
isIPFS.ipfsPath(path)
Returns true
if the provided string is a valid IPFS path or false
otherwise.
isIPFS.ipnsPath(path)
Returns true
if the provided string is a valid IPNS path or false
otherwise.
Note: the regex used for these checks is also exported as isIPFS.urlPattern
License
MIT