2
2
3
3
# Generate random strings, strings with mask and strength passwords
4
4
5
- ` generate-string ` is a string generator that build random strings, strings with mask and passwords with password-strength tester.
5
+ ` generate-strings ` is a string generator that build random strings, strings with mask and passwords with password-strength tester.
6
6
It is lightweight, extensible, has no dependencies, typescript support and can be used on the server with NodeJS or in-browser with JS.
7
7
8
8
[ ![ Build Status] ( https://travis-ci.com/lucasgdb/generate-strings.svg?branch=master )] ( https://travis-ci.com/lucasgdb/generate-strings )
@@ -17,6 +17,12 @@ From the command line:
17
17
npm install generate-strings --save
18
18
```
19
19
20
+ or
21
+
22
+ ``` sh
23
+ yarn add generate-strings
24
+ ```
25
+
20
26
### In-browser
21
27
22
28
Within your document (each one for the desired function)
@@ -30,24 +36,24 @@ Within your document (each one for the desired function)
30
36
or
31
37
32
38
``` html
33
- <script src =" bundle .min.js" ></script >
39
+ <script src =" generateStrings .min.js" ></script >
34
40
```
35
41
36
42
## Features
37
43
38
- 1 . Generate random strings (default) like below :
44
+ 1 . Generate random strings:
39
45
40
46
``` sh
41
47
' ,9nlg4^]'
42
48
```
43
49
44
- 2 . Generate strings with mask like below :
50
+ 2 . Generate strings with mask:
45
51
46
52
``` sh
47
53
' @#$%-@#$%-@#$%-@#$%' = ' Aa!0-Aa!0-Aa!0-Aa!0'
48
54
```
49
55
50
- 3 . Generate passwords with password-strength tester like below :
56
+ 3 . Generate passwords with password-strength tester:
51
57
52
58
``` sh
53
59
{ password: ' 2dt4hKIPO*=He' , strength: ' high' }
@@ -67,9 +73,15 @@ After you've included it into your project, using the module is straightforward:
67
73
68
74
```javascript
69
75
// require the module
70
- const { generateRandomString } = require(' generate-strings' );
76
+ const {
77
+ generateRandomString,
78
+ generateRandomStringWithMask,
79
+ generateRandomPassword,
80
+ } = require(' generate-strings' );
71
81
72
82
console.log(generateRandomString());
83
+ console.log(generateRandomStringWithMask());
84
+ console.log(generateRandomPassword());
73
85
```
74
86
75
87
### In-browser
@@ -87,29 +99,24 @@ The module may be configured as follows:
87
99
OBS: The settings shown below are the defaults.
88
100
89
101
```javascript
90
- const { generateRandomPassword } = require(' generate-strings' );
91
-
92
- // Pass a hash of settings into an object.
93
- const settings = {
94
- // available settings will be shown below
95
- };
102
+ import { generateRandomString } from ' generate-strings' ;
96
103
97
104
// and then:
98
- const string = generateRandomPassword(settings );
105
+ const randomString = generateRandomString( );
99
106
```
100
107
101
108
### Available options for generateRandomString
102
109
103
110
| Name | Type | Description | Default value | Allowed values |
104
111
| ------------------- | ------- | ----------------------------------------- | ---------------------------- | ------------------------- |
105
112
| stringLength | Integer | Size of the string that will be generated | 8 | 0-Number.MAX_SAFE_INTEGER |
106
- | upperCase | Boolean | Determines whether it will be generated | true | true and false |
113
+ | upperCase | Boolean | Determines whether it will be generated | true | true, false |
107
114
| upperCaseCharacters | String | UpperCase letters to be generated | ' ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ' A-Z' |
108
- | lowerCase | Boolean | Determines whether it will be generated | true | true and false |
115
+ | lowerCase | Boolean | Determines whether it will be generated | true | true, false |
109
116
| lowerCaseCharacters | String | LowerCase letters to be generated | ' abcdefghijklmnopqrstuvwxyz' | ' a-z' |
110
- | special | Boolean | Determines whether it will be generated | false | true and false |
117
+ | special | Boolean | Determines whether it will be generated | false | true, false |
111
118
| specialCharacters | String | Special letters to be generated | ' ! @# $%&\*()=[]{}' | All special characters |
112
- | number | Boolean | Determines whether it will be generated | true | true and false |
119
+ | number | Boolean | Determines whether it will be generated | true | true, false |
113
120
| numberCharacters | String | Numbers to be generated | '0123456789' | 0-9 |
114
121
115
122
### Available options for generateRandomStringWithMask
@@ -131,51 +138,64 @@ const string = generateRandomPassword(settings);
131
138
| Name | Type | Description | Default value | Allowed values |
132
139
| ------------------- | ------- | ----------------------------------------------- | ---------------------------- | ------------------------------------------------------- |
133
140
| passwordLength | Integer | Size of the strings that will be generated | 8 | 0-Number.MAX_SAFE_INTEGER |
134
- | showStrength | Boolean | Shows the password strength | false | true and false |
135
- | excludeEqualChars | Boolean | Excludes characters that are consecutive equals | true | true and false |
141
+ | showStrength | Boolean | Shows the password strength | false | true, false |
142
+ | excludeEqualChars | Boolean | Excludes characters that are consecutive equals | false | true, false |
136
143
| firstCharType | String | Determines the type of first character | 'random' | 'random', 'upperCase', 'lowerCase', 'special', 'number' |
137
- | upperCase | Boolean | Determines whether it will be generated | true | true and false |
144
+ | upperCase | Boolean | Determines whether it will be generated | true | true, false |
138
145
| upperCaseCharacters | String | UpperCase letters to be generated | 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | 'A-Z' |
139
- | lowerCase | Boolean | Determines whether it will be generated | true | true and false |
146
+ | lowerCase | Boolean | Determines whether it will be generated | true | true, false |
140
147
| lowerCaseCharacters | String | LowerCase letters to be generated | 'abcdefghijklmnopqrstuvwxyz' | 'a-z' |
141
- | special | Boolean | Determines whether it will be generated | false | true and false |
148
+ | special | Boolean | Determines whether it will be generated | false | true, false |
142
149
| specialCharacters | String | Special letters to be generated | '!@#$%&\*()=[]{}' | All special characters |
143
- | number | Boolean | Determines whether it will be generated | true | true and false |
150
+ | number | Boolean | Determines whether it will be generated | true | true, false |
144
151
| numberCharacters | String | Numbers to be generated | '0123456789' | 0-9 |
145
152
146
153
## Examples
147
154
148
- ` ` ` javascript
149
- const { generateRandomPassword } = require(' generate-strings' );
155
+ ` ` ` typescript
156
+ import {
157
+ generateRandomString,
158
+ generateRandomStringProps,
159
+ } from ' generate-strings' ;
150
160
151
- const settings = {
152
- passwordLength: 12 ,
161
+ const settings: generateRandomStringProps = {
162
+ stringLength: 15 ,
153
163
special: true,
154
- showStrength: true,
155
- excludeEqualChars: true,
156
164
};
157
165
158
- const pass = generateRandomPassword (settings); // will return a random object like: { password: ' T2$he{Yk6pvf ' , strength: ' high ' }
166
+ const randomStringWithMask = generateRandomString (settings); // will return a string like: bov $Ia @}Rr8gzU *
159
167
` ` `
160
168
161
- ` ` ` javascript
162
- const { generateRandomStringWithMask } = require(' generate-strings' );
169
+ ` ` ` typescript
170
+ import {
171
+ generateRandomStringWithMask,
172
+ generateRandomStringWithMaskProps,
173
+ } from ' generate-strings' ;
163
174
164
- const settings = {
175
+ const settings: generateRandomStringWithMaskProps = {
165
176
upperCaseMask: ' &' ,
166
177
mask: ' ####_####%@hotmail.com' ,
167
178
};
168
179
169
- const
pass = generateRandomStringWithMask(settings)
; // will
return a
random string like:
[email protected]
180
+ const
randomStringWithMask = generateRandomStringWithMask(settings)
; // will
return a string like:
[email protected]
170
181
` ` `
171
182
172
- # # Testing
183
+ ` ` ` typescript
184
+ import {
185
+ generateRandomPassword,
186
+ generateRandomPasswordProps,
187
+ } from ' generate-strings' ;
173
188
174
- To run the test, simply run ` yarn test` . You
175
- may first need to run ` yarn` to install the required development
176
- dependencies. (These dependencies are ** not** required in a production
177
- environment, and facilitate only unit testing.)
189
+ const settings: generateRandomPasswordProps = {
190
+ passwordLength: 12,
191
+ special: true,
192
+ showStrength: true,
193
+ excludeEqualChars: true,
194
+ };
178
195
179
- # # Contributing
196
+ const randomPassword = generateRandomPassword(settings); // will return a object like: { password: ' T2$he{Yk6pvf' , strength: ' high' }
197
+ ` ` `
198
+
199
+ # # Testing
180
200
181
- If you ' d like to contribute, please fork this repository, change the branch typing `git switch dev`, make a new branch typing `git checkout -b new-branch-name`, make your changes, make a push typing `git push -u origin new-branch-name` and then submit a pull-request.
201
+ To test the application, run ` yarn test ` . You may first need to run ` yarn ` to install the required development dependencies. (These dependencies are ** not ** required in a production environment, and facilitate only unit testing.)
0 commit comments