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:
@@ -16,5 +16,5 @@
|
||||
* ```
|
||||
*/
|
||||
export function isBigInt (value: unknown): value is bigint {
|
||||
return typeof value === 'bigint';
|
||||
return typeof value === 'bigint' || value instanceof BigInt;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user