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

Use dignified.js #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

language: node_js
node_js:
- 4
- 5

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
"name": "ipld",
"version": "0.4.0",
"description": "JavaScript implementation of the IPLD (InterpPlanetary Linked Data)",
"main": "src/index.js",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"test": "./node_modules/.bin/lab tests/*-test.js",
"codestyle-fix": "./node_modules/.bin/standard --format",
"codestyle": "./node_modules/.bin/standard"
"lint": "dignified-lint",
"build": "dignified-build",
"test": "dignified-test",
"test:node": "dignified-test node",
"test:browser": "dignified-test browser",
"release": "dignified-release"
},
"pre-commit": [
"codestyle"
"lint",
"test"
],
"repository": {
"type": "git",
Expand All @@ -35,9 +40,9 @@
"underscore": "^1.8.3"
},
"devDependencies": {
"chai": "^3.5.0",
"code": "^1.5.0",
"lab": "^5.15.2",
"pre-commit": "^1.1.1",
"standard": "^5.1.0"
"dignified.js": "github:dignifiedquire/dignified.js",
"pre-commit": "^1.1.1"
}
}
1 change: 1 addition & 0 deletions src/clone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// http://jsperf.com/cloning-an-object/2
'use strict'

exports = module.exports = function clone (obj) {
var target = {}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var cbor = require('cbor')
var cborSync = require('cbor-sync')

Expand Down
119 changes: 119 additions & 0 deletions test/test.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/* eslint-env mocha */
'use strict'

var expect = require('chai').expect
var ipld = require('../src')

describe('IPLD Tests', (done) => {
it('add the mlink as context a json blob', function (done) {
var node = {
data: 'aaah the data'
}

node['@context'] = ipld.context.merkleweb

var expected = {
data: 'aaah the data',
'@context': {
mlink: 'http://merkle-link'
}
}

expect(node).to.deep.equal(expected)
done()
})

it('expand', function (done) {
var node = {
data: 'aaah the data',
mlink: 'GIMETHEHASSSSSH'
}

node['@context'] = ipld.context.merkleweb

var expected = {
data: 'aaah the data',
'http://merkle-link': 'GIMETHEHASSSSSH'
}

expect(ipld.expand(node)).to.deep.equal(expected)
done()
})

it('expand with buffer as val', function (done) {
var node = {
data: 'aaah the data',
mlink: new Buffer('GIVEMETHEHASH')
}

node['@context'] = ipld.context.merkleweb

var expected = {
data: 'aaah the data',
'http://merkle-link': new Buffer('GIVEMETHEHASH')
}

expect(ipld.expand(node)).to.deep.equal(expected)
done()
})

it('expand nested', function (done) {
var node = {
data: 'aaah the data',
foo: {
mlink: 'GIMETHEHASSSSSH'
}
}

node['@context'] = ipld.context.merkleweb

var expected = {
data: 'aaah the data',
foo: {
'http://merkle-link': 'GIMETHEHASSSSSH'
}
}

expect(ipld.expand(node)).to.deep.equal(expected)
done()
})

it('marshel and unmarshal', function (done) {
var node = {
data: 'aaah the data',
mlink: 'GIMETHEHASSSSSH'
}

node['@context'] = ipld.context.merkleweb

ipld.unmarshalAsync(ipld.marshal(node), function (err, result) {
expect(err).to.equal(null)
var expected = {
data: 'aaah the data',
'http://merkle-link': 'GIMETHEHASSSSSH'
}

expect(ipld.expand(result[0])).to.deep.equal(expected)
done()
})
})

it('marshel and unmarshal Sync', function (done) {
var node = {
data: 'aaah the data',
mlink: 'GIMETHEHASSSSSH'
}

node['@context'] = ipld.context.merkleweb

var result = ipld.unmarshal(ipld.marshal(node))

var expected = {
data: 'aaah the data',
'http://merkle-link': 'GIMETHEHASSSSSH'
}

expect(ipld.expand(result)).to.deep.equal(expected)
done()
})
})
120 changes: 0 additions & 120 deletions tests/simple-test.js

This file was deleted.