experimenting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-05-21 17:39:26 +03:00
parent af1cf87560
commit 213603690d

View File

@ -317,13 +317,19 @@ module.BaseStore = {
var order = (this.metadata(path) ?? {}).order || [] var order = (this.metadata(path) ?? {}).order || []
// NOTE: we are matching full paths only here so leading and // NOTE: we are matching full paths only here so leading and
// trainling '/' are optional... // trainling '/' are optional...
// NOTE: we ensure that we match full names and always split
// at '/' only...
var pattern = new RegExp(`^\\/?${ var pattern = new RegExp(`^\\/?${
module.path.normalize(path, 'string') module.path.normalize(path, 'string')
.replace(/^\/|\/$/g, '') .replace(/^\/|\/$/g, '')
.replace(/\//g, '\\/') .replace(/\//g, '\\/')
.replace(/\*\*/g, '.+') .replace(/\*\*/g, '.+')
.replace(/\*/g, '[^\\/]+') }`) .replace(/\*/g, '[^\\/]+')
}(?=[\\\\\/]|$)`)
return [...this.paths() return [...this.paths()
// NOTE: we are not using .filter(..) here as wee
// need to keep parts of the path only and not
// return the whole thing...
.reduce(function(res, p){ .reduce(function(res, p){
// skip metadata paths... // skip metadata paths...
if(p.includes('*')){ if(p.includes('*')){
@ -335,7 +341,60 @@ module.BaseStore = {
&& res.add(m[0]) && res.add(m[0])
return res }, new Set())] return res }, new Set())]
.sortAs(order) } .sortAs(order) }
// search... // direct...
for(var p of module.path.paths(path)){
p = this.exists(p)
if(p){
return p } } },
// XXX like .match(..) when paths end in '/' but when paths end with
// a non-pattern then match the basedir and then add the basename
// to each resulting path...
// XXX EXPERIMENTAL
match2: function(path, strict=false){
// pattern match * / **
if(path.includes('*')
|| path.includes('**')){
path = module.path.split(path)
// match basedir and addon basename to the result...
var name = path[path.length-1]
if(name
&& name != ''
&& !name.includes('*')){
path.pop()
path.push('')
return this.match2(path.join('/'), strict)
.map(function(p){
return module.path.join(p, name) }) }
var order = (this.metadata(path) ?? {}).order || []
// NOTE: we are matching full paths only here so leading and
// trainling '/' are optional...
// NOTE: we ensure that we match full names and always split
// at '/' only...
var pattern = new RegExp(`^\\/?${
module.path.normalize(path, 'string')
.replace(/^\/|\/$/g, '')
.replace(/\//g, '\\/')
.replace(/\*\*/g, '.+')
.replace(/\*/g, '[^\\/]+')
}(?=[\\\\\/]|$)`)
return [...this.paths()
// NOTE: we are not using .filter(..) here as wee
// need to keep parts of the path only and not
// return the whole thing...
.reduce(function(res, p){
// skip metadata paths...
if(p.includes('*')){
return res }
var m = p.match(pattern)
m
&& (!strict
|| m[0] == p)
&& res.add(m[0])
return res }, new Set())]
.sortAs(order) }
// direct...
for(var p of module.path.paths(path)){ for(var p of module.path.paths(path)){
p = this.exists(p) p = this.exists(p)
if(p){ if(p){