Skip to content

Commit

Permalink
feat: upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 13, 2018
1 parent 8eb9b1f commit 54a5073
Show file tree
Hide file tree
Showing 15 changed files with 2,613 additions and 1,962 deletions.
8 changes: 4 additions & 4 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const vectors = require('../test/fixtures/vectors.js')
const fastDecoder = new fastCbor.Decoder()

const parsed = vectors
.filter((v) => v.hex && v.decoded)
.map((v) => JSON.stringify(v.decoded))
.filter((v) => v.hex && v.decoded)
.map((v) => JSON.stringify(v.decoded))

const buffers = vectors
.filter((v) => v.hex && v.decoded)
.map((v) => new Buffer(v.hex, 'hex'))
.filter((v) => v.hex && v.decoded)
.map((v) => Buffer.from(v.hex, 'hex'))

const suite = new Benchmark.Suite('cbor')

Expand Down
35 changes: 18 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
"fs": false
},
"scripts": {
"test": "aegir-test",
"test:browser": "aegir-test --env browser",
"test:node": "aegir-test --env node",
"lint": "aegir-lint",
"docs": "aegir-docs",
"release": "aegir-release --docs",
"release-minor": "aegir-release --type minor --docs",
"release-major": "aegir-release --type major --docs",
"build": "aegir-build",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish",
"test": "aegir test --files test/**/*.spec.js",
"test:browser": "aegir test --target browser",
"test:node": "aegir test --target node",
"lint": "aegir lint",
"docs": "aegir docs",
"release": "aegir release --docs",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"build": "aegir build",
"coverage": "aegir coverage",
"coverage-publish": "aegir coverage --upload",
"bench": "node benchmarks/index.js",
"bench-browser": "budo benchmarks/index.js"
},
Expand All @@ -38,18 +38,19 @@
"email": "dignifiedquire@gmail.com"
},
"devDependencies": {
"aegir": "^9.1.2",
"aegir": "^13.0.6",
"benchmark": "^2.1.0",
"budo": "^10.0.4",
"cbor": "^3.0.0",
"chai": "^3.5.0",
"budo": "^11.2.0",
"cbor": "^4.0.0",
"chai": "^4.1.2",
"dirty-chai": "^2.0.1",
"garbage": "0.0.0"
},
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"bignumber.js": "~3.0.0",
"commander": "^2.9",
"bignumber.js": "^6.0.0",
"commander": "^2.15.0",
"ieee754": "^1.1.8",
"json-text-sequence": "^0.1"
},
Expand Down
16 changes: 8 additions & 8 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Decoder {
return
}

p.length --
p.length--

