locatai-ts
Version:
Enterprise-grade AI-powered element locator for Selenium WebDriver - TypeScript implementation
45 lines • 1.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ensureDir = ensureDir;
exports.readJson = readJson;
exports.writeJson = writeJson;
const fs_1 = __importDefault(require("fs"));
/**
* Ensures a directory exists
* @param dirPath Directory path to create
*/
async function ensureDir(dirPath) {
try {
await fs_1.default.promises.mkdir(dirPath, { recursive: true });
}
catch (err) {
// Ignore errors if directory already exists
}
}
/**
* Reads JSON from a file, returns default value if the file doesn't exist
* @param filePath Path to the JSON file
* @param defaultValue Default value to return if file doesn't exist
*/
async function readJson(filePath, defaultValue) {
try {
const content = await fs_1.default.promises.readFile(filePath, 'utf8');
return JSON.parse(content);
}
catch (err) {
// If file doesn't exist or has invalid JSON, return default value
return defaultValue;
}
}
/**
* Writes data as JSON to a file
* @param filePath Path to write the JSON file
* @param data Data to write
*/
async function writeJson(filePath, data) {
await fs_1.default.promises.writeFile(filePath, JSON.stringify(data, null, 2));
}
//# sourceMappingURL=JsonFileHelpers.js.map