Skip to content

Commit 214d84b

Browse files
committed
Refactor
Inline function called once
1 parent fbc1035 commit 214d84b

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

dist/lib/charSet.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,14 @@ var _ndxDiv = function _ndxDiv(chunk, slice, bytes, entropyPerChar) {
108108
return (bytes[chunk] << lShift * slice & 0xff) >> rShift;
109109
};
110110

111-
var charSet64 = new CharSet("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", _ndx64);
112-
var charSet32 = new CharSet("2346789bdfghjmnpqrtBDFGHJLMNPQRT", _ndx32);
113-
var charSet16 = new CharSet("0123456789abcdef", _ndx16);
114-
var charSet8 = new CharSet("01234567", _ndx8);
115-
var charSet4 = new CharSet("ATCG", _ndx4);
116-
var charSet2 = new CharSet("01", _ndx2);
117-
118-
var isValid = function isValid(charSet) {
119-
return charSet instanceof CharSet;
120-
};
121-
122111
exports.default = {
123-
charSet64: charSet64,
124-
charSet32: charSet32,
125-
charSet16: charSet16,
126-
charSet8: charSet8,
127-
charSet4: charSet4,
128-
charSet2: charSet2,
129-
isValid: isValid
112+
charSet64: new CharSet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_', _ndx64),
113+
charSet32: new CharSet('2346789bdfghjmnpqrtBDFGHJLMNPQRT', _ndx32),
114+
charSet16: new CharSet('0123456789abcdef', _ndx16),
115+
charSet8: new CharSet('01234567', _ndx8),
116+
charSet4: new CharSet('ATCG', _ndx4),
117+
charSet2: new CharSet('01', _ndx2),
118+
isValid: function isValid(charSet) {
119+
return charSet instanceof CharSet;
120+
}
130121
};

dist/lib/entropy.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,14 @@ var _randomBytes = function _randomBytes(entropy, charSet) {
147147
for (var n = 0; n < 6; n++) {
148148
var fByteNum = _endianByteNum[n];
149149
var bByteNum = 6 * rNum + n;
150-
_bufferByte(buffer, bByteNum, fByteNum, byteCount, dataView);
150+
if (bByteNum < byteCount) {
151+
buffer[bByteNum] = dataView.getUint8(fByteNum);
152+
}
151153
}
152154
}
153155
return buffer;
154156
};
155157

156-
var _bufferByte = function _bufferByte(buffer, bByte, nByte, byteCount, dataView) {
157-
if (bByte < byteCount) {
158-
buffer[bByte] = dataView.getUint8(nByte);
159-
}
160-
};
161-
162158
exports.default = {
163159
bits: bits,
164160
bitsWithRiskPower: bitsWithRiskPower,

lib/entropy.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,14 @@ const _randomBytes = (entropy, charSet) => {
117117
for (let n = 0; n < 6; n++) {
118118
let fByteNum = _endianByteNum[n]
119119
let bByteNum = 6*rNum + n
120-
_bufferByte(buffer, bByteNum, fByteNum, byteCount, dataView)
120+
if (bByteNum < byteCount) {
121+
buffer[bByteNum] = dataView.getUint8(fByteNum)
122+
}
121123
}
122124
}
123125
return buffer
124126
}
125127

126-
const _bufferByte = (buffer, bByte, nByte, byteCount, dataView) => {
127-
if (bByte < byteCount) {
128-
buffer[bByte] = dataView.getUint8(nByte)
129-
}
130-
}
131-
132128
export default {
133129
bits,
134130
bitsWithRiskPower,

0 commit comments

Comments
 (0)