@@ -12,53 +12,76 @@ export const ObjectID = () => '5e5677d71bdc2ae76344968c';
1212export const PositiveFloat = ( ) => 123.45 ;
1313export const PositiveInt = ( ) => 123 ;
1414export const PostalCode = ( ) => '60031' ;
15- const URLMock = ( ) => {
16- // tslint:disable-next-line: no-eval
17- let URLCtor = typeof URL === 'undefined' ? eval ( `require('url')` ) . URL : URL ;
18- return new URLCtor ( 'http://www.test.com/' ) ;
19- } ;
15+ const URLMock = ( ) => new URL ( 'http://www.test.com/' ) ;
2016// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
21- export const GUID = ( ) => { // Public Domain/MIT
22- let d = new Date ( ) . getTime ( ) ;
23- if ( typeof performance !== 'undefined' && typeof performance . now === 'function' ) {
24- d += performance . now ( ) ; //use high-precision timer if available
25- }
26- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
27- // tslint:disable-next-line: no-bitwise
28- const r = ( d + Math . random ( ) * 16 ) % 16 | 0 ;
29- d = Math . floor ( d / 16 ) ;
30- // tslint:disable-next-line: no-bitwise
31- return ( c === 'x' ? r : ( r & 0x3 | 0x8 ) ) . toString ( 16 ) ;
32- } ) ;
17+ export const GUID = ( ) => {
18+ // Public Domain/MIT
19+ let d = new Date ( ) . getTime ( ) ;
20+ if (
21+ typeof performance !== 'undefined' &&
22+ typeof performance . now === 'function'
23+ ) {
24+ d += performance . now ( ) ; // use high-precision timer if available
25+ }
26+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' . replace ( / [ x y ] / g, function ( c ) {
27+ // tslint:disable-next-line: no-bitwise
28+ const r = ( d + Math . random ( ) * 16 ) % 16 | 0 ;
29+ d = Math . floor ( d / 16 ) ;
30+ // tslint:disable-next-line: no-bitwise
31+ return ( c === 'x' ? r : ( r & 0x3 ) | 0x8 ) . toString ( 16 ) ;
32+ } ) ;
3333} ;
34- export const HexColorCode = ( ) => '#' + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
35- export const Hexadecimal = ( ) => Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
34+ export const HexColorCode = ( ) =>
35+ '#' + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
36+ export const Hexadecimal = ( ) =>
37+ Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 ) ;
3638
3739const randomVal = ( min : number , max : number ) => {
38- return Math . floor ( Math . random ( ) * ( max - min ) + 1 ) + min ;
40+ return Math . floor ( Math . random ( ) * ( max - min ) + 1 ) + min ;
3941} ;
4042// https://codepen.io/meowwwls/pen/jbEJRp
41- export const HSL = ( ) => `hsl(${ randomVal ( 0 , 360 ) } , ${ randomVal ( 30 , 95 ) } %, ${ randomVal ( 30 , 80 ) } %)` ;
42- export const HSLA = ( ) => `hsla(${ randomVal ( 0 , 360 ) } , ${ randomVal ( 30 , 95 ) } %, ${ randomVal ( 30 , 80 ) } %, ${ Math . random ( ) } )` ;
43+ export const HSL = ( ) =>
44+ `hsl(${ randomVal ( 0 , 360 ) } , ${ randomVal ( 30 , 95 ) } %, ${ randomVal ( 30 , 80 ) } %)` ;
45+ export const HSLA = ( ) =>
46+ `hsla(${ randomVal ( 0 , 360 ) } , ${ randomVal ( 30 , 95 ) } %, ${ randomVal (
47+ 30 ,
48+ 80 ,
49+ ) } %, ${ Math . random ( ) } )`;
4350
4451// https://stackoverflow.com/questions/43464519/creating-fake-ip-address-using-javascript
45- export const IPv4 = ( ) => ( Math . floor ( Math . random ( ) * 255 ) + 1 ) + '.' + ( Math . floor ( Math . random ( ) * 255 ) + 0 ) + '.' + ( Math . floor ( Math . random ( ) * 255 ) + 0 ) + '.' + ( Math . floor ( Math . random ( ) * 255 ) + 0 ) ;
52+ export const IPv4 = ( ) =>
53+ Math . floor ( Math . random ( ) * 255 ) +
54+ 1 +
55+ '.' +
56+ ( Math . floor ( Math . random ( ) * 255 ) + 0 ) +
57+ '.' +
58+ ( Math . floor ( Math . random ( ) * 255 ) + 0 ) +
59+ '.' +
60+ ( Math . floor ( Math . random ( ) * 255 ) + 0 ) ;
4661export const IPv6 = ( ) => '2001:0db8:85a3:0000:0000:8a2e:0370:7334' ;
4762// http://jsfiddle.net/guest271314/qhbC9/
48- export const MAC = ( ) => 'XX:XX:XX:XX:XX:XX' . replace ( / X / g, ( ) => '0123456789ABCDEF' . charAt ( Math . floor ( Math . random ( ) * 16 ) ) ) ;
63+ export const MAC = ( ) =>
64+ 'XX:XX:XX:XX:XX:XX' . replace ( / X / g, ( ) =>
65+ '0123456789ABCDEF' . charAt ( Math . floor ( Math . random ( ) * 16 ) ) ,
66+ ) ;
4967export const Port = ( ) => randomVal ( 0 , 65535 ) ;
50- export const RGB = ( ) => `rgb(${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } )` ;
51- export const RGBA = ( ) => `rgba(${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } , ${ Math . random ( ) } )` ;
68+ export const RGB = ( ) =>
69+ `rgb(${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } )` ;
70+ export const RGBA = ( ) =>
71+ `rgba(${ randomVal ( 0 , 255 ) } , ${ randomVal ( 0 , 255 ) } , ${ randomVal (
72+ 0 ,
73+ 255 ,
74+ ) } , ${ Math . random ( ) } )`;
5275export const ISBN = ( ) => `978-3-16-148410-0` ;
5376export const USCurrency = ( ) => 1000 ;
5477export const JSON = ( ) => ( { } ) ;
5578export const JSONObject = ( ) => ( { } ) ;
5679export const IBAN = ( ) => 'NL55INGB4789170233' ;
5780
5881export {
59- URLMock as URL ,
60- NonNegativeInt as UnsignedInt ,
61- NonNegativeFloat as UnsignedFloat ,
62- BigIntMock as Long ,
63- BigIntMock as BigInt ,
82+ URLMock as URL ,
83+ NonNegativeInt as UnsignedInt ,
84+ NonNegativeFloat as UnsignedFloat ,
85+ BigIntMock as Long ,
86+ BigIntMock as BigInt ,
6487} ;
0 commit comments