* Clean path * @param {String} _path - Path to clean * @return {String} Cleaned path
(_path = '')
| 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 |
no outgoing calls
no test coverage detected