Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: remove use of assert module (#173)
Browse files Browse the repository at this point in the history
The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.
  • Loading branch information
achingbrain committed Feb 13, 2020
1 parent 7b99370 commit de85eb6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const assert = require('assert')
const { EventEmitter } = require('events')
const errcode = require('err-code')

Expand Down Expand Up @@ -67,7 +66,10 @@ class KadDHT extends EventEmitter {
randomWalk = {}
}) {
super()
assert(dialer, 'libp2p-kad-dht requires an instance of Dialer')

if (!dialer) {
throw new Error('libp2p-kad-dht requires an instance of Dialer')
}

/**
* Local reference to the libp2p dialer instance
Expand Down
5 changes: 2 additions & 3 deletions src/message/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const assert = require('assert')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const protons = require('protons')
Expand All @@ -21,8 +20,8 @@ class Message {
* @param {number} level
*/
constructor (type, key, level) {
if (key) {
assert(Buffer.isBuffer(key))
if (key && !Buffer.isBuffer(key)) {
throw new Error('Key must be a buffer')
}

this.type = type
Expand Down
5 changes: 3 additions & 2 deletions src/random-walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const crypto = require('libp2p-crypto')
const multihashing = require('multihashing-async')
const PeerId = require('peer-id')
const assert = require('assert')
const AbortController = require('abort-controller')
const errcode = require('err-code')
const times = require('p-times')
Expand All @@ -23,7 +22,9 @@ class RandomWalk {
* @param {DHT} options.dht
*/
constructor (dht, options) {
assert(dht, 'Random Walk needs an instance of the Kademlia DHT')
if (!dht) {
throw new Error('Random Walk needs an instance of the Kademlia DHT')
}

this._kadDHT = dht
this._options = {
Expand Down
3 changes: 1 addition & 2 deletions test/random-walk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const expect = chai.expect
const sinon = require('sinon')
const RandomWalk = require('../src/random-walk')
const { defaultRandomWalk } = require('../src/constants')
const { AssertionError } = require('assert')

const TestDHT = require('./utils/test-dht')
const {
Expand All @@ -35,7 +34,7 @@ describe('Random Walk', () => {

describe('configuration', () => {
it('should use require a dht', () => {
expect(() => new RandomWalk()).to.throw(AssertionError)
expect(() => new RandomWalk()).to.throw()
})

it('should use defaults', () => {
Expand Down

0 comments on commit de85eb6

Please sign in to comment.