Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 205b548

Browse files
Setup dignified.js
1 parent a4c0487 commit 205b548

File tree

50 files changed

+68
-35
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+68
-35
lines changed

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: node_js
2+
node_js:
3+
- '4'
4+
- '5'
5+
6+
before_install:
7+
- npm i -g npm
8+
# Workaround for a permissions issue with Travis virtual machine images
9+
10+
addons:
11+
firefox: 'latest'
12+
13+
before_script:
14+
- export DISPLAY=:99.0
15+
- sh -e /etc/init.d/xvfb start
16+
17+
script:
18+
- npm run lint
19+
- npm test

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
"description": "JavaScript Implementation of Block and BlockService",
55
"main": "src/index.js",
66
"scripts": {
7-
"test": "mocha tests/index.js",
8-
"lint": "standard"
7+
"lint": "dignified-lint",
8+
"build": "dignified-build",
9+
"test": "dignified-test",
10+
"test:node": "dignified-test node",
11+
"test:browser": "dignified-test browser",
12+
"release": "dignified-release"
913
},
1014
"pre-commit": [
1115
"lint",
@@ -30,17 +34,17 @@
3034
"devDependencies": {
3135
"bs58": "^3.0.0",
3236
"chai": "^3.5.0",
37+
"dignified.js": "github:dignifiedquire/dignified.js",
3338
"fs-blob-store": "^5.2.1",
3439
"ipfs-repo": "^0.3.0",
35-
"mocha": "^2.4.5",
3640
"ncp": "^2.0.0",
3741
"pre-commit": "^1.1.2",
38-
"rimraf": "^2.5.1",
39-
"standard": "^5.4.1"
42+
"rimraf": "^2.5.1"
4043
},
4144
"dependencies": {
4245
"async": "^1.5.2",
4346
"bl": "^1.0.1",
47+
"detect-node": "^2.0.3",
4448
"multihashing": "^0.2.0"
4549
}
4650
}

src/block-service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
'use strict'
12
const Block = require('./block')
23
const bl = require('bl')
34
const async = require('async')
45

5-
module.exports = BlockService
6-
76
// BlockService is a hybrid block datastore. It stores data in a local
87
// datastore and may retrieve data from a remote Exchange.
98
// It uses an internal `datastore.Datastore` instance to store values.
109
function BlockService (ipfsRepo, exchange) {
1110
this.addBlock = (block, callback) => {
12-
var ws = ipfsRepo.datastore.createWriteStream(block.key)
11+
const ws = ipfsRepo.datastore.createWriteStream(block.key)
1312
ws.write(block.data)
1413
ws.on('finish', callback)
1514
ws.end()
@@ -44,7 +43,7 @@ function BlockService (ipfsRepo, exchange) {
4443
return callback(new Error('Invalid batch of multihashes'))
4544
}
4645

47-
var blocks = []
46+
const blocks = []
4847

4948
async.each(multihashes, (multihash, next) => {
5049
this.getBlock(multihash, (err, block) => {
@@ -77,3 +76,4 @@ function BlockService (ipfsRepo, exchange) {
7776
}
7877
}
7978

79+
module.exports = BlockService

src/block.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
'use strict'
12
const util = require('./util')
23

34
// Immutable block of data
4-
5-
module.exports = Block
6-
75
function Block (data) {
86
if (!data) { throw new Error('Block must be constructed with data') }
97

10-
if (!(this instanceof Block)) { return new Block(data) }
8+
if (!(this instanceof Block)) {
9+
return new Block(data)
10+
}
1111

1212
this.data = new Buffer(data)
1313
this.key = util.hash(this.data)
1414
}
15+
16+
module.exports = Block

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
exports.BlockService = require('./block-service.js')
24
exports.Block = require('./block.js')
35
exports.util = require('./util.js')

src/util.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
var multihashing = require('multihashing')
1+
'use strict'
2+
3+
const multihashing = require('multihashing')
4+
const isNode = require('detect-node')
25

36
exports = module.exports
47

58
// Hash is the global IPFS hash function. uses multihash SHA2_256, 256 bits
6-
exports.hash = (data) => { return multihashing(data, 'sha2-256') }
7-
exports.isBrowser = () => { return !!global.window }
9+
exports.hash = (data) => multihashing(data, 'sha2-256')
10+
exports.isBrowser = () => !isNode

tests/block-service-test.js renamed to test/block-service-test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* globals describe, it */
2-
1+
/* eslint-env mocha */
32
'use strict'
43

54
const expect = require('chai').expect
@@ -9,7 +8,7 @@ const BlockService = require('../src').BlockService
98
const IPFSRepo = require('ipfs-repo')
109

1110
describe('block-service', () => {
12-
var bs
11+
let bs
1312

1413
it('create a block-service', (done) => {
1514
const repo = new IPFSRepo(process.env.IPFS_PATH)

tests/block-test.js renamed to test/block-test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/* globals describe, it */
2-
1+
/* eslint-env mocha */
32
'use strict'
43

54
const expect = require('chai').expect
@@ -14,7 +13,7 @@ describe('block', () => {
1413
})
1514

1615
it('fail to create an empty block', (done) => {
17-
var b
16+
let b
1817
try {
1918
b = new Block()
2019
} catch (err) {
@@ -34,7 +33,7 @@ describe('block', () => {
3433
// it from the original implementation
3534
// It doesn't stricly verify the immutability of the Block object
3635
const block = new Block("Can't change this!")
37-
var key = block.key
36+
let key = block.key
3837
key = new Buffer('new key')
3938

4039
expect(key.equals(block.key)).to.equal(false)

test/browser.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
describe.skip('blocks', () => {
5+
it('works in the browser')
6+
})

0 commit comments

Comments
 (0)