From 2ca01ea6e7e3fe44a367bb621ebcdf50f9f90fab Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Mon, 16 Dec 2019 22:55:16 +0000 Subject: [PATCH] refactor: reuse ma validation fn --- src/core/components/bootstrap/add.js | 10 +--------- src/core/components/bootstrap/rm.js | 10 +--------- src/core/components/bootstrap/utils.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 18 deletions(-) create mode 100644 src/core/components/bootstrap/utils.js diff --git a/src/core/components/bootstrap/add.js b/src/core/components/bootstrap/add.js index 1f28aca05f..6405d2b0d6 100644 --- a/src/core/components/bootstrap/add.js +++ b/src/core/components/bootstrap/add.js @@ -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) { diff --git a/src/core/components/bootstrap/rm.js b/src/core/components/bootstrap/rm.js index 98ecb45873..070ae9bb14 100644 --- a/src/core/components/bootstrap/rm.js +++ b/src/core/components/bootstrap/rm.js @@ -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) { diff --git a/src/core/components/bootstrap/utils.js b/src/core/components/bootstrap/utils.js new file mode 100644 index 0000000000..4e525ce021 --- /dev/null +++ b/src/core/components/bootstrap/utils.js @@ -0,0 +1,11 @@ +'use strict' + +const isMultiaddr = require('mafmt').IPFS.matches + +exports.isValidMultiaddr = ma => { + try { + return isMultiaddr(ma) + } catch (err) { + return false + } +}