multiformats/js-multihash

How to detect multihash?

linonetwo opened this issue · 2 comments

I want to do something like:

if (isMultihash(someString)) {
  ...
}

Can I do this with js-multihash? Like using try catch or so:

try {
  multihash.decode(Buffer(someString));
catch (error) {
  throw new Error(`${someString} is not a multihash`);
}
lidel commented

Check multihash method from is-ipfs util, it relies on simple try/catch internally:

Thanks, @lidel.