Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
refactor: reuse ma validation fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Shaw committed Dec 16, 2019
1 parent 6b9deef commit c74fab4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
10 changes: 1 addition & 9 deletions src/core/components/bootstrap/add.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
'use strict'

const defaultConfig = require('../runtime/config-nodejs.js')
const isMultiaddr = require('mafmt').IPFS.matches

function isValidMultiaddr (ma) {
try {
return isMultiaddr(ma)
} catch (err) {
return false
}
}
const { isValidMultiaddr } = require('./utils')

module.exports = ({ repo }) => {
return async function add (multiaddr, options) {
Expand Down
10 changes: 1 addition & 9 deletions src/core/components/bootstrap/rm.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
'use strict'

const isMultiaddr = require('mafmt').IPFS.matches

function isValidMultiaddr (ma) {
try {
return isMultiaddr(ma)
} catch (err) {
return false
}
}
const { isValidMultiaddr } = require('./utils')

module.exports = ({ repo }) => {
return async function rm (multiaddr, options) {
Expand Down
11 changes: 11 additions & 0 deletions src/core/components/bootstrap/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const isMultiaddr = require('mafmt').IPFS.matches

exports.isValidMultiaddr = ma => {
try {
return isMultiaddr(ma)
} catch (err) {
return false
}
}

0 comments on commit c74fab4

Please sign in to comment.