tav-media
Version:
Cross platform media editing framework
31 lines (30 loc) • 777 B
JavaScript
import { uuid } from '../types/tav-object';
/**
* Utils for Paths.
*/
export class Path {
/**
* Get the file name from a path.
* @param path Full path of the file.
* @returns File name of the path.
*/
static getFileName(path) {
const items = path.split('/').filter(item => !!item);
if (items.length)
return items[items.length - 1];
return path;
}
/**
* Get a unique file name from a url.
* @param url The url to parse.
* @returns A local path.
*/
static getLocalFileName(url) {
if (url.indexOf('://') < 0) {
return url;
}
const folder = uuid(12);
const fileName = Path.getFileName(url);
return `${folder}/${fileName}`;
}
}