Skip to content

Commit ed5c96c

Browse files
Fix arrayLike (#37)
* Fix arrayLike * Update src/BigNumber.ts Co-authored-by: Marc Rousavy <me@mrousavy.com>
1 parent 045b529 commit ed5c96c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/BigNumber.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ export class BN {
225225
return native.toArray.call(this.internalBigNum, endian === 'le', len || -1);
226226
}
227227

228-
// TODO(MARC ts magician )
228+
// TODO(MARC ts magician - please check )
229229
toArrayLike<T extends (len: number) => { buffer: ArrayBuffer }>(
230230
arrayLike: T,
231-
endian: 'le' | 'be',
232-
len: number
231+
endian?: 'le' | 'be',
232+
len?: number
233233
) {
234234
if (typeof arrayLike !== 'function') {
235235
console.log('toArrayLike exptects constructor');
@@ -240,7 +240,9 @@ export class BN {
240240
return this.toArray(endian, len);
241241
}
242242

243-
const res = new (arrayLike as any)(len);
243+
const outLen = len != null ? len : this.byteLength();
244+
245+
const res = new (arrayLike as any)(outLen);
244246

245247
native.toArrayLike.call(
246248
this.internalBigNum,

0 commit comments

Comments
 (0)