| | 1 | | @using System.Text |
| | 2 | | @using Fare |
| | 3 | | @inject IJSRuntime JSRuntime |
| | 4 | |
|
| | 5 | | <div class="container"> |
| | 6 | | <div class="row"> |
| | 7 | | <div class="col"> |
| | 8 | |
|
| | 9 | | <label class="label-control">Regular Expression:</label> |
| | 10 | | <div class="input-group"> |
| | 11 | | <input type="regularExpression" id="regularExpression" name="regularExpression" class="form-control" @bi |
| | 12 | | </div> |
| | 13 | |
|
| | 14 | | </div> |
| | 15 | |
|
| | 16 | | <div class="col"> |
| | 17 | |
|
| | 18 | | <label class="label-control">Count:</label> |
| | 19 | | <div class="input-group"> |
| | 20 | | <input type="count" id="count" name="count" class="form-control" @bind="Count"> |
| | 21 | | </div> |
| | 22 | |
|
| | 23 | | </div> |
| | 24 | |
|
| | 25 | | </div> |
| | 26 | |
|
| | 27 | | <div class="row"> |
| | 28 | | <div class="col"> |
| | 29 | | <button id="Generate" name="Generate" @onclick="Generate" class="btn btn-success float-right">Generate</butt |
| | 30 | | </div> |
| | 31 | | </div> |
| | 32 | |
|
| | 33 | | <div class="row"> |
| | 34 | | <div class="col"> |
| | 35 | | <div class="input-group"> |
| | 36 | | <textarea id="output" class="form-control" rows="@Count" @bind="Output"></textarea> |
| | 37 | | <span class="input-group-btn"> |
| | 38 | | <button id="btnCopy" name="btnCopy" class="btn btn-info float-right" @onclick="Copy"><i class="far f |
| | 39 | | </span> |
| | 40 | | </div> |
| | 41 | | </div> |
| | 42 | | </div> |
| | 43 | |
|
| | 44 | | <div class="row"> |
| | 45 | | <div class="col"> |
| | 46 | | <p>Inspired from <a href="https://onlinestringtools.com/generate-string-from-regex" target="_blank">String f |
| | 47 | | </div> |
| | 48 | | </div> |
| | 49 | |
|
| | 50 | | </div> |
| | 51 | |
|
| | 52 | | @code |
| | 53 | | { |
| | 54 | | [Parameter] |
| 0 | 55 | | public string Output { get; set; } |
| | 56 | |
|
| | 57 | | string RegularExpression; |
| | 58 | | int Count; |
| | 59 | |
|
| | 60 | | protected override void OnInitialized() |
| 0 | 61 | | { |
| 0 | 62 | | RegularExpression = @"\d{1,5}"; |
| 0 | 63 | | Count = 5; |
| 0 | 64 | | Output = ""; |
| 0 | 65 | | } |
| | 66 | |
|
| | 67 | | private void Generate() |
| 0 | 68 | | { |
| 0 | 69 | | StringBuilder builder = new StringBuilder(); |
| 0 | 70 | | for (int i = 0; i < Count; i++) |
| 0 | 71 | | { |
| 0 | 72 | | var xeger = new Xeger(RegularExpression); |
| 0 | 73 | | var random = xeger.Generate(); |
| | 74 | |
|
| 0 | 75 | | builder.Append(random + System.Environment.NewLine); |
| 0 | 76 | | } |
| | 77 | |
|
| 0 | 78 | | Output = builder.ToString().Trim(); |
| 0 | 79 | | } |
| | 80 | |
|
| | 81 | | async Task Copy() |
| 0 | 82 | | { |
| 0 | 83 | | await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output); |
| 0 | 84 | | } |
| | 85 | | } |