Add isCompact (#1061)

This commit is contained in:
Jaco
2021-07-17 08:49:30 +02:00
committed by GitHub
parent f8cc8d07e1
commit bbdf5659df
3 changed files with 29 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BN } from '../bn/bn';
import { isFunction } from './function';
interface Compact<T> {
toBigInt (): bigint;
toBn (): BN;
toNumber (): number;
unwrap (): T;
}
/**
* @name isCompact
* @summary Tests for SCALE-Compact-like object instance.
*/
export function isCompact <T> (value: unknown): value is Compact<T> {
return isFunction((value as Compact<T>).toBigInt) && isFunction((value as Compact<T>).toBn) && isFunction((value as Compact<T>).toNumber) && isFunction((value as Compact<T>).unwrap);
}
+1
View File
@@ -10,6 +10,7 @@ export { isBn } from './bn';
export { isBuffer } from './buffer';
export { isBoolean } from './boolean';
export { isChildClass } from './childClass';
export { isCompact } from './compact';
export { isError } from './error';
export { isFunction } from './function';
export { isHex } from './hex';