Add token creation dialog
This commit is contained in:
8
matrixgw_frontend/src/utils/DateUtils.ts
Normal file
8
matrixgw_frontend/src/utils/DateUtils.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Get UNIX time
|
||||
*
|
||||
* @returns Number of seconds since Epoch
|
||||
*/
|
||||
export function time(): number {
|
||||
return Math.floor(new Date().getTime() / 1000);
|
||||
}
|
||||
52
matrixgw_frontend/src/utils/FormUtils.ts
Normal file
52
matrixgw_frontend/src/utils/FormUtils.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import isCidr from "is-cidr";
|
||||
import type { LenConstraint } from "../api/ServerApi";
|
||||
|
||||
/**
|
||||
* Check if a constraint was respected or not
|
||||
*
|
||||
* @returns An error message appropriate for the constraint
|
||||
* violation, if any, or undefined otherwise
|
||||
*/
|
||||
export function checkConstraint(
|
||||
constraint: LenConstraint,
|
||||
value: string | undefined
|
||||
): string | undefined {
|
||||
value = value ?? "";
|
||||
if (value.length < constraint.min)
|
||||
return `Please specify at least ${constraint.min} characters!`;
|
||||
|
||||
if (value.length > constraint.max)
|
||||
return `Please specify at least ${constraint.min} characters!`;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a number constraint was respected or not
|
||||
*
|
||||
* @returns An error message appropriate for the constraint
|
||||
* violation, if any, or undefined otherwise
|
||||
*/
|
||||
export function checkNumberConstraint(
|
||||
constraint: LenConstraint,
|
||||
value: number
|
||||
): string | undefined {
|
||||
value = value ?? "";
|
||||
if (value < constraint.min)
|
||||
return `Value is below accepted minimum (${constraint.min})!`;
|
||||
|
||||
if (value > constraint.max)
|
||||
return `Value is above accepted maximum (${constraint.min})!`;
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given IP network address is valid or not
|
||||
*
|
||||
* @param ip The IP network to check
|
||||
* @returns true if the address is valid, false otherwise
|
||||
*/
|
||||
export function isIPNetworkValid(ip: string): boolean {
|
||||
return isCidr(ip) !== 0;
|
||||
}
|
||||
Reference in New Issue
Block a user