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
22
3- # top-most EditorConfig file
43root = true
54
6- # Unix-style newlines with a newline ending every file
75[* ]
8- charset = utf-8
96end_of_line = lf
10- trim_trailing_whitespace = true
117insert_final_newline = true
8+
9+ [* .{js,d.ts,ts} ]
10+ charset = utf-8
11+ trim_trailing_whitespace = true
1212indent_style = space
1313indent_size = 4
1414
15- # 2 space indentation
16- [* .yaml, * .yml ]
15+ [package.json,* .yaml ]
1716indent_style = space
1817indent_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 11# Global
22node_modules /
3+ coverage
34
45# OS Generated
56.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 11export default function string ( options ) {
22 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 = [ ] ;
66 if ( length < 0 ) {
77 length = 1 ;
88 }
9- for ( var i = 0 ; i < length ; i ++ ) {
9+
10+ for ( let i = 0 ; i < length ; i ++ ) {
1011 pieces . push ( keyspace . charAt ( Math . floor ( Math . random ( ) * keyspace . length ) ) ) ;
1112 }
13+
1214 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 11{
22 "name" : " @fakerjs/string" ,
3- "version" : " 2.0.1 " ,
3+ "version" : " 2.1.0 " ,
44 "description" : " String package provides functionality to generate a fake string value." ,
55 "license" : " MIT" ,
66 "repository" : " faker-javascript/string" ,
1515 "node" : " >=12"
1616 },
1717 "scripts" : {
18- "test" : " ava"
18+ "test" : " c8 ava; xo --space 4; tsd; "
1919 },
2020 "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"
2225 },
2326 "files" : [
24- " index.js"
27+ " index.js" ,
28+ " index.d.ts"
2529 ],
2630 "keywords" : [
2731 " fakerjs" ,
Original file line number Diff line number Diff line change 1- import string from './index.js' ;
21import test from 'ava' ;
2+ import string from './index.js' ;
33
44test ( 'string return type to be string' , t => {
5- t . is ( typeof string ( ) , 'string' ) ;
5+ t . is ( typeof string ( ) , 'string' ) ;
66} ) ;
77
88test ( '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 ) ;
1014} ) ;
1115
1216test ( '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