Updated ASet & Path Events
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
	"name": "@ztimson/utils",
 | 
						"name": "@ztimson/utils",
 | 
				
			||||||
	"version": "0.20.12",
 | 
						"version": "0.21.0",
 | 
				
			||||||
	"description": "Utility library",
 | 
						"description": "Utility library",
 | 
				
			||||||
	"author": "Zak Timson",
 | 
						"author": "Zak Timson",
 | 
				
			||||||
	"license": "MIT",
 | 
						"license": "MIT",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ export class ASet<T> extends Array {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	add(...items: T[]) {
 | 
						add(...items: T[]) {
 | 
				
			||||||
		items.filter(el => !this.has(el)).forEach(el => this.push(el));
 | 
							items.filter(el => !this.has(el)).forEach(el => this.push(el));
 | 
				
			||||||
 | 
							return this;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
@@ -35,6 +36,7 @@ export class ASet<T> extends Array {
 | 
				
			|||||||
			const index = this.indexOf(el);
 | 
								const index = this.indexOf(el);
 | 
				
			||||||
			if(index != -1) this.slice(index, 1);
 | 
								if(index != -1) this.slice(index, 1);
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
 | 
							return this;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -69,19 +69,26 @@ export class PathEvent {
 | 
				
			|||||||
	/** Last sagment of path */
 | 
						/** Last sagment of path */
 | 
				
			||||||
	name!: string;
 | 
						name!: string;
 | 
				
			||||||
	/** List of methods */
 | 
						/** List of methods */
 | 
				
			||||||
	methods!: Method[];
 | 
						methods!: ASet<Method>;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/** All/Wildcard specified */
 | 
						/** All/Wildcard specified */
 | 
				
			||||||
	all!: boolean;
 | 
						get all(): boolean { return this.methods.has('*') }
 | 
				
			||||||
 | 
						set all(v: boolean) { v ? new ASet<Method>(['*']) : this.methods.delete('*'); }
 | 
				
			||||||
	/** None specified */
 | 
						/** None specified */
 | 
				
			||||||
	none!: boolean;
 | 
						get none(): boolean { return this.methods.has('n') }
 | 
				
			||||||
 | 
						set none(v: boolean) { v ? this.methods = new ASet<Method>(['n']) : this.methods.delete('n'); }
 | 
				
			||||||
	/** Create method specified */
 | 
						/** 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 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 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 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) {
 | 
						constructor(Event: string | PathEvent) {
 | 
				
			||||||
		if(typeof Event == 'object') return Object.assign(this, Event);
 | 
							if(typeof Event == 'object') return Object.assign(this, Event);
 | 
				
			||||||
@@ -96,13 +103,7 @@ export class PathEvent {
 | 
				
			|||||||
		this.fullPath = p;
 | 
							this.fullPath = p;
 | 
				
			||||||
		this.path = temp.join('/');
 | 
							this.path = temp.join('/');
 | 
				
			||||||
		this.name = temp.pop() || '';
 | 
							this.name = temp.pop() || '';
 | 
				
			||||||
		this.methods = <Method[]>method.split('');
 | 
							this.methods = new ASet(<any>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'));
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user