ciu-parser
3.0.0
dotnet add package ciu-parser --version 3.0.0
NuGet\Install-Package ciu-parser -Version 3.0.0
<PackageReference Include="ciu-parser" Version="3.0.0" />
<PackageVersion Include="ciu-parser" Version="3.0.0" />
<PackageReference Include="ciu-parser" />
paket add ciu-parser --version 3.0.0
#r "nuget: ciu-parser, 3.0.0"
#:package ciu-parser@3.0.0
#addin nuget:?package=ciu-parser&version=3.0.0
#tool nuget:?package=ciu-parser&version=3.0.0
Uri Credential Parser
A lightweight .NET library for parsing Credential-in-URL connection strings (e.g., scheme://user:password@host:port/database?options) into structured objects, and converting them into Npgsql (PostgreSQL) or MongoDB connection strings.
Features
- Parse complex database URIs into structured
ConnectionParameters. - Support for multiple schemes (PostgreSQL, MongoDB, etc.).
- Convert parsed parameters to standard connection strings for Npgsql and MongoDB.
- Handles query parameters as a dictionary.
- Lightweight and targets
.NET Standard 2.0. - Utilises C# 14 Extension Types for a clean and intuitive API.
Installation
NuGet
dotnet add package ciu-parser
Quick Start
using UriCredentialParser;
// Parse a connection URI
var details = CredentialsParser.Parse(
"postgres://admin:secret@localhost:5432/testdb?timeout=30&sslmode=require");
Console.WriteLine(details.HostName); // localhost
Console.WriteLine(details.UserName); // admin
Console.WriteLine(details.AdditionalQueryParameters["timeout"]); // 30
PostgreSQL (Npgsql)
using UriCredentialParser;
using UriCredentialParser.Enums;
var connString = details.ToNpgsqlConnectionString(
pooling: true,
sslMode: PostgresSSLMode.Prefer
);
MongoDB
using UriCredentialParser;
var (databaseUrl, databaseName) = details.ToMongoConnectionSplit();
// databaseUrl: mongodb://admin:secret@localhost:5432?timeout=30&sslmode=require
// databaseName: testdb
Parsing Rules
CredentialsParser.Parse expects a valid absolute URI.
| Part of URL | Property | Description |
|---|---|---|
scheme |
Scheme |
e.g., postgres, mongodb, redis |
user:pass |
UserName / Password |
Extracted from UserInfo |
host |
HostName |
Server address |
port |
Port |
Numeric port or null if omitted |
/path |
DatabasePath |
The path segment (usually database name) |
?query |
AdditionalQueryParameters |
A Dictionary<string, string> of options |
ConnectionParameters Record
The ConnectionParameters record encapsulates the parsed data:
Scheme: The URI scheme.HostName: The server host.UserName/Password: Credentials (defaults to empty strings if missing).DatabasePath: The database name or path.Port: The port number (int?).AdditionalQueryParameters: A dictionary of all query parameters.
Relationship to other packages
This library supersedes the narrower PostgresConnString.NET and mongo-url-parser packages with a single, shared parser and typed exports.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development
To build and test the project:
cd src
dotnet build UriCredentialParser.slnx
dotnet test
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- changes asembly and lib name to be more intuitive.
- Update target framework to adjust to .NEt recommendations