-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (41 loc) · 898 Bytes
/
index.js
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
'use strict'
const p = require('path')
const packageDir = require('pkg-dir')
/**
* Returns a normalized path.
*
* @param {string} path - The path to be normalized.
*
* @returns {string} The normalized path.
*/
function path (path) {
return p.normalize(path)
}
/**
* @private
* @type {string|null}
*/
let _rootPath = null
/**
* Returns a normalized path relative to the project's root directory.
*
* @param {string} [path] - The path to use to normalize.
* If none given, only the project's root directory will be used.
*
* @returns {string} The normalized path relative to the project's root directory.
*/
function root (path = '') {
if (_rootPath === null) {
_rootPath = packageDir.sync(__dirname)
}
return p.normalize(`${_rootPath}/${path}`)
}
/**
* Files module.
*
* @module dev-toolbox/files
*/
module.exports = {
path,
root
}