import * as check from "../../../sync/check/string"; import {AssertError} from "../../../sync/error/AssertError"; export function assertString (name : string, mixed : any) : (string)|never { const error = check.checkString(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertMinLength (name : string, mixed : any, min : number) : (string)|never { const error = check.checkMinLength(mixed, min); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, min); } } export function assertMinLengthHandler (min : number) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertMinLength(name, mixed, min); }; } export function assertMaxLength (name : string, mixed : any, max : number) : (string)|never { const error = check.checkMaxLength(mixed, max); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, max); } } export function assertMaxLengthHandler (max : number) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertMaxLength(name, mixed, max); }; } export function assertLength (name : string, mixed : any, args : { min? : number, max? : number }) : (string)|never { const error = check.checkLength(mixed, args); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, args); } } export function assertLengthHandler (args : { min? : number, max? : number }) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertLength(name, mixed, args); }; } export function assertNonEmpty (name : string, mixed : any) : (string)|never { const error = check.checkNonEmpty(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertContains (name : string, mixed : any, x : string) : (string)|never { const error = check.checkContains(mixed, x); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, x); } } export function assertContainsHandler (x : string) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertContains(name, mixed, x); }; } export function assertNoDuplicate (name : string, mixed : any) : (string)|never { const error = check.checkNoDuplicate(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertNotAllWhitespace (name : string, mixed : any) : (string)|never { const error = check.checkNotAllWhitespace(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertNonEmptyAndNotAllWhitespace (name : string, mixed : any) : (string)|never { const error = check.checkNonEmptyAndNotAllWhitespace(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertMatch (name : string, mixed : any, regex : RegExp) : (string)|never { const error = check.checkMatch(mixed, regex); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, regex); } } export function assertMatchHandler (regex : RegExp) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertMatch(name, mixed, regex); }; } export function assertEmail (name : string, mixed : any) : (string)|never { const error = check.checkEmail(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertNotOneOf (name : string, mixed : any, arr : T[]) : (string)|never { const error = check.checkNotOneOf(mixed, arr); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed, arr); } } export function assertNotOneOfHandler (arr : T[]) : (name : string, mixed : any) => (string)|never { return (name : string, mixed : any) : (string)|never => { return assertNotOneOf(name, mixed, arr); }; } export function assertBase64 (name : string, mixed : any) : (string)|never { const error = check.checkBase64(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } } export function assertJson (name : string, mixed : any) : (string)|never { const error = check.checkJson(mixed); if (error === undefined) { return mixed; } else { throw new AssertError(name, error, mixed); } }