mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-08 01:48:32 +00:00
Make tab width 2 spaces (#445)
This commit is contained in:
@@ -2,22 +2,22 @@ export const posix = { sep: '/' };
|
||||
|
||||
// TODO: poor man's `path.join(path, '..')` in the browser.
|
||||
export function parentPosix(path: string): string {
|
||||
const segments = path.split(posix.sep) || [];
|
||||
segments.pop();
|
||||
let modified = segments.join(posix.sep);
|
||||
if (path.charAt(path.length - 1) === posix.sep) {
|
||||
modified += posix.sep;
|
||||
}
|
||||
return modified;
|
||||
const segments = path.split(posix.sep) || [];
|
||||
segments.pop();
|
||||
let modified = segments.join(posix.sep);
|
||||
if (path.charAt(path.length - 1) === posix.sep) {
|
||||
modified += posix.sep;
|
||||
}
|
||||
return modified;
|
||||
}
|
||||
|
||||
export function basename(path: string): string {
|
||||
const segments = path.split(posix.sep) || [];
|
||||
return segments.pop()!;
|
||||
const segments = path.split(posix.sep) || [];
|
||||
return segments.pop()!;
|
||||
}
|
||||
|
||||
export function posixSegments(posixPath: string): string[] {
|
||||
return posixPath.split(posix.sep).filter((segment) => !!segment);
|
||||
return posixPath.split(posix.sep).filter((segment) => !!segment);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,28 +32,28 @@ export function posixSegments(posixPath: string): string[] {
|
||||
* ```
|
||||
*/
|
||||
export function splitSketchPath(
|
||||
raw: string,
|
||||
sep = '/sketches_v2/'
|
||||
raw: string,
|
||||
sep = '/sketches_v2/'
|
||||
): [string, string] {
|
||||
if (!sep) {
|
||||
throw new Error('Invalid separator. Cannot be zero length.');
|
||||
}
|
||||
const index = raw.indexOf(sep);
|
||||
if (index === -1) {
|
||||
throw new Error(`Invalid path pattern. Raw path was '${raw}'.`);
|
||||
}
|
||||
const createRoot = raw.substring(0, index + sep.length - 1); // TODO: validate the `createRoot` format.
|
||||
const posixPath = raw.substr(index + sep.length - 1);
|
||||
if (!posixPath) {
|
||||
throw new Error(`Could not extract POSIX path from '${raw}'.`);
|
||||
}
|
||||
return [createRoot, posixPath];
|
||||
if (!sep) {
|
||||
throw new Error('Invalid separator. Cannot be zero length.');
|
||||
}
|
||||
const index = raw.indexOf(sep);
|
||||
if (index === -1) {
|
||||
throw new Error(`Invalid path pattern. Raw path was '${raw}'.`);
|
||||
}
|
||||
const createRoot = raw.substring(0, index + sep.length - 1); // TODO: validate the `createRoot` format.
|
||||
const posixPath = raw.substr(index + sep.length - 1);
|
||||
if (!posixPath) {
|
||||
throw new Error(`Could not extract POSIX path from '${raw}'.`);
|
||||
}
|
||||
return [createRoot, posixPath];
|
||||
}
|
||||
|
||||
export function toPosixPath(raw: string): string {
|
||||
if (raw === posix.sep) {
|
||||
return posix.sep; // Handles the root resource case.
|
||||
}
|
||||
const [, posixPath] = splitSketchPath(raw);
|
||||
return posixPath;
|
||||
if (raw === posix.sep) {
|
||||
return posix.sep; // Handles the root resource case.
|
||||
}
|
||||
const [, posixPath] = splitSketchPath(raw);
|
||||
return posixPath;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user