This repository was archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpath.js
More file actions
68 lines (59 loc) · 1.38 KB
/
path.js
File metadata and controls
68 lines (59 loc) · 1.38 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* @module Path
*/
import process from '../process.js'
import os from '../os.js'
const isWin32 = os.platform() === 'win32'
export class Path {
/**
* Computes current working directory for a path
* @param {object=} [opts]
* @param {boolean=} [opts.posix] Set to `true` to force POSIX style path
*/
static cwd (opts) {
if (isWin32 && opts?.posix === true) {
const cwd = process.cwd().replace(/\\/g, '/')
return cwd.slice(cwd.indexOf('/'))
}
return process.cwd()
}
static from (input) {
if (typeof input === 'string') {
return new this(this.parse(input))
} else if (input && typeof input === 'object') {
return new this(input)
}
throw new TypeError('Invalid input given to `Path.from()`')
}
/**
* `Path` class constructor.
* @protected
* @param {object=} [opts]
* @param {string=} [opts.root]
* @param {string=} [opts.base]
* @param {string=} [opts.name]
* @param {string=} [opts.dir]
* @param {string=} [opts.ext]
*/
constructor (opts) {
this.root = opts?.root ?? ''
this.base = opts?.base ?? ''
this.name = opts?.name ?? ''
this.dir = opts?.dir ?? ''
this.ext = opts?.ext ?? ''
}
toString () {
const { format } = this.constructor
return format(this)
}
/**
* @TODO
*/
static resolve (...args) {
}
/**
* @TODO
*/
static normalize (path) {
}
}