Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 5bccbb6

Browse files
committed
Merge pull request #127 from Dignifiedquire/style-cleanup
style cleanup + browser build fix
2 parents 39219d3 + 3d593fa commit 5bccbb6

21 files changed

+608
-691
lines changed

.eslintrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
22
"parser": "babel-eslint",
3-
"extends": "standard"
3+
"extends": "standard",
4+
"rules": {
5+
"no-var": 2
6+
}
47
}

dist/ipfsapi.js

Lines changed: 306 additions & 438 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ipfsapi.min.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
var gulp = require('gulp')
2-
var runSequence = require('run-sequence')
1+
'use strict'
2+
3+
const gulp = require('gulp')
4+
const runSequence = require('run-sequence')
35

46
require('require-dir')('tasks')
57

6-
gulp.task('default', function (done) {
8+
gulp.task('default', done => {
79
runSequence(
810
'lint',
911
'test',
@@ -17,8 +19,8 @@ gulp.task('default', function (done) {
1719
// The issue for this is that the daemon start seems to keep
1820
// some open connections that are not cleaned up properly and so
1921
// gulp does not exit. So it's probably a bug in node-ipfs-ctl
20-
gulp.on('stop', function () {
21-
process.nextTick(function () {
22+
gulp.on('stop', () => {
23+
process.nextTick(() => {
2224
process.exit()
2325
})
2426
})

karma.conf.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
var webpackConfig = require('./tasks/config').webpack
1+
const webpackConfig = require('./tasks/config').webpack
22

33
module.exports = function (config) {
4-
var reporters = ['progress']
4+
const reporters = ['progress']
55

6-
if (process.env.TRAVIS) {
7-
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
8-
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.')
9-
process.exit(1)
10-
}
6+
// if (process.env.TRAVIS) {
7+
// if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
8+
// console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.')
9+
// process.exit(1)
10+
// }
1111

12-
reporters.push('saucelabs')
13-
}
12+
// reporters.push('saucelabs')
13+
// }
1414

1515
// Browsers to run on Sauce Labs
1616
// Check out https://saucelabs.com/platforms for all browser/OS combos
17-
var customLaunchers = {
17+
const customLaunchers = {
1818
'SL_Chrome': {
1919
base: 'SauceLabs',
2020
platform: 'OS X 10.11',
@@ -75,7 +75,7 @@ module.exports = function (config) {
7575
logLevel: process.env.DEBUG ? config.LOG_DEBUG : config.LOG_INFO,
7676
autoWatch: false,
7777
customLaunchers: customLaunchers,
78-
browsers: process.env.TRAVIS ? Object.keys(customLaunchers) : ['Chrome'],
78+
browsers: process.env.TRAVIS ? ['Firefox'] /* Object.keys(customLaunchers)*/ : ['Chrome'],
7979
singleRun: false,
8080
concurrency: 2,
8181
browserNoActivityTimeout: 600000

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"babel-loader": "^6.2.0",
2727
"babel-plugin-transform-runtime": "^6.1.18",
2828
"babel-preset-es2015": "^6.0.15",
29+
"babel-runtime": "^5.8.34",
2930
"concurrently": "^1.0.0",
3031
"eslint-config-standard": "^4.4.0",
3132
"eslint-plugin-standard": "^1.3.1",
@@ -40,6 +41,7 @@
4041
"json-loader": "^0.5.3",
4142
"karma": "^0.13.11",
4243
"karma-chrome-launcher": "^0.2.1",
44+
"karma-firefox-launcher": "^0.1.7",
4345
"karma-mocha": "^0.2.0",
4446
"karma-sauce-launcher": "^0.3.0",
4547
"karma-webpack": "^1.7.0",
@@ -64,7 +66,7 @@
6466
},
6567
"pre-commit": [
6668
"lint",
67-
"test:node"
69+
"test"
6870
],
6971
"keywords": [
7072
"ipfs"

src/config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
var pkg = require('../package.json')
1+
'use strict'
22

3-
exports = module.exports = function getConfig () {
3+
const pkg = require('../package.json')
4+
5+
exports = module.exports = () => {
46
return {
57
'api-path': '/api/v0/',
6-
'user-agent': '/node-' + pkg.name + '/' + pkg.version + '/',
8+
'user-agent': `/node-$pkg.name}/${pkg.version}/`,
79
'host': 'localhost',
810
'port': '5001'
911
}

src/get-files-stream.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1-
var File = require('vinyl')
2-
var vinylfs = require('vinyl-fs-browser')
3-
var vmps = require('vinyl-multipart-stream')
4-
var stream = require('stream')
5-
var Merge = require('merge-stream')
1+
'use strict'
2+
3+
const File = require('vinyl')
4+
const vinylfs = require('vinyl-fs-browser')
5+
const vmps = require('vinyl-multipart-stream')
6+
const stream = require('stream')
7+
const Merge = require('merge-stream')
68

79
exports = module.exports = getFilesStream
810

911
function getFilesStream (files, opts) {
1012
if (!files) return null
1113

1214
// merge all inputs into one stream
13-
var adder = new Merge()
15+
const adder = new Merge()
1416

1517
// single stream for pushing directly
16-
var single = new stream.PassThrough({objectMode: true})
18+
const single = new stream.PassThrough({objectMode: true})
1719
adder.add(single)
1820

19-
for (var i = 0; i < files.length; i++) {
20-
var file = files[i]
21+
for (let i = 0; i < files.length; i++) {
22+
const file = files[i]
2123

2224
if (typeof (file) === 'string') {
23-
var srcOpts = {
25+
const srcOpts = {
2426
buffer: false,
2527
stripBOM: false,
2628
followSymlinks: opts.followSymlinks != null ? opts.followSymlinks : true
@@ -53,7 +55,7 @@ function vinylFile (file) {
5355
}
5456

5557
// let's try to make a vinyl file?
56-
var f = {cwd: '/', base: '/', path: ''}
58+
const f = {cwd: '/', base: '/', path: ''}
5759
if (file.contents && file.path) {
5860
// set the cwd + base, if there.
5961
f.path = file.path
@@ -78,7 +80,7 @@ function vinylContentsSafe (c) {
7880
if (typeof (c.pipe) === 'function') {
7981
// hey, looks like a stream. but vinyl won't detect it.
8082
// pipe it to a PassThrough, and use that
81-
var s = new stream.PassThrough()
83+
const s = new stream.PassThrough()
8284
return c.pipe(s)
8385
}
8486

src/index.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
var multiaddr = require('multiaddr')
2-
var getConfig = require('./config')
3-
var getRequestAPI = require('./request-api')
4-
var Wreck = require('wreck')
1+
'use strict'
2+
3+
const multiaddr = require('multiaddr')
4+
const getConfig = require('./config')
5+
const getRequestAPI = require('./request-api')
6+
const Wreck = require('wreck')
57

68
exports = module.exports = IpfsAPI
79

810
function IpfsAPI (host_or_multiaddr, port) {
9-
var self = this
10-
var config = getConfig()
11+
const self = this
12+
const config = getConfig()
1113

1214
if (!(self instanceof IpfsAPI)) {
1315
return new IpfsAPI(host_or_multiaddr, port)
1416
}
1517

1618
try {
17-
var maddr = multiaddr(host_or_multiaddr).nodeAddress()
19+
const maddr = multiaddr(host_or_multiaddr).nodeAddress()
1820
config.host = maddr.address
1921
config.port = maddr.port
2022
} catch (e) {
@@ -25,17 +27,17 @@ function IpfsAPI (host_or_multiaddr, port) {
2527
// autoconfigure in browser
2628
if (!config.host &&
2729
typeof window !== 'undefined') {
28-
var split = window.location.host.split(':')
30+
const split = window.location.host.split(':')
2931
config.host = split[0]
3032
config.port = split[1]
3133
}
3234

33-
var requestAPI = getRequestAPI(config)
35+
const requestAPI = getRequestAPI(config)
3436

3537
// -- Internal
3638

3739
function command (name) {
38-
return function (opts, cb) {
40+
return (opts, cb) => {
3941
if (typeof (opts) === 'function') {
4042
cb = opts
4143
opts = {}
@@ -45,7 +47,7 @@ function IpfsAPI (host_or_multiaddr, port) {
4547
}
4648

4749
function argCommand (name) {
48-
return function (arg, opts, cb) {
50+
return (arg, opts, cb) => {
4951
if (typeof (opts) === 'function') {
5052
cb = opts
5153
opts = {}
@@ -58,7 +60,7 @@ function IpfsAPI (host_or_multiaddr, port) {
5860

5961
self.send = requestAPI
6062

61-
self.add = function (files, opts, cb) {
63+
self.add = (files, opts, cb) => {
6264
if (typeof (opts) === 'function' && cb === undefined) {
6365
cb = opts
6466
opts = {}
@@ -82,17 +84,17 @@ function IpfsAPI (host_or_multiaddr, port) {
8284

8385
self.config = {
8486
get: argCommand('config'),
85-
set: function (key, value, opts, cb) {
87+
set (key, value, opts, cb) {
8688
if (typeof (opts) === 'function') {
8789
cb = opts
8890
opts = {}
8991
}
9092
return requestAPI('config', [key, value], opts, null, cb)
9193
},
92-
show: function (cb) {
94+
show (cb) {
9395
return requestAPI('config/show', null, null, null, true, cb)
9496
},
95-
replace: function (file, cb) {
97+
replace (file, cb) {
9698
return requestAPI('config/replace', null, null, file, cb)
9799
}
98100
}
@@ -106,15 +108,15 @@ function IpfsAPI (host_or_multiaddr, port) {
106108
self.version = command('version')
107109
self.commands = command('commands')
108110

109-
self.mount = function (ipfs, ipns, cb) {
111+
self.mount = (ipfs, ipns, cb) => {
110112
if (typeof ipfs === 'function') {
111113
cb = ipfs
112114
ipfs = null
113115
} else if (typeof ipns === 'function') {
114116
cb = ipns
115117
ipns = null
116118
}
117-
var opts = {}
119+
const opts = {}
118120
if (ipfs) opts.f = ipfs
119121
if (ipns) opts.n = ipns
120122
return requestAPI('mount', null, opts, null, cb)
@@ -126,7 +128,7 @@ function IpfsAPI (host_or_multiaddr, port) {
126128

127129
self.block = {
128130
get: argCommand('block/get'),
129-
put: function (file, cb) {
131+
put (file, cb) {
130132
if (Array.isArray(file)) {
131133
return cb(null, new Error('block.put() only accepts 1 file'))
132134
}
@@ -136,7 +138,7 @@ function IpfsAPI (host_or_multiaddr, port) {
136138

137139
self.object = {
138140
get: argCommand('object/get'),
139-
put: function (file, encoding, cb) {
141+
put (file, encoding, cb) {
140142
if (typeof encoding === 'function') {
141143
return cb(null, new Error("Must specify an object encoding ('json' or 'protobuf')"))
142144
}
@@ -145,7 +147,7 @@ function IpfsAPI (host_or_multiaddr, port) {
145147
data: argCommand('object/data'),
146148
stat: argCommand('object/stat'),
147149
links: argCommand('object/links'),
148-
patch: function (file, opts, cb) {
150+
patch (file, opts, cb) {
149151
return requestAPI('object/patch', [file].concat(opts), null, null, cb)
150152
}
151153
}
@@ -155,14 +157,14 @@ function IpfsAPI (host_or_multiaddr, port) {
155157
connect: argCommand('swarm/connect')
156158
}
157159

158-
self.ping = function (id, cb) {
160+
self.ping = (id, cb) => {
159161
return requestAPI('ping', id, { n: 1 }, null, function (err, res) {
160162
if (err) return cb(err, null)
161163
cb(null, res[1])
162164
})
163165
}
164166

165-
self.id = function (id, cb) {
167+
self.id = (id, cb) => {
166168
if (typeof id === 'function') {
167169
cb = id
168170
id = null
@@ -171,35 +173,35 @@ function IpfsAPI (host_or_multiaddr, port) {
171173
}
172174

173175
self.pin = {
174-
add: function (hash, opts, cb) {
176+
add (hash, opts, cb) {
175177
if (typeof opts === 'function') {
176178
cb = opts
177179
opts = null
178180
}
179181

180182
requestAPI('pin/add', hash, opts, null, cb)
181183
},
182-
remove: function (hash, opts, cb) {
184+
remove (hash, opts, cb) {
183185
if (typeof opts === 'function') {
184186
cb = opts
185187
opts = null
186188
}
187189

188190
requestAPI('pin/rm', hash, opts, null, cb)
189191
},
190-
list: function (type, cb) {
192+
list (type, cb) {
191193
if (typeof type === 'function') {
192194
cb = type
193195
type = null
194196
}
195-
var opts = null
197+
let opts = null
196198
if (type) opts = { type: type }
197199
return requestAPI('pin/ls', null, opts, null, cb)
198200
}
199201
}
200202

201203
self.log = {
202-
tail: function (cb) {
204+
tail (cb) {
203205
return requestAPI('log/tail', null, {enc: 'text'}, null, true, cb)
204206
}
205207
}
@@ -217,13 +219,13 @@ function IpfsAPI (host_or_multiaddr, port) {
217219
self.dht = {
218220
findprovs: argCommand('dht/findprovs'),
219221

220-
get: function (key, opts, cb) {
222+
get (key, opts, cb) {
221223
if (typeof (opts) === 'function' && !cb) {
222224
cb = opts
223225
opts = null
224226
}
225227

226-
return requestAPI('dht/get', key, opts, null, function (err, res) {
228+
return requestAPI('dht/get', key, opts, null, (err, res) => {
227229
if (err) return cb(err)
228230
if (!res) return cb(new Error('empty response'))
229231
if (res.length === 0) return cb(new Error('no value returned for key'))
@@ -241,7 +243,7 @@ function IpfsAPI (host_or_multiaddr, port) {
241243
})
242244
},
243245

244-
put: function (key, value, opts, cb) {
246+
put (key, value, opts, cb) {
245247
if (typeof (opts) === 'function' && !cb) {
246248
cb = opts
247249
opts = null

0 commit comments

Comments
 (0)