diff --git a/src/index.js b/src/index.js index be394e7..88624d0 100644 --- a/src/index.js +++ b/src/index.js @@ -17,7 +17,7 @@ const fqdnProtocolMatch = 2 function isMultihash (hash) { const formatted = convertToString(hash) try { - const buffer = new Buffer(base58.decode(formatted)) + const buffer = Buffer.from(base58.decode(formatted)) multihash.decode(buffer) return true } catch (e) { diff --git a/test/test-cid.spec.js b/test/test-cid.spec.js index 8237d07..f9607f0 100644 --- a/test/test-cid.spec.js +++ b/test/test-cid.spec.js @@ -13,13 +13,13 @@ describe('ipfs cid', () => { }) it('isIPFS.cid should match a valid CIDv0 (multihash) buffer', (done) => { - const actual = isIPFS.cid(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.cid(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(true) done() }) it('isIPFS.cid should not match a broken CIDv0 buffer', (done) => { - const actual = isIPFS.cid(new Buffer('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) + const actual = isIPFS.cid(Buffer.from('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) expect(actual).to.equal(false) done() }) @@ -48,7 +48,6 @@ describe('ipfs cid', () => { done() }) - it('isIPFS.cid should not match an invalid CID', (done) => { const actual = isIPFS.cid('noop') expect(actual).to.equal(false) @@ -60,6 +59,4 @@ describe('ipfs cid', () => { expect(actual).to.equal(false) done() }) - - }) diff --git a/test/test-multibase.spec.js b/test/test-multibase.spec.js index bab9b3f..c5c5d7c 100644 --- a/test/test-multibase.spec.js +++ b/test/test-multibase.spec.js @@ -1,7 +1,6 @@ /* eslint-env mocha */ 'use strict' -const base58btc = require('bs58') const expect = require('chai').expect const isIPFS = require('../src/index') @@ -30,7 +29,6 @@ describe('ipfs base32cid', () => { done() }) - it('isIPFS.base32cid should not match an invalid CID', (done) => { const actual = isIPFS.base32cid('noop') expect(actual).to.equal(false) @@ -42,7 +40,6 @@ describe('ipfs base32cid', () => { expect(actual).to.equal(false) done() }) - }) describe('ipfs multibase', () => { @@ -69,5 +66,4 @@ describe('ipfs multibase', () => { expect(actual).to.equal(false) done() }) - }) diff --git a/test/test-multihash.spec.js b/test/test-multihash.spec.js index 4c23166..d82a823 100644 --- a/test/test-multihash.spec.js +++ b/test/test-multihash.spec.js @@ -13,13 +13,13 @@ describe('ipfs multihash', () => { }) it('isIPFS.multihash should match a valid multihash buffer', (done) => { - const actual = isIPFS.multihash(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.multihash(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(true) done() }) it('isIPFS.multihash should not match a buffer', (done) => { - const actual = isIPFS.multihash(new Buffer('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) + const actual = isIPFS.multihash(Buffer.from('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) expect(actual).to.equal(false) done() }) diff --git a/test/test-path.spec.js b/test/test-path.spec.js index 87a2b18..e28057a 100644 --- a/test/test-path.spec.js +++ b/test/test-path.spec.js @@ -37,7 +37,7 @@ describe('ipfs path', () => { }) it('isIPFS.ipfsPath should not match a buffer data type', (done) => { - const actual = isIPFS.ipfsPath(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.ipfsPath(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) @@ -67,7 +67,7 @@ describe('ipfs path', () => { }) it('isIPFS.ipnsPath should not match a buffer data type', (done) => { - const actual = isIPFS.ipnsPath(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.ipnsPath(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) @@ -97,7 +97,7 @@ describe('ipfs path', () => { }) it('isIPFS.path should not match a buffer data type', (done) => { - const actual = isIPFS.path(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.path(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) @@ -127,7 +127,7 @@ describe('ipfs path', () => { }) it('isIPFS.urlOrPath should not match a buffer data type', (done) => { - const actual = isIPFS.ipfsPath(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.ipfsPath(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) diff --git a/test/test-subdomain.spec.js b/test/test-subdomain.spec.js index aebacc6..23e0ffe 100644 --- a/test/test-subdomain.spec.js +++ b/test/test-subdomain.spec.js @@ -42,7 +42,7 @@ describe('ipfs subdomain', () => { }) it('isIPFS.ipfsSubdomain should not match a buffer data type', (done) => { - const actual = isIPFS.ipfsSubdomain(new Buffer(base58.decode('QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'))) + const actual = isIPFS.ipfsSubdomain(Buffer.from(base58.decode('QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'))) expect(actual).to.equal(false) done() }) @@ -82,7 +82,7 @@ describe('ipfs subdomain', () => { }) it('isIPFS.ipnsSubdomain should not match a buffer data type', (done) => { - const actual = isIPFS.ipnsSubdomain(new Buffer(base58.decode('QmNQuBJ8tg4QN6mSLXHekxBbcToPwKxamWNrDdEugxMTDd'))) + const actual = isIPFS.ipnsSubdomain(Buffer.from(base58.decode('QmNQuBJ8tg4QN6mSLXHekxBbcToPwKxamWNrDdEugxMTDd'))) expect(actual).to.equal(false) done() }) @@ -118,7 +118,7 @@ describe('ipfs subdomain', () => { }) it('isIPFS.subdomain should not match a buffer data type', (done) => { - const actual = isIPFS.subdomain(new Buffer(base58.decode('QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'))) + const actual = isIPFS.subdomain(Buffer.from(base58.decode('QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR'))) expect(actual).to.equal(false) done() }) @@ -142,5 +142,4 @@ describe('ipfs subdomain', () => { expect(actual).to.equal(false) done() }) - }) diff --git a/test/test-url.spec.js b/test/test-url.spec.js index a0e61eb..dcfaf1c 100644 --- a/test/test-url.spec.js +++ b/test/test-url.spec.js @@ -37,7 +37,7 @@ describe('ipfs url', () => { }) it('isIPFS.ipfsUrl should not match a buffer input', (done) => { - const actual = isIPFS.ipfsUrl(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.ipfsUrl(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) @@ -67,7 +67,7 @@ describe('ipfs url', () => { }) it('isIPFS.ipnsUrl should not match a buffer input', (done) => { - const actual = isIPFS.ipnsUrl(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.ipnsUrl(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() }) @@ -97,7 +97,7 @@ describe('ipfs url', () => { }) it('isIPFS.url should not match a buffer input', (done) => { - const actual = isIPFS.url(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) + const actual = isIPFS.url(Buffer.from(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) expect(actual).to.equal(false) done() })