echogarden
Version:
An easy-to-use speech toolset. Includes tools for synthesis, recognition, alignment, speech translation, language detection, source separation and more.
57 lines • 1.77 kB
JavaScript
import * as NodePath from 'node:path';
import { fileURLToPath } from 'node:url';
import * as os from 'node:os';
export function getModuleRootDir() {
const currentScriptDir = getDirName(fileURLToPath(import.meta.url));
return resolvePath(currentScriptDir, '..', '..');
}
export function resolveToModuleRootDir(relativePath) {
return resolvePath(getModuleRootDir(), relativePath);
}
export function getLowercaseFileExtension(filename) {
const fileExtensionIndex = filename.lastIndexOf('.');
if (fileExtensionIndex == -1) {
return '';
}
return filename.substring(fileExtensionIndex + 1).toLowerCase();
}
export function getAppTempDir(appName) {
let tempDir;
const platform = process.platform;
const homeDir = os.homedir();
if (platform == 'win32') {
tempDir = joinPath(homeDir, 'AppData', 'Local', 'Temp', appName);
}
else if (platform == 'darwin') {
tempDir = joinPath(homeDir, 'Library', 'Caches', appName);
}
else if (platform == 'linux') {
tempDir = joinPath(homeDir, '.cache', appName);
}
else {
throw new Error(`Unsupport platform ${platform}`);
}
return tempDir;
}
export function joinPath(...paths) {
return NodePath.join(...paths);
}
export function resolvePath(...paths) {
return NodePath.resolve(...paths);
}
export function normalizePath(path) {
return NodePath.normalize(path);
}
export function getBaseName(path) {
return NodePath.basename(path);
}
export function getDirName(path) {
return NodePath.dirname(path);
}
export function getFileNameWithoutExtension(filePath) {
return NodePath.parse(filePath).name;
}
export function parsePath(path) {
return NodePath.parse(path);
}
//# sourceMappingURL=PathUtilities.js.map