Adjust encoder/decoder fallbacks (#750)

* Adjust encoder/decoder fallbacks

* Dep-dup is functions

* Complexity cleanups
This commit is contained in:
Jaco Greeff
2020-11-08 11:20:22 +01:00
committed by GitHub
parent e1aa096cef
commit c67c1966d7
18 changed files with 118 additions and 78 deletions
+6 -2
View File
@@ -3,10 +3,14 @@
import validate from './validate';
export default function isBase32 (value?: string | null): boolean {
export function testValidator (validate: (value?: string | null, ipfsCompat?: boolean) => boolean, value?: string | null, ipfsCompat?: boolean): boolean {
try {
return validate(value);
return validate(value, ipfsCompat);
} catch (error) {
return false;
}
}
export default function isBase32 (value?: string | null, ipfsCompat?: boolean): boolean {
return testValidator(validate, value, ipfsCompat);
}
+2 -5
View File
@@ -1,12 +1,9 @@
// Copyright 2017-2020 @polkadot/util-crypto authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { testValidator } from '../base32/is';
import validate from './validate';
export default function isBase58 (value?: string | null, ipfsCompat?: boolean): boolean {
try {
return validate(value, ipfsCompat);
} catch (error) {
return false;
}
return testValidator(validate, value, ipfsCompat);
}