You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
convergencelabs_monaco-coll.../src/ts/Validation.ts

39 lines
1.1 KiB

/**
* A helper class to aid in input validation.
*
* @internal
*/
export class Validation {
public static assertString(val: any, name: string): void {
if (typeof val !== "string") {
throw new Error(`${name} must be a string but was: ${val}`);
}
}
public static assertNumber(val: any, name: string): void {
if (typeof val !== "number") {
throw new Error(`${name} must be a number but was: ${val}`);
}
}
public static assertDefined(val: any, name: string): void {
if (val === undefined || val === null) {
throw new Error(`${name} must be a defined but was: ${val}`);
}
}
public static assertFunction(val: any, name: string): void {
if (typeof val !== "function") {
throw new Error(`${name} must be a function but was: ${typeof val}`);
}
}
public static assertPosition(val: any, name: string): void {
Validation.assertDefined(val, name);
if (typeof val.lineNumber !== "number" || typeof val.column !== "number") {
throw new Error(`${name} must be an Object like {lineNumber: number, column: number}: ${JSON.stringify(val)}`);
}
}
}