Skip to content

Commit 982a4b4

Browse files
committed
Add checks to ensure bytes arguments provided to ByteUnitObject adaptors are valid
1 parent 40caaeb commit 982a4b4

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,22 +183,26 @@ class ByteUnitObject {
183183
}
184184

185185
add(bytes) {
186-
this.checkInternalByteVal(bytes);
186+
if (!isParsable(bytes)) throw Error('<bytes> argument must be a finite value');
187+
this.checkInternalByteVal();
187188
return new ByteUnitObject(this.bytes + parseByteOrByteArray(bytes).reduce((a, v) => a + v, 0));
188189
}
189190

190191
subtract(bytes) {
191-
this.checkInternalByteVal(bytes);
192+
if (!isParsable(bytes)) throw Error('<bytes> argument must be a finite value');
193+
this.checkInternalByteVal();
192194
return new ByteUnitObject(this.bytes - parseByteOrByteArray(bytes).reduce((a, v) => a + v, 0));
193195
}
194196

195197
multiply(bytes) {
196-
this.checkInternalByteVal(bytes);
198+
if (!isParsable(bytes)) throw Error('<bytes> argument must be a finite value');
199+
this.checkInternalByteVal();
197200
return new ByteUnitObject(this.bytes * parseByteOrByteArray(bytes).reduce((a, v) => a * v, 1));
198201
}
199202

200203
divide(bytes) {
201-
this.checkInternalByteVal(bytes);
204+
if (!isParsable(bytes)) throw Error('<bytes> argument must be a finite value');
205+
this.checkInternalByteVal();
202206
return new ByteUnitObject(this.bytes / parseByteOrByteArray(bytes).reduce((a, v) => a * v, 1));
203207
}
204208

0 commit comments

Comments
 (0)