isAddress/validateAddress functions (#946)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
import { base64Validate } from './validate';
|
||||
|
||||
export function isBase64 (value?: string | null): boolean {
|
||||
export function isBase64 (value?: string | null): value is string {
|
||||
try {
|
||||
return base64Validate(value);
|
||||
} catch (error) {
|
||||
|
||||
@@ -7,9 +7,9 @@ import { assert } from '@polkadot/util';
|
||||
* @name base64Validate
|
||||
* @summary Validates a base64 value.
|
||||
* @description
|
||||
* Validates the the supplied value is valid base64
|
||||
* Validates that the supplied value is valid base64
|
||||
*/
|
||||
export function base64Validate (value?: string | null): true {
|
||||
export function base64Validate (value?: string | null): value is string {
|
||||
assert(value, 'Expected non-null, non-empty base64 input');
|
||||
assert(/^(?:[A-Za-z0-9+/]{2}[A-Za-z0-9+/]{2})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value), 'Invalid base64 encoding');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user