-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath.ts
More file actions
26 lines (24 loc) · 801 Bytes
/
path.ts
File metadata and controls
26 lines (24 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import * as path from "node:path";
/**
* Returns true if the argument looks like a filesystem path rather than a
* resource key. Paths contain the OS path separator.
*
* @param arg - The command argument to check
* @returns True if the argument appears to be a path
*/
export const isPathArg = (arg: string): boolean =>
arg.includes(path.sep) || arg.includes("/");
/**
* Resolves a path argument to an absolute path and extracts the resource key
* from the directory basename.
*
* @param arg - The path argument to resolve
* @returns Object with key (basename) and abspath (resolved path)
*/
export const resolvePathArg = (
arg: string,
): { key: string; abspath: string } => {
const abspath = path.resolve(arg);
const key = path.basename(abspath);
return { key, abspath };
};