"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getSQLFriendlyEventName = exports.getHumanizedEventName = exports.asciiWords = exports.createDir = exports.getTestSpecFolder = exports.getSchemaFolder = void 0;
const utils_1 = require("@syftdata/common/lib/utils");
const findUp = require("find-up");
const fs = require("fs");
const path = require("path");
const SCHEMA_FOLDER = 'syft';
function getSchemaFolder() {
    let projectRootFolder = '.';
    const projectFilePath = findUp.sync(['package.json']);
    if (projectFilePath !== undefined && projectFilePath !== null) {
        projectRootFolder = path.relative(path.dirname(projectFilePath), projectRootFolder);
    }
    return path.join(projectRootFolder, SCHEMA_FOLDER);
}
exports.getSchemaFolder = getSchemaFolder;
function getTestSpecFolder(schemaFolder) {
    const dir = schemaFolder ?? getSchemaFolder();
    return path.join(dir, 'tests');
}
exports.getTestSpecFolder = getTestSpecFolder;
function createDir(dir) {
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
    }
}
exports.createDir = createDir;
const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
function asciiWords(val) {
    return val.replace(/['\u2019]/g, '').match(reAsciiWord) ?? [];
}
exports.asciiWords = asciiWords;
function getHumanizedEventName(name) {
    return asciiWords(name).map(utils_1.capitalize).join(' ');
}
exports.getHumanizedEventName = getHumanizedEventName;
function getSQLFriendlyEventName(name) {
    return (0, utils_1.lowerize)(name)
        .replace(/([A-Z])/g, '_$1')
        .toLocaleLowerCase();
}
exports.getSQLFriendlyEventName = getSQLFriendlyEventName;
