Additional bigint utilities (#1194)

* Additional bigint utilities

* Adjust tests

* biTo{Hex, U8a}

* Adjust

* Ordering

* biSqrt

* Fix toU8a

* Extensible BigInt

* Class TS issues....

* Move type def to types

* Update packages/util/src/bi/sqrt.spec.ts

* max/min

* min/max tests
This commit is contained in:
Jaco
2021-11-16 20:27:19 +02:00
committed by GitHub
parent 87afdb1d86
commit fa5b5bca7e
24 changed files with 703 additions and 18 deletions
+1 -1
View File
@@ -16,5 +16,5 @@
* ```
*/
export function isBigInt (value: unknown): value is bigint {
return typeof value === 'bigint';
return typeof value === 'bigint' || value instanceof BigInt;
}
+1
View File
@@ -24,6 +24,7 @@ export { isObject } from './object';
export { isObservable } from './observable';
export { isString } from './string';
export { isTestChain } from './testChain';
export { isToBigInt } from './toBigInt';
export { isToBn } from './toBn';
export { isU8a } from './u8a';
export { isUndefined } from './undefined';
+20
View File
@@ -0,0 +1,20 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { isToBigInt } from '.';
describe('isToBigInt', (): void => {
it('is false on no value', (): void => {
expect(isToBigInt()).toEqual(false);
});
it('is false on non-compact value', (): void => {
expect(isToBigInt(123)).toEqual(false);
});
it('is true when compact-like signature is found', (): void => {
expect(isToBigInt({
toBigInt: () => BigInt(1)
})).toEqual(true);
});
});
+10
View File
@@ -0,0 +1,10 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ToBigInt } from '../types';
import { isFunction } from './function';
export function isToBigInt (value?: unknown): value is ToBigInt {
return !!value && isFunction((value as ToBigInt).toBigInt);
}