Son CV dans un terminal web en Javascript!
https://terminal-cv.gregandev.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
// @flow strict-local
|
|
import type {FilePath} from '@parcel/types';
|
|
import path from 'path';
|
|
|
|
const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
|
|
const SEPARATOR_REGEX = /[\\]+/g;
|
|
|
|
export function isAbsolute(filepath: string): boolean {
|
|
return ABSOLUTE_PATH_REGEX.test(filepath);
|
|
}
|
|
|
|
export function normalizeSeparators(filePath: FilePath): FilePath {
|
|
return filePath.replace(SEPARATOR_REGEX, '/');
|
|
}
|
|
|
|
export type PathOptions = {
|
|
noLeadingDotSlash?: boolean,
|
|
...
|
|
};
|
|
|
|
export function normalizePath(
|
|
filePath: FilePath,
|
|
leadingDotSlash: boolean = true,
|
|
): FilePath {
|
|
if (
|
|
leadingDotSlash &&
|
|
(filePath[0] !== '.' ||
|
|
(filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\')) &&
|
|
!path.isAbsolute(filePath)
|
|
) {
|
|
return normalizeSeparators('./' + filePath);
|
|
} else {
|
|
return normalizeSeparators(filePath);
|
|
}
|
|
}
|
|
|
|
export function relativePath(
|
|
from: string,
|
|
to: string,
|
|
leadingDotSlash: boolean = true,
|
|
): FilePath {
|
|
// Fast path
|
|
if (to.startsWith(from + '/')) {
|
|
return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
|
|
}
|
|
|
|
return normalizePath(path.relative(from, to), leadingDotSlash);
|
|
}
|
|
|