// All children were seen, we can close the current parent
if (p.length === 0) {
Expand All @@ -168,7 +168,7 @@ class Decoder {
// Push any value to the current parent
_push (val, hasChildren) {
const p = this._currentParent
p.values ++
p.values++

switch (p.type) {
case c.PARENT.ARRAY:
Expand Down Expand Up @@ -268,10 +268,10 @@ class Decoder {

createByteStringFromHeap (start, end) {
if (start === end) {
return new Buffer(0)
return Buffer.alloc(0)
}

return new Buffer(this._heap.slice(start, end))
return Buffer.from(this._heap.slice(start, end))
}

createInt (val) {
Expand Down Expand Up @@ -307,7 +307,7 @@ class Decoder {
const g = utils.buildInt32(g1, g2)

if (f > c.MAX_SAFE_HIGH) {
return c.NEG_ONE.sub(new Bignumber(f).times(c.SHIFT32).plus(g))
return c.NEG_ONE.minus(new Bignumber(f).times(c.SHIFT32).plus(g))
}

return -1 - ((f * c.SHIFT32) + g)
Expand Down Expand Up @@ -355,7 +355,7 @@ class Decoder {
}

return (
new Buffer(this._heap.slice(start, end))
Buffer.from(this._heap.slice(start, end))
).toString('utf8')
}

Expand Down Expand Up @@ -593,7 +593,7 @@ class Decoder {
*/
static decode (input, enc) {
if (typeof input === 'string') {
input = new Buffer(input, enc || 'hex')
input = Buffer.from(input, enc || 'hex')
}

const dec = new Decoder({size: input.length})
Expand All @@ -609,7 +609,7 @@ class Decoder {
*/
static decodeAll (input, enc) {
if (typeof input === 'string') {
input = new Buffer(input, enc || 'hex')
input = Buffer.from(input, enc || 'hex')
}

const dec = new Decoder({size: input.length})
Expand Down
10 changes: 5 additions & 5 deletions src/diagnose.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Diagnose extends Decoder {
}

createByteStringFromHeap (start, end) {
const val = (new Buffer(
const val = (Buffer.from(
super.createByteStringFromHeap(start, end)
)).toString('hex')

Expand Down Expand Up @@ -118,7 +118,7 @@ class Diagnose extends Decoder {
createMap (map, len) {
const val = super.createMap(map)
const list = Array.from(val.keys())
.reduce(collectObject(val), '')
.reduce(collectObject(val), '')

if (len === -1) {
return `{_ ${list}}`
Expand All @@ -130,7 +130,7 @@ class Diagnose extends Decoder {
createObject (obj, len) {
const val = super.createObject(obj)
const map = Object.keys(val)
.reduce(collectObject(val), '')
.reduce(collectObject(val), '')

if (len === -1) {
return `{_ ${map}}`
Expand All @@ -150,7 +150,7 @@ class Diagnose extends Decoder {
}

createUtf8StringFromHeap (start, end) {
const val = (new Buffer(
const val = (Buffer.from(
super.createUtf8StringFromHeap(start, end)
)).toString('utf8')

Expand All @@ -159,7 +159,7 @@ class Diagnose extends Decoder {

static diagnose (input, enc) {
if (typeof input === 'string') {
input = new Buffer(input, enc || 'hex')
input = Buffer.from(input, enc || 'hex')
}

const dec = new Diagnose()
Expand Down
22 changes: 11 additions & 11 deletions src/encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const UNDEFINED = (constants.MT.SIMPLE_FLOAT << 5) | constants.SIMPLE.UNDEFINED
const NULL = (constants.MT.SIMPLE_FLOAT << 5) | constants.SIMPLE.NULL

const MAXINT_BN = new Bignumber('0x20000000000000')
const BUF_NAN = new Buffer('f97e00', 'hex')
const BUF_INF_NEG = new Buffer('f9fc00', 'hex')
const BUF_INF_POS = new Buffer('f97c00', 'hex')
const BUF_NAN = Buffer.from('f97e00', 'hex')
const BUF_INF_NEG = Buffer.from('f9fc00', 'hex')
const BUF_INF_POS = Buffer.from('f97c00', 'hex')

function toType (obj) {
// [object Type]
Expand Down Expand Up @@ -83,7 +83,7 @@ class Encoder {
this.result[this.offset] = val
this.resultMethod[this.offset] = 0
this.resultLength[this.offset] = val.length
this.offset ++
this.offset++

if (this.streaming) {
this.onData(this.finalize())
Expand All @@ -96,7 +96,7 @@ class Encoder {
this.result[this.offset] = val
this.resultMethod[this.offset] = method
this.resultLength[this.offset] = len
this.offset ++
this.offset++

if (this.streaming) {
this.onData(this.finalize())
Expand Down Expand Up @@ -131,15 +131,15 @@ class Encoder {
}

_pushFloat (obj) {
const b2 = new Buffer(2)
const b2 = Buffer.allocUnsafe(2)

if (utils.writeHalf(b2, obj)) {
if (utils.parseHalf(b2) === obj) {
return this._pushUInt8(HALF) && this.push(b2)
}
}

const b4 = new Buffer(4)
const b4 = Buffer.allocUnsafe(4)
b4.writeFloatBE(obj, 0)
if (b4.readFloatBE(0) === obj) {
return this._pushUInt8(FLOAT) && this.push(b4)
Expand Down Expand Up @@ -272,7 +272,7 @@ class Encoder {
if (str.length % 2) {
str = '0' + str
}
const buf = new Buffer(str, 'hex')
const buf = Buffer.from(str, 'hex')
return this._pushTag(tag) && this._pushBuffer(this, buf)
}

Expand All @@ -292,11 +292,11 @@ class Encoder {
}

const dec = obj.decimalPlaces()
const slide = obj.mul(new Bignumber(10).pow(dec))
const slide = obj.multipliedBy(new Bignumber(10).pow(dec))
if (!gen._pushIntNum(-dec)) {
return false
}
if (slide.abs().lessThan(MAXINT_BN)) {
if (slide.abs().isLessThan(MAXINT_BN)) {
return gen._pushIntNum(slide.toNumber())
} else {
return gen._pushBigint(slide)
Expand Down Expand Up @@ -399,7 +399,7 @@ class Encoder {
case 'Array':
return this._pushArray(this, obj)
case 'Uint8Array':
return this._pushBuffer(this, Buffer.isBuffer(obj) ? obj : new Buffer(obj))
return this._pushBuffer(this, Buffer.isBuffer(obj) ? obj : Buffer.from(obj))
case 'Null':
return this._pushUInt8(NULL)
case 'Undefined':
Expand Down
1 change: 0 additions & 1 deletion src/tagged.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* be an extension point you're not yet expecting.
*/
class Tagged {

/**
* Creates an instance of Tagged.
*
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ exports.writeHalf = function writeHalf (buf, half) {
// } u32;
// u32.f = float_val;

const u32 = new Buffer(4)
const u32 = Buffer.allocUnsafe(4)
u32.writeFloatBE(half, 0)
const u = u32.readUInt32BE(0)

Expand Down
14 changes: 8 additions & 6 deletions test/decoder.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const Bignumber = require('bignumber.js')

const cases = require('./fixtures/cases')
Expand All @@ -17,7 +19,7 @@ describe('Decoder', function () {
continue
}
testGood(
new Buffer(vectors[i].hex, 'hex'),
Buffer.from(vectors[i].hex, 'hex'),
vectors[i].decoded,
vectors[i].hex
)
Expand All @@ -43,7 +45,7 @@ describe('Decoder', function () {
tags: {0: replaceTag, 127: newTag}
})

const input = new Buffer('d87f01c001', 'hex')
const input = Buffer.from('d87f01c001', 'hex')

expect(
d.decodeAll(input)
Expand Down Expand Up @@ -71,7 +73,7 @@ describe('Decoder', function () {
).to.throw()

expect(
() => cbor.decodeFirst(new Buffer(0))
() => cbor.decodeFirst(Buffer.from(0))
).to.throw()
})

Expand Down Expand Up @@ -175,7 +177,7 @@ function testGood (input, expected, desc) {
const res = decoder.decodeFirst(input)

if (Number.isNaN(expected)) {
expect(Number.isNaN(res)).to.be.true
expect(Number.isNaN(res)).to.be.true()
} else if (res instanceof Bignumber) {
expect(res).be.eql(new Bignumber(String(expected)))
} else {
Expand All @@ -191,7 +193,7 @@ function testAll (list) {
if (Number.isNaN(c[0]) ||
// Bignum.js needs num.isNaN()
(c[0] && c[0].isNaN && c[0].isNaN())) {
expect(Number.isNaN(res)).to.be.true
expect(Number.isNaN(res)).to.be.true()
} else {
expect(res).to.be.eql(c[0])
}
Expand Down
6 changes: 4 additions & 2 deletions test/diagnose.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-env mocha */
'use strict'

const expect = require('chai').expect
const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect

const cbor = require('../')
const cases = require('./fixtures/cases')
Expand All @@ -20,7 +22,7 @@ function failAll (list) {
list.forEach(c => {
expect(
() => cbor.diagnose(cases.toBuffer(c))
).to.throw
).to.throw()
})
}

Expand Down
20 changes: 10 additions & 10 deletions test/encoder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('encoder', () => {

class HexBuffer {
constructor (val, enc) {
this.val = new Buffer(val, enc)
this.val = Buffer.from(val, enc)
}

toString (enc) {
Expand Down Expand Up @@ -123,15 +123,15 @@ describe('encoder', () => {
enc.write(123456)

expect(chunks).to.be.eql([
new Buffer('65', 'hex'),
new Buffer('68656c6c6f', 'hex'),
new Buffer('65', 'hex'),
new Buffer('776f726c64', 'hex'),
new Buffer('a1', 'hex'),
new Buffer('6161', 'hex'),
new Buffer('01', 'hex'),
new Buffer('1a', 'hex'),
new Buffer('0001e240', 'hex')
Buffer.from('65', 'hex'),
Buffer.from('68656c6c6f', 'hex'),
Buffer.from('65', 'hex'),
Buffer.from('776f726c64', 'hex'),
Buffer.from('a1', 'hex'),
Buffer.from('6161', 'hex'),
Buffer.from('01', 'hex'),
Buffer.from('1a', 'hex'),
Buffer.from('0001e240', 'hex')
])
})

Expand Down

0 comments on commit 54a5073

Please sign in to comment.