diff --git a/packages/util-crypto/src/base32/helpers.ts b/packages/util-crypto/src/base32/helpers.ts index 7e26ad799..0240f2969 100644 --- a/packages/util-crypto/src/base32/helpers.ts +++ b/packages/util-crypto/src/base32/helpers.ts @@ -27,6 +27,7 @@ type EncodeFn = (value: U8aLike, ipfsCompat?: boolean) => string; type ValidateFn = (value?: unknown, ipfsCompat?: boolean) => value is string; +/** @internal */ export function createDecode ({ coder, ipfs }: Config, validate: ValidateFn): DecodeFn { return (value: string, ipfsCompat?: boolean): Uint8Array => { validate(value, ipfsCompat); @@ -39,6 +40,7 @@ export function createDecode ({ coder, ipfs }: Config, validate: ValidateFn): De }; } +/** @internal */ export function createEncode ({ coder, ipfs }: Config): EncodeFn { return (value: U8aLike, ipfsCompat?: boolean): string => { const out = coder.encode(u8aToU8a(value)); @@ -49,6 +51,7 @@ export function createEncode ({ coder, ipfs }: Config): EncodeFn { }; } +/** @internal */ export function createIs (validate: ValidateFn): ValidateFn { return (value?: unknown, ipfsCompat?: boolean): value is string => { try { @@ -59,6 +62,7 @@ export function createIs (validate: ValidateFn): ValidateFn { }; } +/** @internal */ export function createValidate ({ chars, ipfs, type }: Config): ValidateFn { return (value?: unknown, ipfsCompat?: boolean): value is string => { assert(value && typeof value === 'string', () => `Expected non-null, non-empty ${type} string input`); diff --git a/packages/util-crypto/src/helpers.ts b/packages/util-crypto/src/helpers.ts index a956c171d..4e76dbf36 100644 --- a/packages/util-crypto/src/helpers.ts +++ b/packages/util-crypto/src/helpers.ts @@ -14,16 +14,19 @@ interface DualHash { 512: (u8a: Uint8Array) => Uint8Array; } +/** @internal */ export function createAsHex Uint8Array> (fn: T): (...args: Parameters) => HexString { return (...args: Parameters): HexString => u8aToHex(fn(...args)); } +/** @internal */ export function createBitHasher (bitLength: 256 | 512, fn: (data: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512, onlyJs?: boolean) => Uint8Array): (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean) => Uint8Array { return (data: HexString | Buffer | Uint8Array | string, onlyJs?: boolean): Uint8Array => fn(data, bitLength, onlyJs); } +/** @internal */ export function createDualHasher (wa: DualHash, js: DualHash): (value: HexString | Buffer | Uint8Array | string, bitLength?: 256 | 512, onlyJs?: boolean) => Uint8Array { return (value: HexString | Buffer | Uint8Array | string, bitLength: 256 | 512 = 256, onlyJs?: boolean): Uint8Array => { const u8a = u8aToU8a(value); diff --git a/packages/util/src/array/filter.ts b/packages/util/src/array/filter.ts index 304ec9ea4..cd06e4fa4 100644 --- a/packages/util/src/array/filter.ts +++ b/packages/util/src/array/filter.ts @@ -19,9 +19,8 @@ import { isUndefined } from '../is/undefined'; * arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, ''] * ``` */ -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function arrayFilter (array: T[], allowNulls = true): T[] { - return array.filter((v) => +export function arrayFilter (array: (T | null | undefined)[], allowNulls = true): T[] { + return array.filter((v): v is T => !isUndefined(v) && (allowNulls || !isNull(v)) );