File tree Expand file tree Collapse file tree 8 files changed +44
-21
lines changed Expand file tree Collapse file tree 8 files changed +44
-21
lines changed Original file line number Diff line number Diff line change 1
- # EditorConfig: http ://EditorConfig.org
1
+ # EditorConfig is awesome: https ://EditorConfig.org
2
2
3
- # top-most EditorConfig file
4
3
root = true
5
4
6
- # Unix-style newlines with a newline ending every file
7
5
[* ]
8
- charset = utf-8
9
6
end_of_line = lf
10
- trim_trailing_whitespace = true
11
7
insert_final_newline = true
8
+
9
+ [* .{js,d.ts,ts} ]
10
+ charset = utf-8
11
+ trim_trailing_whitespace = true
12
12
indent_style = space
13
13
indent_size = 4
14
14
15
- # 2 space indentation
16
- [* .yaml, * .yml ]
15
+ [package.json,* .yaml ]
17
16
indent_style = space
18
17
indent_size = 2
Original file line number Diff line number Diff line change
1
+ * text =auto eol =lf
Original file line number Diff line number Diff line change 1
1
# Global
2
2
node_modules /
3
+ coverage
3
4
4
5
# OS Generated
5
6
.DS_Store *
Original file line number Diff line number Diff line change
1
+ interface Options {
2
+ length ?: number ;
3
+ keyspace ?: string ;
4
+ }
5
+ export default function string ( options ?: Options ) : string ;
Original file line number Diff line number Diff line change 1
1
export default function string ( options ) {
2
2
options = options || { } ;
3
- let length = options . length || 64 ;
4
- let keyspace = options . keyspace || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
5
- let pieces = [ ] ;
3
+ let length = options . length === undefined ? 64 : options . length ;
4
+ const keyspace = options . keyspace || '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
5
+ const pieces = [ ] ;
6
6
if ( length < 0 ) {
7
7
length = 1 ;
8
8
}
9
- for ( var i = 0 ; i < length ; i ++ ) {
9
+
10
+ for ( let i = 0 ; i < length ; i ++ ) {
10
11
pieces . push ( keyspace . charAt ( Math . floor ( Math . random ( ) * keyspace . length ) ) ) ;
11
12
}
13
+
12
14
return pieces . join ( '' ) ;
13
- } ;
15
+ }
Original file line number Diff line number Diff line change
1
+ import { expectType } from 'tsd' ;
2
+ import string from './index.js' ;
3
+
4
+ expectType < string > ( string ( ) ) ;
5
+ expectType < string > ( string ( { length : - 1 } ) ) ;
6
+ expectType < string > ( string ( { length : 10 } ) ) ;
7
+ expectType < string > ( string ( { length : 10 , keyspace : '0123456789' } ) ) ;
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @fakerjs/string" ,
3
- "version" : " 2.0.1 " ,
3
+ "version" : " 2.1.0 " ,
4
4
"description" : " String package provides functionality to generate a fake string value." ,
5
5
"license" : " MIT" ,
6
6
"repository" : " faker-javascript/string" ,
15
15
"node" : " >=12"
16
16
},
17
17
"scripts" : {
18
- "test" : " ava"
18
+ "test" : " c8 ava; xo --space 4; tsd; "
19
19
},
20
20
"devDependencies" : {
21
- "ava" : " ^3.15.0"
21
+ "ava" : " ^4.0.0" ,
22
+ "c8" : " ^7.11.0" ,
23
+ "tsd" : " ^0.19.1" ,
24
+ "xo" : " ^0.47.0"
22
25
},
23
26
"files" : [
24
- " index.js"
27
+ " index.js" ,
28
+ " index.d.ts"
25
29
],
26
30
"keywords" : [
27
31
" fakerjs" ,
Original file line number Diff line number Diff line change 1
- import string from './index.js' ;
2
1
import test from 'ava' ;
2
+ import string from './index.js' ;
3
3
4
4
test ( 'string return type to be string' , t => {
5
- t . is ( typeof string ( ) , 'string' ) ;
5
+ t . is ( typeof string ( ) , 'string' ) ;
6
6
} ) ;
7
7
8
8
test ( 'string length is 10' , t => {
9
- t . is ( string ( { length : 10 } ) . length , 10 ) ;
9
+ t . is ( string ( { length : 10 } ) . length , 10 ) ;
10
+ } ) ;
11
+
12
+ test ( 'string length is -1' , t => {
13
+ t . is ( string ( { length : - 1 } ) . length , 1 ) ;
10
14
} ) ;
11
15
12
16
test ( 'string length is 10 with keyspace 0123456789' , t => {
13
- t . is ( string ( { length : 10 , keyspace : '0123456789' } ) . length , 10 ) ;
14
- } ) ;
17
+ t . is ( string ( { length : 10 , keyspace : '0123456789' } ) . length , 10 ) ;
18
+ } ) ;
You can’t perform that action at this time.
0 commit comments