Helpers for 256/512 hashing (#1303)
* Helpers for 256/512 hashing * Adjust u8aToU8a (u8a-only check earlier) * Fix export * Simplify * revert
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
|
||||
export function isOn <T> (fn: keyof T): (value?: unknown) => value is T {
|
||||
return (value?: unknown): value is T =>
|
||||
!!value && (isObject(value) || isFunction(value)) && isFunction((value as T)[fn]);
|
||||
}
|
||||
@@ -1,12 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isObject } from './object';
|
||||
import type { Observable } from '../types';
|
||||
|
||||
interface Observable {
|
||||
next: (...params: unknown[]) => unknown;
|
||||
}
|
||||
import { isOn } from './helpers';
|
||||
|
||||
/**
|
||||
* @name isBObservable
|
||||
@@ -22,9 +19,4 @@ interface Observable {
|
||||
* console.log('isObservable', isObservable(...));
|
||||
* ```
|
||||
*/
|
||||
export function isObservable (value: unknown): value is Observable {
|
||||
return (
|
||||
isObject(value) &&
|
||||
isFunction((value as Observable).next)
|
||||
);
|
||||
}
|
||||
export const isObservable = isOn<Observable>('next');
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
import type { ToBigInt } from '../types';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isOn } from './helpers';
|
||||
|
||||
export function isToBigInt (value?: unknown): value is ToBigInt {
|
||||
return !!value && isFunction((value as ToBigInt).toBigInt);
|
||||
}
|
||||
export const isToBigInt = isOn<ToBigInt>('toBigInt');
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
import type { ToBn } from '../types';
|
||||
|
||||
import { isFunction } from './function';
|
||||
import { isOn } from './helpers';
|
||||
|
||||
export function isToBn (value?: unknown): value is ToBn {
|
||||
return !!value && isFunction((value as ToBn).toBn);
|
||||
}
|
||||
export const isToBn = isOn<ToBn>('toBn');
|
||||
|
||||
Reference in New Issue
Block a user