import path from 'path'; import { CBFileSystem } from '../node/file-system'; /** * True only when `value` is a string and is not empty or whitespace-only after trim. * Logically the opposite of `(typeof value !== 'string' || value.trim() === '')`. * @param {unknown} value - Value to check * @returns {value is string} Whether `value` is a usable non-empty string */ export function isNonEmptyString(value: unknown): value is string { return typeof value === 'string' && value.trim() !== ''; } /** * Throws if `filePath` does not exist on the given filesystem. * Message uses the file basename, e.g. `iparams.json not found`. */ export function ensureFileExists(fileSystem: CBFileSystem, filePath: string): void { if (!fileSystem.existsSync(filePath)) { throw new Error(`${path.basename(filePath)} not found`); } }