Trivial 9.0.0-preview6

This is a prerelease version of Trivial.
There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Trivial --version 9.0.0-preview6                
NuGet\Install-Package Trivial -Version 9.0.0-preview6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Trivial" Version="9.0.0-preview6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Trivial --version 9.0.0-preview6                
#r "nuget: Trivial, 9.0.0-preview6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Trivial as a Cake Addin
#addin nuget:?package=Trivial&version=9.0.0-preview6&prerelease

// Install Trivial as a Cake Tool
#tool nuget:?package=Trivial&version=9.0.0-preview6&prerelease                

Trivial

Includes utilities and services for tasks, security, JSON, etc.

Tasks

using Trivial.Tasks;

Interceptor

Set an action with a specific interceptor to control its execution.

  • Interceptor.Debounce: Request to invoke a specific action several times in a short time but only the last one should be executed and previous ones should be ignored. A sample is real-time search suggestion.
  • Interceptor.Throttle: Raise actually only once in a short time even if invoke several times. A sample is the submit button in a form.
  • Interceptor.Times: The action can be only executed only when invoke in the specific times range and others will be ignored. A sample is double click.
  • Interceptor.Multiple: A handler to execute for the specific times and the state will be reset after a while.
// Set an action with interceptor.
var action = Interceptor.Debounce(() =>
{
    // Do something...
}, TimeSpan.FromMilliseconds(200));

// Invoke somewhere.
action();

Retry

Create a linear retry policy by LinearRetryPolicy or a customized one to process an action with the specific retry policy. And you can use ObservableTask to observe the state of an action processing.

Network

Contains the helper functions and extension functions for network, such as HTTP web client and its content.

using Trivial.Net;

Use JsonHttpClient to serialize the JSON format response with additional retry policy. And HttpUri for HTTP URI fields accessing.

Security

using Trivial.Security;

Access token

Provide a set of tools for OAuth including following models.

  • TokenInfo The access token and other properties.
  • AppAccessingKey The app identifier and secret key.
  • OAuthClient The token container with the ability to resolve the access token and create the JSON HTTP web client to access the resources required authentication.

Optional to implement the OAuthBasedClient base class to create your own business HTTP web client factory with OAuth supports.

JWT

Create a JSON web token to get the string encoded by initializing a new instance of the JsonWebToken class or the JsonWebTokenParser class.

var sign = HashSignatureProvider.CreateHS512("a secret string");
var jwt = new JsonWebToken<JsonWebTokenPayload>(new JsonWebTokenPayload
{
    Id = Guid.NewGuid().ToString("n"),
    Issuer = "example"
}, sign);

// Get authenticiation header value.
var header = jwt.ToAuthenticationHeaderValue();

// Parse.
var jwtSame = JsonWebToken<Model>.Parse(jwtStr, sign); // jwtSame.ToEncodedString() == header.Parameter

RSA

Convert a PEM (OpenSSL RSA key) or an XML string to the RSAParameters struct.

var parameters = RSAParametersConvert.Parse(pem);

And convert back by extension method ToPrivatePEMString or ToPublicPEMString. Or to XML by extension method ToXElement.

Symmetric & Hash

Use a symmetric algorithm to encrypt and decrypt a string by calling SymmetricUtilities.Encrypt and SymmetricUtilities.DecryptText functions.

For hash algorithm, you can call HashUtilities.ToHashString function to get hash from a plain string and call HashUtilities.Verify to verify.

Secure string

Convert the secret between SecureString and String/StringBuilder/Byte[] by the SecureStringExtensions class.

And class RSASecretExchange is used to transfer the secret by RSA encryption.

Text

using Trivial.Text;

JSON

Includes writable JSON DOM JsonObjectNode and JsonArrayNode. And includes lots of useful converter like following.

  • JsonJavaScriptTicksConverter and its fallback converters to convert DateTime from/to JavaScript ticks number in JSON.
  • JsonUnixTimestampConverter and its fallback converters to convert DateTime from/to Unix timestamp number in JSON.
  • JsonNumberConverter and JsonNumberConverter.NumberStringConverter, to read number string in JSON.
  • JsonStringListConverter and its character separated converters (such as JsonStringListConverter.WhiteSpaceSeparatedConverter) to convert a string list from/to a string in JSON.

CSV

Read CSV or TSV file into a list of the specific models. For example, you have a model class CsvModel with string properties A and B, now you can map to the CSV file.

var csv = new CsvParser("abcd,efg\nhijk,lmn");
foreach (var model in csv.ConvertTo<CsvModel>(new[] { "A", "B" }))
{
    Console.WriteLine("{0},{1}", model.A, model.B);
}

Data

using Trivial.Data;

Cache

Save a number of model in memory cache by generic class DataCacheCollection.

Drawing

using Trivial.Drawing;

Color calculator

Color adjustment, converter, parser and mixer.

var color = ColorCalculator.Parse("rgb(226, 37, 0xA8)");
color = ColorCalculator.Opacity(color, 0.9);
color = ColorCalculator.Saturate(color, RelativeSaturationLevels.High);
color = ColorCalculator.Mix(ColorMixTypes.Lighten, color, Color.FromArgb(0, 240, 0));

Mathematics

using Trivial.Maths;

Arithmetic

There are a lot of arithmetic functions.

Arithmetic.IsPrime(2147483647); // True
Arithmetic.Gcd(192, 128); // 64

Numerals

Get the number symbols as you want. And get the numerals in English.

EnglishNumerals.Default.ToString(12345.67);
// twelve thousand three hundred and forty-five point six seven

