Skip to content

Commit fc3cdf2

Browse files
Use dignified.js
1 parent 805aa79 commit fc3cdf2

File tree

51 files changed

+37
-84
lines changed

Some content is hidden

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

51 files changed

+37
-84
lines changed

.gitignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ atlassian-ide-plugin.xml
3131
com_crashlytics_export_strings.xml
3232
/node_modules
3333
**/*.log
34-
tests/repo-just-for-test*
35-
/tests/blocks
34+
test/repo-just-for-test*
35+
/test/blocks
36+
37+
dist
38+
lib

karma.conf.js

-54
This file was deleted.

package.json

+11-20
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,29 @@
44
"description": "A JavaScript implementations of the IPFS MerkleDAG implementations (protobufs)",
55
"main": "./src/index.js",
66
"scripts": {
7-
"test": "npm run test:node && npm run test:browser",
8-
"test:node": "mocha tests/index.js",
9-
"test:browser": "karma start --single-run=true karma.conf.js",
10-
"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"
1113
},
1214
"pre-commit": [
1315
"lint",
1416
"test"
1517
],
1618
"author": "Vijayee Kulkaa <[email protected]>",
1719
"contributors": [
18-
"David Dias <[email protected]>"
20+
"David Dias <[email protected]>",
21+
"Friedel Ziegelmayer <[email protected]>"
1922
],
2023
"license": "ISC",
2124
"repository": {
2225
"type": "git",
2326
"url": "https://github.com/vijayee/js-ipfs-merkle-dag.git"
2427
},
2528
"dependencies": {
29+
"detect-node": "^2.0.3",
2630
"ipfs-blocks": "^0.1.0",
2731
"is-ipfs": "^0.2.0",
2832
"multihashing": "^0.2.0",
@@ -31,29 +35,16 @@
3135
},
3236
"devDependencies": {
3337
"async": "^1.5.2",
34-
"brfs": "^1.4.3",
3538
"bs58": "^3.0.0",
3639
"buffer-loader": "0.0.1",
3740
"chai": "^3.5.0",
41+
"dignified.js": "github:dignifiedquire/dignified.js",
3842
"fs-blob-store": "^5.2.1",
3943
"idb-plus-blob-store": "^1.0.0",
4044
"ipfs-repo": "^0.5.3",
41-
"json-loader": "^0.5.4",
42-
"karma": "^0.13.19",
43-
"karma-chrome-launcher": "^0.2.2",
44-
"karma-cli": "^0.1.2",
45-
"karma-firefox-launcher": "^0.1.7",
46-
"karma-mocha": "^0.2.1",
47-
"karma-sourcemap-loader": "^0.3.7",
48-
"karma-spec-reporter": "0.0.24",
49-
"karma-webpack": "^1.7.0",
5045
"lodash": "^4.6.1",
51-
"mocha": "^2.4.5",
5246
"ncp": "^2.0.0",
5347
"pre-commit": "^1.1.2",
54-
"rimraf": "^2.5.0",
55-
"standard": "^6.0.8",
56-
"transform-loader": "^0.2.3",
57-
"webpack": "^2.0.7-beta"
48+
"rimraf": "^2.5.0"
5849
}
5950
}

src/dag-node.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
var util = require('./util')
24
var protobuf = require('protocol-buffers')
35
var stable = require('stable')

src/dag-service-batch.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
var Block = require('ipfs-blocks').Block
24

35
exports = module.exports = Batch

src/dag-service.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
const DAGNode = require('./dag-node').DAGNode
24
const Block = require('ipfs-blocks').Block
35
const isIPFS = require('is-ipfs')
@@ -70,8 +72,9 @@ function DAGService (blockService) {
7072
nodeStack.push(node)
7173

7274
var keys = []
75+
var link
7376
for (var i = 0; i < node.links.length; i++) {
74-
var link = node.links[i]
77+
link = node.links[i]
7578
keys.push(link.hash)
7679
}
7780
linkStack = linkStack.concat(keys)
@@ -81,13 +84,14 @@ function DAGService (blockService) {
8184
if (next) {
8285
this.getRecursive(next, callback, linkStack, nodeStack)
8386
} else {
87+
const compare = (hash) => (node) => {
88+
node.multihash().equals(hash)
89+
}
8490
for (var k = 0; k < nodeStack.length; k++) {
8591
var current = nodeStack[k]
8692
for (var j = 0; j < current.links.length; j++) {
8793
link = current.links[j]
88-
var index = nodeStack.findIndex((node) => {
89-
return node.multihash().equals(link.hash)
90-
})
94+
var index = nodeStack.findIndex(compare(link.hash))
9195
if (index !== -1) {
9296
link.node = nodeStack[index]
9397
}

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
exports.DAGNode = require('./dag-node.js').DAGNode
24
exports.DAGLink = require('./dag-node.js').DAGLink
35
exports.DAGService = require('./dag-service.js')

src/util.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
'use strict'
2+
13
var multihashing = require('multihashing')
4+
var 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/index.js renamed to test/node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const expect = require('chai').expect
77
const IPFSRepo = require('ipfs-repo')
88

99
describe('node test blocks', () => {
10-
const repoExample = process.cwd() + '/tests/example-repo'
11-
const repoTests = process.cwd() + '/tests/repo-just-for-test' + Date.now()
10+
const repoExample = process.cwd() + '/test/example-repo'
11+
const repoTests = process.cwd() + '/test/repo-just-for-test' + Date.now()
1212

1313
before((done) => {
1414
ncp(repoExample, repoTests, (err) => {

0 commit comments

Comments
 (0)