let RandExp = require ( 'randexp' ) ; import { integer } from 'random-js' ; import { Arbitrary } from '../arbitrary' ; import { oneOf } from './pickers' ; /**
 * Generates a constant value.
 */ export function constant ( value ) { return new Arbitrary ( { gen : ( ) => ( ) => value } ) . set ( 'name' , 'Constant' ) ; } /**
 * Options of RegexGenOpts
 */ export type RegexGenOpts = { ignoreCase : boolean ; multiline : boolean ; } ; XXX export function regex ( pattern ) { return new Arbitrary ( { gen : function ( opts ) { return function ( engine ) { const m = [ ] ; if ( opts . ignoreCase ) m . push ( 'i' ) ; if ( opts . multiline ) m . push ( 'm' ) ; const randexp = new RandExp ( pattern , m . join ( ) ) ; randexp . randInt = ( from , to ) => { return integer ( from , to ) ( engine ) ; } ; return randexp . gen ( ) ; } ; } , genOpts : { ignoreCase : false , multiline : false } } ) ; } /**
 * An arbitrary returns a value or null.
 */ export function maybe ( arb ) { return oneOf ( [ arb , constant ( null ) ] ) . set ( 'name' , 'Maybe' ) ; }