EnglishNumerals.Default.ToApproximationString(1234567);
// 1.2M

And ChineseNumerals for Chinese and JapaneseNumerals for Japanese.

Angle and polar point

  • Angle Angle.
  • PolarPoint The point in polar coordinates.
  • SphericalPoint The point in spherical coordinates.

Set

  • NullableValueSimpleInterval<T> Interval, such as [20, 100).

Rectangular coordinates

  • IntPoint1D DoublePoint1D The point in 1D (line) coordinates.
  • IntPoint2D DoublePoint2D The point in 2D (flat) coordinates.
  • IntPoint3D DoublePoint3D The point in 3D (stereoscophic) coordinates.
  • SpacetimePoint The point in 4D (spacetime) coordinates.

Further

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible. 
.NET Framework net461 is compatible.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (10)

Showing the top 5 NuGet packages that depend on Trivial:

Package Downloads
Trivial.Console

The console utilities and rich user interface console.

Trivial.WindowsKit

Some advanced visual controls and utilities for Windows app.

NuScien

A core library of NuScien framework which provides a solution to build community and enterprise projects based on resource entity and accessories with ACL and CMS built-in.

Trivial.Chemistry

A library with basic chemical models.

Trivial.Web

A library for web API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.1.0 100 12/24/2024
9.0.0 167 12/12/2024
8.0.0 1,242 6/12/2024
7.2.0 2,868 11/16/2023 7.2.0 is deprecated because it is no longer maintained.
7.1.2 1,401 5/10/2023 7.1.2 is deprecated because it is no longer maintained.
7.1.1 449 5/10/2023 7.1.1 is deprecated because it is no longer maintained.
7.1.0 611 5/8/2023 7.1.0 is deprecated because it is no longer maintained.
7.0.0 1,432 1/20/2023 7.0.0 is deprecated because it is no longer maintained.
6.6.0 3,690 11/9/2022
6.5.6 1,322 10/10/2022 6.5.6 is deprecated because it is no longer maintained.
6.5.5 664 10/9/2022 6.5.5 is deprecated because it is no longer maintained.
6.5.4 1,058 8/10/2022 6.5.4 is deprecated because it is no longer maintained.
6.5.0 735 6/17/2022 6.5.0 is deprecated because it is no longer maintained.
6.4.0 2,858 4/14/2022 6.4.0 is deprecated because it is no longer maintained.
6.3.0 2,038 3/8/2022 6.3.0 is deprecated because it is no longer maintained.
6.2.0 4,668 1/30/2022 6.2.0 is deprecated because it is no longer maintained.
6.1.0 1,944 1/23/2022 6.1.0 is deprecated because it is no longer maintained.
6.0.0 1,486 1/1/2022 6.0.0 is deprecated because it is no longer maintained.
5.2.0 5,006 12/15/2021 5.2.0 is deprecated because it is no longer maintained.
5.1.1 655 12/3/2021 5.1.1 is deprecated because it is no longer maintained.
5.1.0 1,417 12/2/2021 5.1.0 is deprecated because it is no longer maintained.
5.0.0 1,439 11/27/2021 5.0.0 is deprecated because it is no longer maintained.
4.0.0 1,147 11/9/2021 4.0.0 is deprecated because it is no longer maintained.
3.9.0 1,524 12/15/2021 3.9.0 is deprecated because it is no longer maintained.
3.8.0 1,288 11/9/2021 3.8.0 is deprecated because it is no longer maintained.
3.7.2 9,519 4/22/2021 3.7.2 is deprecated because it is no longer maintained.
3.7.0 1,669 3/17/2021 3.7.0 is deprecated because it is no longer maintained.
3.6.2 977 3/17/2021 3.6.2 is deprecated because it is no longer maintained.
3.6.0 7,378 11/12/2020 3.6.0 is deprecated because it is no longer maintained.
3.5.2 7,865 4/13/2020 3.5.2 is deprecated because it is no longer maintained.
3.5.1 1,530 4/12/2020 3.5.1 is deprecated because it is no longer maintained.
3.5.0 1,513 4/1/2020 3.5.0 is deprecated because it is no longer maintained.
3.4.3 1,447 3/20/2020 3.4.3 is deprecated because it is no longer maintained.
3.4.2 1,408 3/12/2020 3.4.2 is deprecated because it is no longer maintained.
3.4.1 1,454 2/25/2020 3.4.1 is deprecated because it is no longer maintained.
3.4.0 1,749 2/20/2020 3.4.0 is deprecated because it is no longer maintained.
3.3.0 1,833 2/14/2020 3.3.0 is deprecated because it is no longer maintained.
3.2.0 2,147 1/22/2020 3.2.0 is deprecated because it is no longer maintained.
3.1.0 2,193 12/30/2019 3.1.0 is deprecated because it is no longer maintained.
3.0.1 2,052 12/26/2019 3.0.1 is deprecated because it is no longer maintained.
2.2.0 1,219 2/19/2020 2.2.0 is deprecated because it is no longer maintained.
2.1.0 1,743 12/24/2019 2.1.0 is deprecated because it is no longer maintained.
2.0.3 1,602 12/3/2019 2.0.3 is deprecated because it is no longer maintained.
1.2.0 31,810 5/20/2019 1.2.0 is deprecated because it is no longer maintained.
1.1.0 2,189 5/8/2019 1.1.0 is deprecated because it is no longer maintained.
1.0.0 4,216 5/1/2019 1.0.0 is deprecated because it is no longer maintained.