|
2 | 2 |
|
3 | 3 | **A module to generate a random string based on a given string pattern**
|
4 | 4 |
|
| 5 | +## Installation |
| 6 | + |
| 7 | +The package can be installed by adding `random_string_generator` to your list of dependencies in `mix.exs`: |
| 8 | + |
| 9 | +```elixir |
| 10 | +def deps do |
| 11 | + [ |
| 12 | + {:random_string_generator, "~> 0.1.1"} |
| 13 | + ] |
| 14 | +end |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
5 | 19 | #### Accepted string patterns:
|
6 | 20 |
|
7 | 21 | Use `l` for lower case letter from a to z
|
8 |
| - |
| 22 | + |
9 | 23 | Use `L` for upper case letter from A to Z
|
10 |
| - |
| 24 | + |
11 | 25 | Use `d` for digit from 0 to 9
|
12 |
| - |
| 26 | + |
13 | 27 | Use `p` for punctuation
|
14 | 28 |
|
15 | 29 | #### Punctuation is any character on the following group:
|
16 | 30 |
|
17 |
| - @punctuation [ |
18 |
| - "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", |
19 |
| - ".", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", |
20 |
| - "_", "`", "{", "|","}", "~" |
21 |
| - ] |
| 31 | + `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, `*`, `+`, `,`, `-`, |
| 32 | + `.`, `/`, `:`, `;`, `<`, `=`, `>`, `?`, `@`, `[`, ` \ `, `]`, `^`, |
| 33 | + `_`, `{`, `|`,`}`, `~` and `` ` `` |
22 | 34 |
|
23 | 35 | ##### Generate a string containing 2 lower case letters followed by 2 digits.
|
24 |
| - |
25 |
| - RandomStringGenerator.generate("lldd") |
| 36 | +```elixir |
| 37 | +iex> RandomStringGenerator.generate("lldd") |
| 38 | +"ol68" |
| 39 | +``` |
26 | 40 |
|
27 | 41 | ##### Generate a string containing 2 upper case letters.
|
28 |
| - |
29 |
| - RandomStringGenerator.generate("LL") |
| 42 | +```elixir |
| 43 | +iex> RandomStringGenerator.generate("LL") |
| 44 | +"VR" |
| 45 | +``` |
| 46 | + |
| 47 | +##### Generate a string containing 2 punctuations. |
| 48 | +```elixir |
| 49 | +iex> RandomStringGenerator.generate("pp") |
| 50 | +"?!" |
| 51 | +``` |
30 | 52 |
|
31 | 53 | **Delimiters**
|
32 | 54 |
|
|
35 | 57 | a lower case letter followed by a question mark.
|
36 | 58 |
|
37 | 59 | ##### Generate a string containing 2 letters followed by a hyphen.
|
38 |
| - |
39 |
| - RandomStringGenerator.generate("ll-") |
| 60 | +```elixir |
| 61 | +iex> RandomStringGenerator.generate("ll-") |
| 62 | +"yz-" |
| 63 | +``` |
40 | 64 |
|
41 | 65 | **Scape**
|
42 | 66 |
|
43 | 67 | In order to generate a string containing the characters `l`,`L`,`d` and `p`
|
44 | 68 | as a delimiter you need to use the backslash twice in order to scape it.
|
45 | 69 |
|
46 | 70 | ##### Generate a string containing 2 digits followed by the letters `lLdp`.
|
47 |
| - |
48 |
| - RandomStringGenerator.generate("dd\\l\\L\\d\\p") |
49 |
| - |
50 |
| -## Installation |
51 |
| - |
52 |
| -The package can be installed by adding `random_string_generator` to your list of dependencies in `mix.exs`: |
53 |
| - |
54 | 71 | ```elixir
|
55 |
| -def deps do |
56 |
| - [ |
57 |
| - {:random_string_generator, "~> 0.1.0"} |
58 |
| - ] |
59 |
| -end |
| 72 | +iex> RandomStringGenerator.generate("dd\\l\\L\\d\\p") |
| 73 | +"39lLdp" |
60 | 74 | ```
|
61 | 75 |
|
62 | 76 | Full documentation at [https://hexdocs.pm/random_string_generator](https://hexdocs.pm/random_string_generator).
|
|
0 commit comments