From 9f9d501c0e5456b985a71d635d31344677b4d118 Mon Sep 17 00:00:00 2001 From: Alex Hedley <79629950+alex-hedley@users.noreply.github.com> Date: Wed, 9 Apr 2025 17:04:49 +0100 Subject: [PATCH 1/4] Regex from String --- README.md | 1 + docs/ACKNOWLEDGEMENTS.md | 1 + src/Utility.Test/RegexFromStringTest.cs | 20 +++++ src/Utility.sln | 5 ++ .../Components/Regex/RegexFromString.razor | 75 +++++++++++++++++++ .../Regex/RegexFromString.razor.css | 0 src/Utility/Pages/Index.razor | 1 + src/Utility/Pages/StringConvertor.razor | 9 ++- src/Utility/Utility.csproj | 1 + 9 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 src/Utility.Test/RegexFromStringTest.cs create mode 100644 src/Utility/Components/Regex/RegexFromString.razor create mode 100644 src/Utility/Components/Regex/RegexFromString.razor.css diff --git a/README.md b/README.md index 143e649b..97c708ae 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Utility Web App written in Blazor WebAssembly (WASM) - Url Encode - Url - Guid +- Regex from String - SQL (IN Clause / LIKE) - Luhn - Hidden Char Finder ([Original](https://www.soscisurvey.de/tools/view-chars.php) [Source](https://github.com/BurninLeo/see-non-printable-characters/blob/main/view-chars.php)) diff --git a/docs/ACKNOWLEDGEMENTS.md b/docs/ACKNOWLEDGEMENTS.md index da4c004d..e3ae91d7 100644 --- a/docs/ACKNOWLEDGEMENTS.md +++ b/docs/ACKNOWLEDGEMENTS.md @@ -8,6 +8,7 @@ - Humanizer - Blazored.LocalStorage - [BlazorMonaco](https://github.com/serdarciplak/BlazorMonaco) +- Fare - OpenIconic https://www.appstudio.dev/app/OpenIconic.html - https://github.com/iconic/open-iconic diff --git a/src/Utility.Test/RegexFromStringTest.cs b/src/Utility.Test/RegexFromStringTest.cs new file mode 100644 index 00000000..186ed86b --- /dev/null +++ b/src/Utility.Test/RegexFromStringTest.cs @@ -0,0 +1,20 @@ +using Bunit; +using Utility.Components.Regex; +using Xunit; + +namespace Utility.Test; + +public class RegexFromStringTest: TestContext +{ + public RegexFromStringTest() {} + + //[Fact] + public void RegexFromString_EmptyString_EmptyString() + { + var cut = RenderComponent(); + cut.FindAll("button")[0].Click(); + + RegexFromString regexFromString = cut.Instance; + Assert.Equal(regexFromString.Output, string.Empty); + } +} \ No newline at end of file diff --git a/src/Utility.sln b/src/Utility.sln index 9ebaed86..7231b46c 100644 --- a/src/Utility.sln +++ b/src/Utility.sln @@ -12,6 +12,11 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{53EC20CC-B77E-4620-91E4-90D0FA828C52}" ProjectSection(SolutionItems) = preProject global.json = global.json + ..\README.md = ..\README.md + ..\docs\ACKNOWLEDGEMENTS.md = ..\docs\ACKNOWLEDGEMENTS.md + ..\docs\CHANGELOG.md = ..\docs\CHANGELOG.md + ..\docs\CONTRIBUTORS.md = ..\docs\CONTRIBUTORS.md + ..\docs\README.md = ..\docs\README.md EndProjectSection EndProject Global diff --git a/src/Utility/Components/Regex/RegexFromString.razor b/src/Utility/Components/Regex/RegexFromString.razor new file mode 100644 index 00000000..c0528d58 --- /dev/null +++ b/src/Utility/Components/Regex/RegexFromString.razor @@ -0,0 +1,75 @@ +@using System.Text +@using Fare +@inject IJSRuntime JSRuntime + +
+
+
+ + +
+ +
+ +
+ +
+ + +
+ +
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+

Inspired from String from Regex Generator

+
+
+ +
+ +@code +{ + [Parameter] + public string Output { get; set; } + + string RegularExpression; + int Count; + + protected override void OnInitialized() + { + RegularExpression = @"\d{1,5}"; + Count = 5; + Output = ""; + } + + private void Generate() + { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < Count; i++) + { + var xeger = new Xeger(RegularExpression); + var random = xeger.Generate(); + + builder.Append(random + System.Environment.NewLine); + } + + Output = builder.ToString(); + } +} \ No newline at end of file diff --git a/src/Utility/Components/Regex/RegexFromString.razor.css b/src/Utility/Components/Regex/RegexFromString.razor.css new file mode 100644 index 00000000..e69de29b diff --git a/src/Utility/Pages/Index.razor b/src/Utility/Pages/Index.razor index 90546843..c81bfe0c 100644 --- a/src/Utility/Pages/Index.razor +++ b/src/Utility/Pages/Index.razor @@ -17,6 +17,7 @@
  • Binary
  • String
  • Base64 Encode/Decode
  • +
  • Regex From String
  • Epoch
  • time converter
  • kb - mb - gb converter
  • diff --git a/src/Utility/Pages/StringConvertor.razor b/src/Utility/Pages/StringConvertor.razor index dfacdc0d..8228faaa 100644 --- a/src/Utility/Pages/StringConvertor.razor +++ b/src/Utility/Pages/StringConvertor.razor @@ -2,10 +2,15 @@ @using Utility.Components.StringConverter @using Utility.Components.Base64 +@using Utility.Components.Regex -String Converter +String Tools -

    String Converter

    +

    String Tools

    + + + +
    diff --git a/src/Utility/Utility.csproj b/src/Utility/Utility.csproj index d1f42444..9f700d3d 100644 --- a/src/Utility/Utility.csproj +++ b/src/Utility/Utility.csproj @@ -9,6 +9,7 @@ + From 06042f6229c06304ea9a7e6cb41c27a76f8c0ef7 Mon Sep 17 00:00:00 2001 From: Alex Hedley <79629950+alex-hedley@users.noreply.github.com> Date: Wed, 9 Apr 2025 17:05:12 +0100 Subject: [PATCH 2/4] Guid: Bind the size of the textarea to the count of items --- src/Utility/Components/GuidGenerator/GuidGenerator.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utility/Components/GuidGenerator/GuidGenerator.razor b/src/Utility/Components/GuidGenerator/GuidGenerator.razor index 51cfce58..7d923a45 100644 --- a/src/Utility/Components/GuidGenerator/GuidGenerator.razor +++ b/src/Utility/Components/GuidGenerator/GuidGenerator.razor @@ -86,7 +86,7 @@
    - +
    From 2c26495f4b6bf5913f761ad770b3af51a88f1243 Mon Sep 17 00:00:00 2001 From: Alex Hedley <79629950+alex-hedley@users.noreply.github.com> Date: Wed, 9 Apr 2025 17:08:52 +0100 Subject: [PATCH 3/4] Guid: Fix test --- src/Utility.Test/GuidGeneratorTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utility.Test/GuidGeneratorTest.cs b/src/Utility.Test/GuidGeneratorTest.cs index 845cdb3e..8828a22f 100644 --- a/src/Utility.Test/GuidGeneratorTest.cs +++ b/src/Utility.Test/GuidGeneratorTest.cs @@ -100,7 +100,7 @@ public void MultipleDeleteShouldBeEmpty() { var cut = RenderComponent(); cut.FindAll("button")[5].Click(); - string markup = ""; + string markup = ""; cut.FindAll("textarea")[0].MarkupMatches(markup); // guids } From e9adbcf47b63490c598810c6c4abcae6c64a89b4 Mon Sep 17 00:00:00 2001 From: Alex Hedley <79629950+alex-hedley@users.noreply.github.com> Date: Wed, 9 Apr 2025 17:17:00 +0100 Subject: [PATCH 4/4] Regex: add copy button --- src/Utility/Components/Regex/RegexFromString.razor | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Utility/Components/Regex/RegexFromString.razor b/src/Utility/Components/Regex/RegexFromString.razor index c0528d58..8390bb09 100644 --- a/src/Utility/Components/Regex/RegexFromString.razor +++ b/src/Utility/Components/Regex/RegexFromString.razor @@ -32,7 +32,12 @@
    - +
    + + + + +
    @@ -70,6 +75,11 @@ builder.Append(random + System.Environment.NewLine); } - Output = builder.ToString(); + Output = builder.ToString().Trim(); + } + + async Task Copy() + { + await JSRuntime.InvokeVoidAsync("navigator.clipboard.writeText", Output); } } \ No newline at end of file