Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2240c93db5 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.27.13",
|
||||
"version": "0.27.14",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -119,25 +119,13 @@ export class PathEvent {
|
||||
if(!method) method = '*';
|
||||
|
||||
// Handle special cases
|
||||
if(p === '' || p === undefined) {
|
||||
// Empty string matches nothing
|
||||
this.module = '';
|
||||
this.path = '';
|
||||
this.fullPath = '';
|
||||
this.name = '';
|
||||
this.methods = new ASet<Method>(['n']);
|
||||
this.hasGlob = false;
|
||||
PathEvent.pathEventCache.set(e, this);
|
||||
return;
|
||||
}
|
||||
|
||||
if(p === '*') {
|
||||
// Wildcard means any path any event
|
||||
if(p === '' || p === undefined || p === '*') {
|
||||
// Empty string with methods (e.g., ":*") matches the root level/everything
|
||||
this.module = '';
|
||||
this.path = '';
|
||||
this.fullPath = '**';
|
||||
this.name = '';
|
||||
this.methods = new ASet<Method>(['*']);
|
||||
this.methods = new ASet<Method>(p === '*' ? ['*'] : <any>method.split(''));
|
||||
this.hasGlob = true;
|
||||
PathEvent.pathEventCache.set(e, this);
|
||||
return;
|
||||
@@ -303,7 +291,8 @@ export class PathEvent {
|
||||
private static matches(pattern: PathEvent, target: PathEvent): boolean {
|
||||
// Handle special cases
|
||||
if(pattern.fullPath === '' || target.fullPath === '') return false;
|
||||
if (pattern.fullPath === '*' || target.fullPath === '*') return pattern.methods.has('*') || target.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
||||
if(pattern.fullPath === '**') return pattern.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
||||
if(target.fullPath === '**') return pattern.methods.has('*') || target.methods.has('*') || pattern.methods.intersection(target.methods).length > 0;
|
||||
|
||||
// Check methods
|
||||
const methodsMatch = pattern.all || target.all || pattern.methods.intersection(target.methods).length > 0;
|
||||
|
||||
@@ -48,10 +48,9 @@ describe('Path Events', () => {
|
||||
expect(pe.hasAll('module:c', 'some/path:ud')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('parses empty string as none', () => {
|
||||
it('parses empty string as wildcard', () => {
|
||||
const pe = new PathEvent('');
|
||||
expect(pe.none).toBe(true);
|
||||
expect(pe.fullPath).toBe('');
|
||||
expect(pe.has('any/path:c')).toBe(true);
|
||||
});
|
||||
|
||||
it('parses none method', () => {
|
||||
|
||||
Reference in New Issue
Block a user