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:
Jaco
2021-12-09 10:10:51 +02:00
committed by GitHub
parent 000d097de2
commit 7955022ce5
13 changed files with 93 additions and 102 deletions
+10
View File
@@ -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]);
}
+3 -11
View File
@@ -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');
+2 -4
View File
@@ -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');
+2 -4
View File
@@ -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');