Skip to content

Commit d63bf3b

Browse files
committed
[eslint] switch to eslint
1 parent 41d738b commit d63bf3b

File tree

5 files changed

+322
-288
lines changed

5 files changed

+322
-288
lines changed

.eslintrc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"globals": {
7+
"Uint8Array": "readonly",
8+
"Uint16Array": "readonly",
9+
},
10+
11+
"rules": {
12+
"array-bracket-newline": "off",
13+
"func-style": ["error", "declaration"],
14+
"no-underscore-dangle": "off",
15+
},
16+
}

index.js

Lines changed: 91 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,109 @@
1-
'use strict'
2-
var Buffer = require('safe-buffer').Buffer
3-
var toBuffer = require('./to-buffer')
4-
var Transform = require('readable-stream').Transform
5-
var inherits = require('inherits')
1+
'use strict';
62

7-
function HashBase (blockSize) {
8-
Transform.call(this)
3+
var Buffer = require('safe-buffer').Buffer;
4+
var toBuffer = require('./to-buffer');
5+
var Transform = require('readable-stream').Transform;
6+
var inherits = require('inherits');
97

10-
this._block = Buffer.allocUnsafe(blockSize)
11-
this._blockSize = blockSize
12-
this._blockOffset = 0
13-
this._length = [0, 0, 0, 0]
8+
function HashBase(blockSize) {
9+
Transform.call(this);
1410

15-
this._finalized = false
11+
this._block = Buffer.allocUnsafe(blockSize);
12+
this._blockSize = blockSize;
13+
this._blockOffset = 0;
14+
this._length = [0, 0, 0, 0];
15+
16+
this._finalized = false;
1617
}
1718

18-
inherits(HashBase, Transform)
19+
inherits(HashBase, Transform);
1920

2021
HashBase.prototype._transform = function (chunk, encoding, callback) {
21-
var error = null
22-
try {
23-
this.update(chunk, encoding)
24-
} catch (err) {
25-
error = err
26-
}
27-
28-
callback(error)
29-
}
22+
var error = null;
23+
try {
24+
this.update(chunk, encoding);
25+
} catch (err) {
26+
error = err;
27+
}
28+
29+
callback(error);
30+
};
3031

3132
HashBase.prototype._flush = function (callback) {
32-
var error = null
33-
try {
34-
this.push(this.digest())
35-
} catch (err) {
36-
error = err
37-
}
38-
39-
callback(error)
40-
}
33+
var error = null;
34+
try {
35+
this.push(this.digest());
36+
} catch (err) {
37+
error = err;
38+
}
39+
40+
callback(error);
41+
};
4142

4243
HashBase.prototype.update = function (data, encoding) {
43-
if (this._finalized) throw new Error('Digest already called')
44-
45-
data = toBuffer(data, encoding) // asserts correct input type
46-
47-
// consume data
48-
var block = this._block
49-
var offset = 0
50-
while (this._blockOffset + data.length - offset >= this._blockSize) {
51-
for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]
52-
this._update()
53-
this._blockOffset = 0
54-
}
55-
while (offset < data.length) block[this._blockOffset++] = data[offset++]
56-
57-
// update length
58-
for (var j = 0, carry = data.length * 8; carry > 0; ++j) {
59-
this._length[j] += carry
60-
carry = (this._length[j] / 0x0100000000) | 0
61-
if (carry > 0) this._length[j] -= 0x0100000000 * carry
62-
}
63-
64-
return this
65-
}
44+
if (this._finalized) {
45+
throw new Error('Digest already called');
46+
}
47+
48+
var dataBuffer = toBuffer(data, encoding); // asserts correct input type
49+
50+
// consume data
51+
var block = this._block;
52+
var offset = 0;
53+
while (this._blockOffset + dataBuffer.length - offset >= this._blockSize) {
54+
for (var i = this._blockOffset; i < this._blockSize;) {
55+
block[i] = dataBuffer[offset];
56+
i += 1;
57+
offset += 1;
58+
}
59+
this._update();
60+
this._blockOffset = 0;
61+
}
62+
while (offset < dataBuffer.length) {
63+
block[this._blockOffset] = dataBuffer[offset];
64+
this._blockOffset += 1;
65+
offset += 1;
66+
}
67+
68+
// update length
69+
for (var j = 0, carry = dataBuffer.length * 8; carry > 0; ++j) {
70+
this._length[j] += carry;
71+
carry = (this._length[j] / 0x0100000000) | 0;
72+
if (carry > 0) {
73+
this._length[j] -= 0x0100000000 * carry;
74+
}
75+
}
76+
77+
return this;
78+
};
6679

6780
HashBase.prototype._update = function () {
68-
throw new Error('_update is not implemented')
69-
}
81+
throw new Error('_update is not implemented');
82+
};
7083

7184
HashBase.prototype.digest = function (encoding) {
72-
if (this._finalized) throw new Error('Digest already called')
73-
this._finalized = true
74-
75-
var digest = this._digest()
76-
if (encoding !== undefined) digest = digest.toString(encoding)
77-
78-
// reset state
79-
this._block.fill(0)
80-
this._blockOffset = 0
81-
for (var i = 0; i < 4; ++i) this._length[i] = 0
82-
83-
return digest
84-
}
85+
if (this._finalized) {
86+
throw new Error('Digest already called');
87+
}
88+
this._finalized = true;
89+
90+
var digest = this._digest();
91+
if (encoding !== undefined) {
92+
digest = digest.toString(encoding);
93+
}
94+
95+
// reset state
96+
this._block.fill(0);
97+
this._blockOffset = 0;
98+
for (var i = 0; i < 4; ++i) {
99+
this._length[i] = 0;
100+
}
101+
102+
return digest;
103+
};
85104

86105
HashBase.prototype._digest = function () {
87-
throw new Error('_digest is not implemented')
88-
}
106+
throw new Error('_digest is not implemented');
107+
};
89108

90-
module.exports = HashBase
109+
module.exports = HashBase;

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"url": "https://github.com/crypto-browserify/hash-base.git"
2222
},
2323
"scripts": {
24-
"lint": "standard",
24+
"lint": "eslint --ext=js,mjs .",
2525
"pretest": "npm run lint",
2626
"test": "npm run tests-only",
27-
"tests-only": "nyc tape 'test/**/*.js'",
28-
"posttest": "npx npm@'>=10.2' audit --production"
27+
"tests-only": "nyc tape \"test/**/*.js\"",
28+
"posttest": "npx npm@\">=10.2\" audit --production"
2929
},
3030
"dependencies": {
3131
"inherits": "^2.0.4",
@@ -34,8 +34,9 @@
3434
"to-buffer": "^1.2.1"
3535
},
3636
"devDependencies": {
37+
"@ljharb/eslint-config": "^21.2.0",
38+
"eslint": "=8.8.0",
3739
"nyc": "^10.3.2",
38-
"standard": "^14.3.3",
3940
"tape": "^5.9.0"
4041
},
4142
"engines": {

0 commit comments

Comments
 (0)