import RandExp from 'randexp' ; import { Inject , Service } from 'typedi' ; import { Property } from '@mockingbird/reflect' ; import { ValueHandler } from '../types/value-handler.interface' ; import { Class } from '@mockingbird/common' ; @ Service ( ) export class RegexValueHandler implements ValueHandler { public constructor ( @ Inject ( 'RandExp' ) private readonly randexp ) { } public shouldHandle ( property ) { return property . decoratorValue . isRegex ( ) ; } public produceValue ( property ) { const { decoratorValue } = property ; const { value : regex } = decoratorValue ; const randexp = new this . randexp ( regex as RegExp ) ; return randexp . gen ( ) as string ; } }