export const isNumeric = (value: string | number): boolean => { return ((value != null) && (value !== '') && !isNaN(Number(value.toString()))) } export const contains = (source: string, search: string | string[], caseInsensitive: boolean = false): boolean => { if (caseInsensitive) { source = source.toLowerCase() if (Array.isArray(search)) { search = search.map(s => s.toLowerCase()) } else { search = search.toLowerCase() } } if (Array.isArray(search)) { for (const s of search) { if (source.indexOf(s) >= 0) return true } return false } return source.indexOf(search) >= 0 } export const startsWith = (source: string, search: string): boolean => { return source.substr(0, search.length) === search } export const remove = (source: string, search: string): string => { return source.replace(search, "") } export const trimEnd = (source: string, search: string): string => { return source.endsWith(search) ? source.slice(0, -search.length) : source } export const repeat = (source: string, count: number): string => { let value = '' for (let i = 0; i < count; i++) value += source return value } export const count = (source: string, search: string): number => { return source.split(search).length - 1 } export const isGUID = (str: string): boolean => { const GUIDPattern = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; return GUIDPattern.test(str); } export const getFileNameWithoutExtension = (filePath: string | null | undefined): string | null => { if (!filePath) return null const lastSlash = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\')) const fileWithExt = filePath.substring(lastSlash + 1) const lastDot = fileWithExt.lastIndexOf('.') return lastDot > 0 ? fileWithExt.substring(0, lastDot) : fileWithExt }