import {IAdvice, IPointcut} from "../../interface" import {ConstructorType} from "../../type" export default class AopPointcut implements IPointcut{ public cost!: ConstructorType public name: string public execution: RegExp public advices: Array = [] constructor({cost = AopPointcut, name = '', execution = ''} = {}){ this.cost = cost this.name = name this.execution = _match(execution) } public setAdvices(advices: Array): void{ advices && advices.forEach((advice: IAdvice): void => { if(advice.cost === this.cost && advice.pointcutName === this.name){ this.advices.push(advice) } }) } } function _match(s: string = ''): RegExp{ s = s.replace(/\.\./g, 'dd') s = s.replace(/\*/g, 'xx') s = s.replace(/\(/g, 'lk') s = s.replace(/\)/g, 'rk') s = s.replace(/dd/g, '.*') s = s.replace(/xx/g, '(\\w*)') s = s.replace(/lk/g, '\\(') s = s.replace(/rk/g, '\\)') return new RegExp(s) }