import path = require('path'); export class Helper { handleException(result: any, helpconfig: any, program: any): boolean { var parsed = JSON.parse(result); var returnvalue = true; if (parsed.exceptionType !== undefined) { if (parsed.exceptionType.length > 0) { returnvalue = false; var jamslogging = require("./jamslogging"); var log = new jamslogging.Logging(program, helpconfig); log.error(parsed.exceptionMessage); } } return returnvalue; } cleanPath(text: string) { if (!this.isNullOrEmpty(text)) { text = path.normalize(text.replace(/\//g, "\\")); } return text; } getHomePath() { return __dirname; } getPath(pathtext: string) { return path.join(this.getHomePath(), pathtext); } // #region Validation functions isNullOrEmpty(text: string): boolean { return text === "" || text === null || text === undefined; } isBoolean(value: any): boolean { return typeof value === "boolean"; } isInteger(value: any): boolean { return value.toString() === parseInt(value, 10).toString(); } isFutureDate(value: any): boolean { return /^(0[1-9]|1[0-2])\/(0[1-9]|1\d|2\d|3[01])\/(19|20)\d{2}$/i.test(value); } validateUrl(url: string): boolean { return /^(http|https):\/\/(.*)/.test(url); } validateFolder(folder: string): boolean { return /^.?(\\|\/)([a-zA-Z0-9\\s_@-^!#$%&+={}\[\]]+(\\{2}|\/)?)/i.test(folder); } validateJSONFileName(filename: string): boolean { return /^.*\.json$/ig.test(filename); } validateLocale(locale: string): boolean { return /^[a-z]{2}(-[a-z]{2})?$/ig.test(locale); } // #endregion }