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

Commit 97af048

Browse files
committed
fix(style): apply CR
1 parent 76b6670 commit 97af048

File tree

2 files changed

+13
-44
lines changed

2 files changed

+13
-44
lines changed

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"interface-ipfs-core": "^0.6.0",
5151
"left-pad": "^1.1.1",
5252
"lodash": "^4.14.1",
53-
"mocha": "^2.5.1",
5453
"ncp": "^2.0.0",
5554
"nexpect": "^0.5.0",
5655
"pre-commit": "^1.1.3",
@@ -68,8 +67,8 @@
6867
"fs-blob-store": "^5.2.1",
6968
"glob": "^7.0.5",
7069
"hapi": "^14.0.0",
70+
"ipfs-api": "ipfs/js-ipfs-api#8cc853f",
7171
"ipfs-bitswap": "^0.6.0",
72-
"ipfs-api": "ipfs/js-ipfs-api#91de5ac",
7372
"ipfs-block": "^0.3.0",
7473
"ipfs-block-service": "^0.4.0",
7574
"ipfs-merkle-dag": "^0.6.2",
@@ -81,11 +80,11 @@
8180
"joi": "^9.0.4",
8281
"libp2p-ipfs": "^0.12.1",
8382
"libp2p-ipfs-browser": "^0.12.1",
84-
"lodash.get": "^4.4.0",
85-
"lodash.set": "^4.3.0",
83+
"lodash.get": "^4.4.1",
84+
"lodash.set": "^4.3.1",
8685
"mafmt": "^2.1.1",
87-
"multihashes": "^0.2.2",
8886
"multiaddr": "^2.0.2",
87+
"multihashes": "^0.2.2",
8988
"path-exists": "^3.0.0",
9089
"peer-book": "^0.3.0",
9190
"peer-id": "^0.7.0",

src/core/ipfs/config.js

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const _get = require('lodash.get')
5+
const _set = require('lodash.set')
46

57
module.exports = function config (self) {
68
return {
@@ -22,21 +24,11 @@ module.exports = function config (self) {
2224
if (err) {
2325
return callback(err)
2426
}
25-
const keys = key.split('.')
26-
let finished = false
27-
keys.forEach((key) => {
28-
if (finished) {
29-
return
30-
}
31-
if (config[key]) {
32-
config = config[key]
33-
} else {
34-
finished = true
35-
callback(new Error(('Key does not exist in config')))
36-
}
37-
})
38-
if (!finished) {
39-
callback(null, config)
27+
const value = _get(config, key, undefined)
28+
if (!value) {
29+
callback(new Error('Key does not exist in config'))
30+
} else {
31+
callback(null, value)
4032
}
4133
})
4234
}),
@@ -50,33 +42,11 @@ module.exports = function config (self) {
5042
}
5143

5244
self._repo.config.get((err, config) => {
53-
const configBak = config
5445
if (err) {
5546
return callback(err)
5647
}
57-
const keys = key.split('.')
58-
let finished = false
59-
keys.forEach((key, index) => {
60-
if (finished) {
61-
return
62-
}
63-
if (config[key]) {
64-
if (index === keys.length - 1) {
65-
finished = true
66-
config[key] = value
67-
}
68-
config = config[key]
69-
} else {
70-
if (index === keys.length - 1) {
71-
finished = true
72-
config[key] = value
73-
} else {
74-
config = config[key] = {}
75-
}
76-
}
77-
})
78-
79-
self.config.replace(configBak, callback)
48+
_set(config, key, value)
49+
self.config.replace(config, callback)
8050
})
8151
}),
8252
replace: promisify((config, callback) => {

0 commit comments

Comments
 (0)