diff --git a/package.json b/package.json index f03a72a..f348b13 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.20.12", + "version": "0.21.0", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/aset.ts b/src/aset.ts index d756167..dd89fb0 100644 --- a/src/aset.ts +++ b/src/aset.ts @@ -24,6 +24,7 @@ export class ASet extends Array { */ add(...items: T[]) { items.filter(el => !this.has(el)).forEach(el => this.push(el)); + return this; } /** @@ -35,6 +36,7 @@ export class ASet extends Array { const index = this.indexOf(el); if(index != -1) this.slice(index, 1); }) + return this; } /** diff --git a/src/path-events.ts b/src/path-events.ts index 37eb55b..b8b9ff0 100644 --- a/src/path-events.ts +++ b/src/path-events.ts @@ -69,19 +69,26 @@ export class PathEvent { /** Last sagment of path */ name!: string; /** List of methods */ - methods!: Method[]; + methods!: ASet; + /** All/Wildcard specified */ - all!: boolean; + get all(): boolean { return this.methods.has('*') } + set all(v: boolean) { v ? new ASet(['*']) : this.methods.delete('*'); } /** None specified */ - none!: boolean; + get none(): boolean { return this.methods.has('n') } + set none(v: boolean) { v ? this.methods = new ASet(['n']) : this.methods.delete('n'); } /** Create method specified */ - create!: boolean; + get create(): boolean { return !this.methods.has('n') && (this.methods.has('*') || this.methods.has('c')) } + set create(v: boolean) { v ? this.methods.delete('n').add('c') : this.methods.delete('c'); } /** Read method specified */ - read!: boolean; + get read(): boolean { return !this.methods.has('n') && (this.methods.has('*') || this.methods.has('r')) } + set read(v: boolean) { v ? this.methods.delete('n').add('r') : this.methods.delete('r'); } /** Update method specified */ - update!: boolean; + get update(): boolean { return !this.methods.has('n') && (this.methods.has('*') || this.methods.has('u')) } + set update(v: boolean) { v ? this.methods.delete('n').add('u') : this.methods.delete('u'); } /** Delete method specified */ - delete!: boolean; + get delete(): boolean { return !this.methods.has('n') && (this.methods.has('*') || this.methods.has('d')) } + set delete(v: boolean) { v ? this.methods.delete('n').add('d') : this.methods.delete('d'); } constructor(Event: string | PathEvent) { if(typeof Event == 'object') return Object.assign(this, Event); @@ -96,13 +103,7 @@ export class PathEvent { this.fullPath = p; this.path = temp.join('/'); this.name = temp.pop() || ''; - this.methods = method.split(''); - this.all = method?.includes('*'); - this.none = method?.includes('n'); - this.create = !method?.includes('n') && (method?.includes('*') || method?.includes('w') || method?.includes('c')); - this.read = !method?.includes('n') && (method?.includes('*') || method?.includes('r')); - this.update = !method?.includes('n') && (method?.includes('*') || method?.includes('w') || method?.includes('u')); - this.delete = !method?.includes('n') && (method?.includes('*') || method?.includes('w') || method?.includes('d')); + this.methods = new ASet(method.split('')); } /**