relative-cjs
Version:
Calculate relative path for commonJs require function
18 lines (14 loc) • 451 B
JavaScript
import relative from 'relative';
function unixify(str) {
return str.replace(/[\\\/]+/g, '/');
}
export default (from, to) => {
const relativePath = relative(from, to);
const unixifiedPath = unixify(relativePath);
if(unixifiedPath.length === 1 && unixifiedPath === '.')
return './.';
else if(unixifiedPath.charAt(0) === '.')
return unixifiedPath;
else
return './' + unixifiedPath;
};