-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathrandom-string-builder.ts
More file actions
64 lines (53 loc) · 1.17 KB
/
random-string-builder.ts
File metadata and controls
64 lines (53 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
'use strict'
import { RandomStringConfig } from './random-string-config'
import { RandomStringBuilder as RandomStringBuilderContract } from './contracts'
export class RandomStringBuilder implements RandomStringBuilderContract {
/**
* Stores the random string config.
*/
private readonly config: RandomStringConfig
/**
* Create a new random string builder instance.
*/
constructor (config: RandomStringConfig) {
this.config = config
}
/**
* Assign the given `length` for the random string. By default, uses a length of 21 characters.
*
* @param length
*
* @returns {this}
*/
length (length: number): this {
this.config.withLength(length)
return this
}
/**
* Use numbers when generating a random string.
*
* @returns {this}
*/
characters (): this {
this.config.useCharacters()
return this
}
/**
* Use numbers when generating a random string.
*
* @returns {this}
*/
numbers (): this {
this.config.useNumbers()
return this
}
/**
* Use symbols when generating a random string.
*
* @returns {this}
*/
symbols (): this {
this.config.useSymbols()
return this
}
}