more bug fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-19 04:07:11 +03:00
parent 3c0e6e0147
commit 1d9e0e0425

View File

@ -92,6 +92,8 @@ module.path = {
'array' 'array'
: 'string') : 'string')
: format : format
var root = path[0] == ''
|| path[0] == '/'
path = (path instanceof Array ? path = (path instanceof Array ?
path path
// NOTE: this will also trim the path elements... // NOTE: this will also trim the path elements...
@ -116,8 +118,10 @@ module.path = {
: res.push(e) : res.push(e)
return res }, []) return res }, [])
return format == 'string' ? return format == 'string' ?
// special case: [''] -> '/' // special case: root -> keep '/'
((path.length == 1 && path[0] == '') ? ((root
&& path.length == 1
&& path[0] == '') ?
('/'+ path.join('/')) ('/'+ path.join('/'))
: path.join('/')) : path.join('/'))
: path }, : path },
@ -127,14 +131,17 @@ module.path = {
'array' 'array'
: 'string') : 'string')
: format : format
path = this.normalize(path, 'array')
// root path... // root path...
if(path[0] == ''){ if(path[0] == '' || path[0] == '/'){
return format == 'string' ? return this.normalize(path, format) }
path.join('/') // unify parent/path types...
: path } parent = parent instanceof Array ?
parent = this.normalize(parent, 'array') parent
return this.normalize(parent.concat(path), format) }, : parent.split(/\s*[\\\/]+\s*/)
path = path instanceof Array ?
path
: path.split(/\s*[\\\/]+\s*/)
return this.normalize([...parent, ...path], format) },
paths: function*(path='/'){ paths: function*(path='/'){
path = this.normalize(path, 'array') path = this.normalize(path, 'array')