MCPcopy
hub / github.com/brunosimon/keppler / cleanPath

Method cleanPath

app/src/utils/FileTree.js:26–56  ·  view source on GitHub ↗

* Clean path * @param {String} _path - Path to clean * @return {String} Cleaned path

(_path = '')

Source from the content-addressed store, hash-verified

24 * @return {String} Cleaned path
25 */
26 cleanPath(_path = '')
27 {
28 // Errors
29 if(typeof _path !== 'string')
30 {
31 console.warn('cleanPath: _path should be a string')
32 return false
33 }
34
35 let path = _path
36
37 // Trim
38 path = path.trim()
39
40 // Repeating `/`
41 path = path.replace(/\/+/g, '/')
42
43 // Ending `/`
44 path = path.replace(/\/$/, '')
45
46 // Starting `/`
47 path = path.replace(/^\//, '')
48
49 // Missing starting `./`
50 if(path !== '.' && path.search('./') !== 0)
51 {
52 path = './' + path
53 }
54
55 return path
56 }
57
58 /**
59 * Add a folder

Callers 6

addFolderMethod · 0.95
addFileMethod · 0.95
removeFolderMethod · 0.95
removeFileMethod · 0.95
getFileMethod · 0.95
getFolderMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected