{"id":28568426,"url":"https://github.com/jamiefutch/basicutils","last_synced_at":"2025-06-10T16:12:03.792Z","repository":{"id":77811465,"uuid":"289536215","full_name":"jamiefutch/BasicUtils","owner":"jamiefutch","description":"Utility library for  .Net applications","archived":false,"fork":false,"pushed_at":"2025-06-08T21:03:12.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-08T21:18:10.529Z","etag":null,"topics":["console-tool","csharp","ngrams","utility-library"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamiefutch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-08-22T17:34:52.000Z","updated_at":"2025-06-08T20:09:46.000Z","dependencies_parsed_at":"2025-04-27T21:26:15.298Z","dependency_job_id":"a8efae6e-0bca-420b-a4ab-58e6e6f6f644","html_url":"https://github.com/jamiefutch/BasicUtils","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiefutch%2FBasicUtils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiefutch%2FBasicUtils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiefutch%2FBasicUtils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiefutch%2FBasicUtils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamiefutch","download_url":"https://codeload.github.com/jamiefutch/BasicUtils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamiefutch%2FBasicUtils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259106733,"owners_count":22805941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["console-tool","csharp","ngrams","utility-library"],"created_at":"2025-06-10T16:12:01.476Z","updated_at":"2025-06-10T16:12:03.774Z","avatar_url":"https://github.com/jamiefutch.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BasicUtils\n\nA modern, modular collection of utility classes and extension methods for .NET 8 and .NET 9 projects.  \nBasicUtils is designed to simplify common programming tasks such as string manipulation, console operations, CSV handling, object type checking, logging, and basic machine learning text processing.\n\n---\n\n## Project Organization\n\n- **BasicUtils**\n  - `ConsoleTools` – Console color management (cache, restore, set).\n  - `CsvTools` – Synchronous and asynchronous CSV file loading, saving, and header extraction.\n  - `DateTimeTools` – Elapsed time and stopwatch formatting.\n  - `LogTools` – Simple file-based logging with timestamped entries.\n  - `MathTools` – Basic mathematical utilities for common operations.\n  - `MenuTools` – Console menu creation and management utilities.\n  - `MlTools` – Internal static list of common English stop words for text processing.\n  - `ObjectsTools` – Type checking and type name utilities for .NET objects.\n  - `SettingsTools` – Load application settings from JSON files into dictionaries or strongly-typed objects.\n  - `StringsTools` – String manipulation, console output helpers, random string generation, and input utilities.\n  - `ThreadingTools` – Basic threading utilities for task management and cancellation.\n\n\n\u003e **Note:** Obsolete methods (such as `MlTools.GetNgramsFromString`) are not documented here. Use the latest APIs in the `ML` namespace.\n\n---\n\n## Getting Started\n\n1. **Add the project or source files to your .NET 8 or .NET 9 solution.**\n2. **Reference the `BasicUtils` namespace in your code:**\n\n## StringExtensions Usage\n\nThe `StringExtensions` class provides a variety of extension methods for string manipulation, console output, and utility operations.  \nTo use these methods, add `using BasicUtils;` to your file.\n\n### Console Output\n```\n\"Hello, World!\".p(); // Prints to console without a line feed \n\"Hello, World!\".pl(); // Prints to console with a line feed\n\"Hello, World!\".Print(); // Prints with timestamp (default) \n\"Hello, World!\".Print(showTimeStamp: false, textColor: ConsoleColor.Green); // Prints in green, no timestamp\n\"Hello, World!\".PrintLine(); // Prints with line feed and timestamp (default) \n\"Hello, World!\".PrintLine(showTimeStamp: false); // Prints with line feed, no timestamp \n\"Hello, World!\".PrintLine(showTimeStamp: true, textColor: ConsoleColor.Yellow); // Prints in yellow with timestamp\n```\n\n\n### User Input\n```\n\"Press any key to continue...\".PressAnyKey(); // Shows prompt and waits for key press\nstring name = \"Enter your name: \".PrintForInput(); // Prompts and reads user input\n```\n\n### String Cleaning\n```\nstring cleaned = \"Hello, 123!\".RemoveNumbers(); // \"Hello, !\" \nstring noPunct = \"Hello, world!\".RemovePunctuation(); // \"Hello world\" \nstring noSymbols = \"A+B=C!\".RemoveSymbols(); // \"ABC\"\nstring noTabs = \"Hello\\tWorld\".RemoveTabs(); // \"Hello World\" \nstring singleSpaced = \"A   B   C\".RemoveMultipleSpaces(); // \"A B C\"\n```\n\n### Stop Words\n`string filtered = \"this is a test of the system\".RemoveStopWords(); // \"test system\"`\n\n### String Utilities\n`string repeated = \"abc\".Repeat(3); // \"abcabcabc\"`\n\n### Random String Generation\n```\n// (Assuming you expose a public method for random string generation) \nstring randomAlpha = StringExtensions.CreateRandomString(10, StringExtensions.RandomStringSettings.AlphaOnly); \nstring randomAll = StringExtensions.CreateRandomString(16, StringExtensions.RandomStringSettings.AlphaNumericSpecialWithSpaces);\n```\n\n\u003e **Note:** Some random string generation methods may be internal or obsolete; use the recommended public API.\n\n---\n\n**Tip:** All extension methods can be called directly on any string instance.\n\n---\n## ConsoleTools Usage\n\nThe `ConsoleTools` class provides static methods for managing console foreground and background colors, allowing you to cache, restore, and set colors for improved console UI control.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Color Management\n\n```\n// Cache the current foreground and background colors \nConsoleTools.CacheForeColor(); \nConsoleTools.CacheBgColor();\n\n// Set new colors \nConsoleTools.SetForeColor(ConsoleColor.Yellow); \nConsoleTools.SetBgColor(ConsoleColor.DarkBlue);\n// ... perform console output ...\n// Restore the original colors \nConsoleTools.RestoreCachedForeColor(); \nConsoleTools.RestoreCachedBgColor();\n```\n---\n\n**Tip:** These utilities help maintain consistent console appearance, especially when outputting colored text or building interactive console applications.\n\n---\n\n## CsvTools Usage\n\nThe `CsvTools` class provides methods for reading, writing, and processing CSV files, both synchronously and asynchronously.  \nTo use these methods, add `using BasicUtils;` to your file.\n\n### Loading CSV Data\n```\n// Load all rows from a CSV file (as arrays of strings) \nvar rows = CsvTools.Load(\"data.csv\");\n\n// Load CSV data with a custom delimiter and skip header \nvar rowsNoHeader = CsvTools.Load(\"data.csv\", delimiter: ';', hasHeader: false);\n\n// Asynchronously load CSV data \nvar rowsAsync = await CsvTools.LoadAsync(\"data.csv\");\n```\n\n\n### Saving CSV Data\n```\n// Save a list of string arrays to a CSV file \nCsvTools.Save(\"output.csv\", rows);\n\n// Save with a custom delimiter \nCsvTools.Save(\"output.csv\", rows, delimiter: ';');\n\n// Asynchronously save CSV data await \nCsvTools.SaveAsync(\"output.csv\", rows);\n```\n\n### Working with Raw CSV Lines\n```\n// Load raw lines from a CSV file (as strings) \nstring[] lines = CsvTools.LoadRawCsv(\"data.csv\");\n\n// Asynchronously load raw lines \nstring[] linesAsync = await CsvTools.LoadRawCsvAsync(\"data.csv\");\n```\n\n### Extracting Headers\n```\n// Load raw lines from a CSV file (as strings) \nstring[] lines = CsvTools.LoadRawCsv(\"data.csv\");\n\n// Asynchronously load raw lines \nstring[] linesAsync = await CsvTools.LoadRawCsvAsync(\"data.csv\");\n```\n\n```\n// Get headers from a CSV file \nstring[] headers = CsvTools.GetHeadersFromFile(\"data.csv\");\n\n// Asynchronously get headers \nstring[] headersAsync = await \nCsvTools.GetHeadersFromFileAsync(\"data.csv\");\n\n// Get headers from a raw CSV string array \nstring[] headersFromRaw = CsvTools.GetHeadersFromRawCsv(lines);\n```\n\n---\n\n**Tip:**  \n- All methods support custom delimiters (default is `,`).\n- Asynchronous methods are ideal for large files or UI applications.\n- Use `hasHeader: false` if your CSV does not include a header row.\n\n\n---\n\n## DateTimeTools Usage\n\nThe `DateTimeTools` class provides extension methods for formatting elapsed time and stopwatch durations, making it easy to display time intervals in a human-readable format.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Formatting Elapsed Time\n\n```\nlong ticks = 1234567890; string elapsed = ticks.ElapsedTime(); // \"00:20:34:56\" (HH:MM:SS:MS)\n```\n\n\n### Formatting Stopwatch Durations\n```\nvar sw = new System.Diagnostics.Stopwatch(); \nsw.Start(); \n\n// ... perform some work ... \n\nsw.Stop(); \nstring formatted = sw.TimeFormatted(); // \"00:00:01:23\" (HH:MM:SS:MS)\n```\n\n---\n\n**Tip:**  \n- These methods are useful for logging, benchmarking, and displaying durations in console or UI applications.\n- The format is always `\"HH:MM:SS:MS\"` for consistency.\n\n--- \n## LogTools Usage\n\nThe `LogTools` class provides simple file-based logging functionality, allowing you to write timestamped log entries to text files for diagnostics, auditing, or general application logging.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Writing Log Entries\n\n```\nLogTools.WriteToLog(@\"C:\\Logs\", \"Application started.\"); \nLogTools.WriteToLog(@\"C:\\Logs\", $\"Error occurred at {DateTime.Now}: {ex.Message}\");\n```\n\n- Each log entry is written to a file named with the current date (e.g., `06082025.txt`) in the specified directory.\n- Entries are separated by a line of equal signs and include a timestamp for each message.\n- If the log file does not exist, it is created automatically; otherwise, entries are appended.\n\n**Tip:**  \n- Use a dedicated log directory to keep your log files organized.\n- LogTools is ideal for lightweight logging needs in console and utility applications.\n\n---\n\n## MenuTools Usage\n\nThe `MenuTools` class provides utilities for creating and managing interactive console menus, making it easy to build user-friendly command-line interfaces.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Example Usage\n```\n// Define menu options \nvar options = new List\u003cstring\u003e { \"Option 1\", \"Option 2\", \"Option 3\", \"Exit\" };\n\n// Display a simple menu and get the user's selection \nint selectedIndex = MenuTools.ShowMenu(\"Main Menu\", options);\n\n// Act on the user's choice \nswitch (selectedIndex) \n{ \n\tcase 0: \n\t\t// Handle Option 1 \n\t\tbreak; \n\tcase 1: \n\t\t// Handle Option 2 \n\t\tbreak; \n\tcase 2: \n\t\t// Handle Option 3 \n\t\tbreak; \n\tcase 3: \n\t\t// Exit \n\t\tbreak; \n}\n```\n---\n\n**Tip:**  \n- MenuTools helps you quickly build navigable console menus for scripts, utilities, and interactive applications.\n- You can customize menu prompts, handle user input, and extend menu logic as needed.\n\n---\n\n## MlTools Usage\n\nThe `MlTools` class provides a static list of common English stop words for use in text processing and natural language applications.  \nThis is useful for filtering out non-informative words when performing tasks such as tokenization, keyword extraction, or building machine learning models.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Accessing the Stop Words List\n\n```\nvar stopWords = MlTools.StopWordsList; \nif (stopWords.Contains(\"the\")) { // \"the\" is a stop word }\n```\n\n\n### Example: Removing Stop Words from Text\n\n```\nvar words = \"this is a test of the system\".Split(' '); \nvar filtered = words.Where(word =\u003e !MlTools.StopWordsList.Contains(word)); \nstring result = string.Join(\" \", filtered); // \"test system\"\n```\n\n\n**Tip:**  \n- The stop words list is provided as a static string array for fast lookups.\n- Use this list to improve the quality of text analysis, search, and machine learning features by ignoring common words.\n\n---\n\n## ObjectsTools Usage\n\nThe `ObjectsTools` class provides utility methods for type checking and type name detection, making it easy to determine the type of an object at runtime and perform robust type validation.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Type Checking and Type Name Detection\n\n```\n// Determine the type name of an object \nstring typeName = ObjectsTools.GetTypeName(123.45); // \"double\"\n\n// Check if an object is a specific type \nbool isInt = ObjectsTools.IsInt(\"123\");         \n\nbool isLong = ObjectsTools.IsLong(123L);        \n\nbool isDouble = ObjectsTools.IsDouble(\"3.14\");  \n\nbool isFloat = ObjectsTools.IsFloat(1.23f);     \n\nbool isDecimal = ObjectsTools.IsDecimal(\"9.99\");\n\nbool isDateTime = ObjectsTools.IsDateTime(\"2025-06-08\"); \n\nbool isBool = ObjectsTools.IsBool(true);        \n\nbool isChar = ObjectsTools.IsChar('A');         \n\nbool isString = ObjectsTools.IsString(\"hello\"); \n\nbool isCurrency = ObjectsTools.IsCurrency(\"$12.34\"); \n```\n\n\n**Tip:**  \n- These methods are useful for dynamic data validation, parsing, and runtime type analysis.\n- All methods are static and can be called directly from the class.\n- `GetTypeName` returns a string such as `\"int\"`, `\"double\"`, `\"DateTime\"`, or `\"unknown\"` for unrecognized types.\n\n---\n\n## SettingsTools Usage\n\nThe `SettingsTools` class provides methods for loading application settings from JSON files into dictionaries or strongly-typed objects, making configuration management simple and robust.\n\nTo use these methods, add `using BasicUtils;` to your file.\n\n### Loading Settings as a Dictionary\n\n```\n// Load settings from a JSON file into a dictionary \nvar settings = SettingsTools.LoadSettings(\"appsettings.json\"); \nstring apiKey = settings[\"ApiKey\"];\n```\n\n\n### Loading Settings as a Strongly-Typed Object\n\n```\n// Define a settings class \n\npublic class MySettings \n{ public string ApiKey { get; set; } public int Timeout { get; set; } }\n\n// Load settings from a JSON file into a strongly-typed object \n\nvar mySettings = SettingsTools.LoadSettings\u003cMySettings\u003e(\"appsettings.json\"); \nstring apiKey = mySettings.ApiKey; \nint timeout = mySettings.Timeout;\n```\n---\n\n**Tip:**  \n- Use strongly-typed objects for compile-time safety and IntelliSense support.\n- Use the dictionary approach for dynamic or loosely-typed configuration scenarios.\n- The JSON file should be well-formed and match the structure of your settings class if using strong typing.\n- Don't be a moron and store credintials in these settings","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiefutch%2Fbasicutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamiefutch%2Fbasicutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamiefutch%2Fbasicutils/lists"}