Skip to content

Commit ae2214e

Browse files
committed
fix: remove node globals
This PR remove node globals, updates deps and fixes lint problems. related to this ipfs/js-ipfs#2924
1 parent b6bae8b commit ae2214e

File tree

16 files changed

+73
-39
lines changed

16 files changed

+73
-39
lines changed

benchmarks/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
'use strict'
23

34
console.log('PID: %s', process.pid)
@@ -24,7 +25,7 @@ const buffers = vectors
2425

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

27-
let vecLength = vectors.length
28+
const vecLength = vectors.length
2829
let res = []
2930

3031
suite.add(`encode - node-cbor - ${vecLength}`, () => {
@@ -40,9 +41,11 @@ suite.add(`encode - borc - ${vecLength}`, () => {
4041
})
4142

4243
suite.add(`encode - stream - borc - ${vecLength}`, () => {
43-
const enc = new fastCbor.Encoder({ stream (chunk) {
44-
res.push(chunk)
45-
} })
44+
const enc = new fastCbor.Encoder({
45+
stream (chunk) {
46+
res.push(chunk)
47+
}
48+
})
4649
for (let i = 0; i < vecLength; i++) {
4750
enc.write(vectors[i].decoded)
4851
}

bin/cbor2json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/* eslint-disable no-console */
23
'use strict'
34

45
const cbor = require('../src/cbor')

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"email": "dignifiedquire@gmail.com"
3939
},
4040
"devDependencies": {
41-
"aegir": "^18.0.1",
41+
"aegir": "^21.4.5",
4242
"benchmark": "^2.1.0",
4343
"budo": "^11.2.0",
4444
"cbor": "^4.0.0",
@@ -50,10 +50,12 @@
5050
"readmeFilename": "README.md",
5151
"dependencies": {
5252
"bignumber.js": "^9.0.0",
53+
"buffer": "^5.5.0",
5354
"commander": "^2.15.0",
54-
"ieee754": "^1.1.8",
55-
"iso-url": "~0.4.4",
56-
"json-text-sequence": "~0.1.0"
55+
"ieee754": "^1.1.13",
56+
"iso-url": "~0.4.7",
57+
"json-text-sequence": "~0.1.0",
58+
"readable-stream": "^3.6.0"
5759
},
5860
"engines": {
5961
"node": ">=4"

src/commented.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict'
22

3-
const stream = require('stream')
4-
const util = require('util')
5-
const utils = require('./utils')
6-
const Simple = require('./simple')
3+
const { Buffer } = require('buffer')
4+
const stream = require('readable-stream')
75
const Decoder = require('./decoder')
86
const constants = require('./constants')
97
const bignumber = require('bignumber.js').BigNumber
@@ -308,7 +306,7 @@ class Commented extends stream.Transform {
308306
this.push(val.toString())
309307
this.push('\n')
310308
} else {
311-
this.push(util.inspect(val))
309+
this.push(JSON.stringify(val))
312310
this.push('\n')
313311
}
314312

src/decoder.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const ieee754 = require('ieee754')
45
const Bignumber = require('bignumber.js').BigNumber
56

@@ -55,6 +56,7 @@ class Decoder {
5556

5657
// Initialize asm based parser
5758
this.parser = parser(global, {
59+
// eslint-disable-next-line no-console
5860
log: console.log.bind(console),
5961
pushInt: this.pushInt.bind(this),
6062
pushInt32: this.pushInt32.bind(this),
@@ -327,7 +329,7 @@ class Decoder {
327329
}
328330

329331
createUndefined () {
330-
return void 0
332+
return undefined
331333
}
332334

333335
createInfinity () {

src/diagnose.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Decoder = require('./decoder')
45
const utils = require('./utils')
56

src/encoder.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const { URL } = require('iso-url')
45
const Bignumber = require('bignumber.js').BigNumber
56

@@ -254,7 +255,7 @@ class Encoder {
254255
if (!gen._pushInt(obj.size, MT.ARRAY)) {
255256
return false
256257
}
257-
for (let x of obj) {
258+
for (const x of obj) {
258259
if (!gen.pushAny(x)) {
259260
return false
260261
}
@@ -425,7 +426,7 @@ class Encoder {
425426
case SYMS.NULL:
426427
return this._pushObject(null)
427428
case SYMS.UNDEFINED:
428-
return this._pushUndefined(void 0)
429+
return this._pushUndefined(undefined)
429430
// TODO: Add pluggable support for other symbols
430431
default:
431432
throw new Error('Unknown symbol: ' + obj.toString())

src/simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class Simple {
8989
}
9090
case SIMPLE.UNDEFINED:
9191
if (hasParent) {
92-
return void 0
92+
return undefined
9393
} else {
9494
return SYMS.UNDEFINED
9595
}

src/tagged.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Tagged {
5858
*/
5959
convert (converters) {
6060
var er, f
61-
f = converters != null ? converters[this.tag] : void 0
61+
f = converters != null ? converters[this.tag] : undefined
6262
if (typeof f !== 'function') {
6363
f = Tagged['_tag' + this.tag]
6464
if (typeof f !== 'function') {

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const { Buffer } = require('buffer')
34
const Bignumber = require('bignumber.js').BigNumber
45

56
const constants = require('./constants')

0 commit comments

Comments
 (0)