@@ -2,54 +2,54 @@ import test from 'ava';
2
2
import cryptoRandomString from '.' ;
3
3
4
4
test ( 'main' , t => {
5
- t . is ( cryptoRandomString ( 0 ) . length , 0 ) ;
6
- t . is ( cryptoRandomString ( 10 ) . length , 10 ) ;
7
- t . is ( cryptoRandomString ( 100 ) . length , 100 ) ;
8
- t . regex ( cryptoRandomString ( 100 ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
5
+ t . is ( cryptoRandomString ( { length : 0 } ) . length , 0 ) ;
6
+ t . is ( cryptoRandomString ( { length : 10 } ) . length , 10 ) ;
7
+ t . is ( cryptoRandomString ( { length : 100 } ) . length , 100 ) ;
8
+ t . regex ( cryptoRandomString ( { length : 100 } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
9
9
} ) ;
10
10
11
11
test ( 'hex' , t => {
12
- t . is ( cryptoRandomString ( 0 , { type : 'hex' } ) . length , 0 ) ;
13
- t . is ( cryptoRandomString ( 10 , { type : 'hex' } ) . length , 10 ) ;
14
- t . is ( cryptoRandomString ( 100 , { type : 'hex' } ) . length , 100 ) ;
15
- t . regex ( cryptoRandomString ( 100 , { type : 'hex' } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
12
+ t . is ( cryptoRandomString ( { length : 0 , type : 'hex' } ) . length , 0 ) ;
13
+ t . is ( cryptoRandomString ( { length : 10 , type : 'hex' } ) . length , 10 ) ;
14
+ t . is ( cryptoRandomString ( { length : 100 , type : 'hex' } ) . length , 100 ) ;
15
+ t . regex ( cryptoRandomString ( { length : 100 , type : 'hex' } ) , / ^ [ a - f \d ] * $ / ) ; // Sanity check, probabilistic
16
16
} ) ;
17
17
18
18
test ( 'base64' , t => {
19
- t . is ( cryptoRandomString ( 0 , { type : 'base64' } ) . length , 0 ) ;
20
- t . is ( cryptoRandomString ( 10 , { type : 'base64' } ) . length , 10 ) ;
21
- t . is ( cryptoRandomString ( 100 , { type : 'base64' } ) . length , 100 ) ;
22
- t . regex ( cryptoRandomString ( 100 , { type : 'base64' } ) , / ^ [ a - z A - Z \d / + ] * $ / ) ; // Sanity check, probabilistic
19
+ t . is ( cryptoRandomString ( { length : 0 , type : 'base64' } ) . length , 0 ) ;
20
+ t . is ( cryptoRandomString ( { length : 10 , type : 'base64' } ) . length , 10 ) ;
21
+ t . is ( cryptoRandomString ( { length : 100 , type : 'base64' } ) . length , 100 ) ;
22
+ t . regex ( cryptoRandomString ( { length : 100 , type : 'base64' } ) , / ^ [ a - z A - Z \d / + ] * $ / ) ; // Sanity check, probabilistic
23
23
} ) ;
24
24
25
25
test ( 'url-safe' , t => {
26
- t . is ( cryptoRandomString ( 0 , { type : 'url-safe' } ) . length , 0 ) ;
27
- t . is ( cryptoRandomString ( 10 , { type : 'url-safe' } ) . length , 10 ) ;
28
- t . is ( cryptoRandomString ( 100 , { type : 'url-safe' } ) . length , 100 ) ;
29
- t . regex ( cryptoRandomString ( 100 , { type : 'url-safe' } ) , / ^ [ a - z A - Z \d . _ ~ - ] * $ / ) ; // Sanity check, probabilistic
26
+ t . is ( cryptoRandomString ( { length : 0 , type : 'url-safe' } ) . length , 0 ) ;
27
+ t . is ( cryptoRandomString ( { length : 10 , type : 'url-safe' } ) . length , 10 ) ;
28
+ t . is ( cryptoRandomString ( { length : 100 , type : 'url-safe' } ) . length , 100 ) ;
29
+ t . regex ( cryptoRandomString ( { length : 100 , type : 'url-safe' } ) , / ^ [ a - z A - Z \d . _ ~ - ] * $ / ) ; // Sanity check, probabilistic
30
30
} ) ;
31
31
32
32
test ( 'characters' , t => {
33
- t . is ( cryptoRandomString ( 0 , { characters : '1234' } ) . length , 0 ) ;
34
- t . is ( cryptoRandomString ( 10 , { characters : '1234' } ) . length , 10 ) ;
35
- t . is ( cryptoRandomString ( 100 , { characters : '1234' } ) . length , 100 ) ;
36
- t . regex ( cryptoRandomString ( 100 , { characters : '1234' } ) , / ^ [ 1 - 4 ] * $ / ) ; // Sanity check, probabilistic
33
+ t . is ( cryptoRandomString ( { length : 0 , characters : '1234' } ) . length , 0 ) ;
34
+ t . is ( cryptoRandomString ( { length : 10 , characters : '1234' } ) . length , 10 ) ;
35
+ t . is ( cryptoRandomString ( { length : 100 , characters : '1234' } ) . length , 100 ) ;
36
+ t . regex ( cryptoRandomString ( { length : 100 , characters : '1234' } ) , / ^ [ 1 - 4 ] * $ / ) ; // Sanity check, probabilistic
37
37
} ) ;
38
38
39
39
test ( 'argument errors' , t => {
40
40
t . throws ( ( ) => {
41
- cryptoRandomString ( Infinity ) ;
41
+ cryptoRandomString ( { length : Infinity } ) ;
42
42
} ) ;
43
43
44
44
t . throws ( ( ) => {
45
- cryptoRandomString ( 0 , { type : 'hex' , characters : '1234' } ) ;
45
+ cryptoRandomString ( { length : 0 , type : 'hex' , characters : '1234' } ) ;
46
46
} ) ;
47
47
48
48
t . throws ( ( ) => {
49
- cryptoRandomString ( 0 , { characters : 42 } ) ;
49
+ cryptoRandomString ( { length : 0 , characters : 42 } ) ;
50
50
} ) ;
51
51
52
52
t . throws ( ( ) => {
53
- cryptoRandomString ( 0 , { type : 'unknown' } ) ;
53
+ cryptoRandomString ( { length : 0 , type : 'unknown' } ) ;
54
54
} ) ;
55
55
} ) ;
0 commit comments