feeles-ide
Version:
The hackable and serializable IDE to make learning material
29 lines (24 loc) • 792 B
JavaScript
import includes from 'lodash/includes';
export default function separate(fullpath) {
// Filename CAN'T contains spaces.
fullpath = fullpath.replace(/\s/g, '');
// Path separator
fullpath = fullpath.replace(/:/g, '/');
// Path cannot empty
fullpath = fullpath.replace(/^\/+/, '');
var pathLength = fullpath.lastIndexOf('/') + 1;
var path = fullpath.substr(0, pathLength);
var filename = fullpath.substr(pathLength);
var planeLength = includes(filename, '.') ? filename.lastIndexOf('.') : filename.length;
var plane = filename.substr(0, planeLength);
var ext = filename.substr(planeLength);
var name = path + plane + ext;
var moduleName = path + plane;
return {
path: path,
plane: plane,
ext: ext,
name: name,
moduleName: moduleName
};
}