Skip to content

Commit

Permalink
README file update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Felis committed May 21, 2021
1 parent 359d606 commit e53fc18
Showing 1 changed file with 108 additions and 16 deletions.
124 changes: 108 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
# DotNetColorParser

[![Build Status](https://robolynx.visualstudio.com/DotNetColorParser/_apis/build/status/sebafelis.DotNetColorParser?branchName=main)](https://robolynx.visualstudio.com/DotNetColorParser/_build/latest?definitionId=6&branchName=main)
[![DotNetColorParser NuGet Package](https://img.shields.io/nuget/v/DotNetColorParser)](https://www.nuget.org/packages/DotNetColorParser/)
[![DotNetColorParser.Abstractions NuGet Package](https://img.shields.io/nuget/v/DotNetColorParser.Abstractions)](https://www.nuget.org/packages/DotNetColorParser.Abstractions/)
![Coverage](https://img.shields.io/azure-devops/coverage/robolynx/DotNetColorParser/6/main)

.Net library parsing strings with notated colors and converting them to .Net Color object. Library support almost all color notations used in CSS3. Color notations are extendable and customizable.

### NuGet's

[![DotNetColorParser NuGet Package](https://img.shields.io/nuget/v/DotNetColorParser?label=nuget:DotNetColorParser)](https://www.nuget.org/packages/DotNetColorParser/)

[![DotNetColorParser.Abstractions NuGet Package](https://img.shields.io/nuget/v/DotNetColorParser.Abstractions?label=nuget:DotNetColorParser.Abstractions)](https://www.nuget.org/packages/DotNetColorParser.Abstractions/)


## Usage

### Static methods

#### Any color notation
#### Many color notations

You can use static method witch converts string with any correct color notation supported by default. e.g:
You can use static method witch converts string with any correct color notation supporting by default. e.g:

```c#
string stringWithColor = "rgba(255,0,128,0.5)";

var color = ColorParser.Parse(stringWithColor);
```

In that case method try parse string using all notations added to `ColorParser.DefaultProvider` collection. This object by default contains all standard color notations.
In that case method parse string using all notations added to `ColorParser.DefaultProvider` collection. This object by default contains all build in color notations.

#### Specify color notation only

If you wont to parser only one specify notation then you can write:
If you wont to parser support only one specify notation then you can write:

```c#
string stringWithColor = "#ff008080";
Expand All @@ -42,12 +47,12 @@ You can add custom color notation support by adding to `ColorParser.DefaultProvi
To customize supported by default color notations you can set to `ColorParser.DefaultProvider` new ColorNotationProvider class instance.

```c#
ColorParser.DefaultProvider = new ColorNotationProvider() { HexRGBANotation, RGBANotation, RGBNotation };
ColorParser.DefaultProvider = new ColorNotationProvider() { HexRGBANotation, RGBANotation, RGBNotation, CustomNotation };
```

### Class instance

You can dynamically create new instance of ColorParser class and configure supported notations by passing ColorNotationProvider object into constructor.
You can dynamically create new instance of ColorParser class and configure supporting notations by passing ColorNotationProvider object into constructor.

```c#
var colorParser = new ColorParser(new ColorNotationProvider() { HexRGBANotation, RGBANotation, RGBNotation });
Expand Down Expand Up @@ -102,14 +107,101 @@ All this notations are default added to ColorNotationProvider.

| Class name | Description | Syntax | e.g. |
| :------------------- | :----------- | ------------------- | :---- |
| KnownColorNameNotation | Color names in English containing by [KnownColor](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor?view=net-5.0&viewFallbackFrom=netstandard-2.0) enumerable object. It's contains all color names using by browsers. Colors are in RGB color space. Every color corresponding specify RBG value. | `colorname` | `silver`, `blue`, `black`, `green`, `yellow`, `darkblue` |
| HexRGBANotation | RGB or RGBA color expressed through hexadecimal value with # prefix (prefix not necessary to correct recognition). Color can be expressed as three, six or eight hexadecimal characters (0–9, A–F). | `#RRGGBB[AA]`<br />`#RGB[A]` | `#FFFFFF`, `#abc`, `#20ee33`, `#ff1250cc` |
| RGBNotation | [RGB color](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb_colors)| **Syntax 1:** rgb(R, G, B)<br />**Syntax 2:** rgb R G B | `rgb(255,255,0)`, `rgb( 255, 255, 255 )` |
| RGBANotation | The same as RGBNotation but with additional alpha channel. | **Syntax 1:** rgba(R, G, B, A)<br />**Syntax 2:** rgba R G B A<br />**Syntax 3:** rgba R G B / A<br />**Syntax 4:** rgba(R G B / A) | `rgba(255,255,0,0.5)`, `rgba( 255, 255, 255, 100% )` |
| HSLNotation | [HSLA color space](https://en.wikipedia.org/wiki/HSL_and_HSV) | **Syntax 1:** `hsl(hue, spectrum, lightness)`<br />**Syntax 2:** `hsl hue, spectrum, lightness`<br />**Syntax 4:** `hsla(hue spectrum lightness)`<br /><br /> | `hsla(180,50%,50%,0.5)`, `hsla(180,50%,50%,30%)`, `hsla(180deg,50%,50%,30%)`, `hsla(4rad,50%,50%,30%)`, `hsla(4ang,50%,50%,30%)`,`hsla 180,50%,50%,0.5`, `hsla 180 50% 50% 0.5`, `hsla 180 50% 50% / 0.5`
| HSLANotation | The same as HSLNotation but with additional alpha channel. | **Syntax 1:** `hsla(hue, spectrum, lightness, alpha)`<br />**Syntax 2:** `hsla hue, spectrum, lightness / alpha`<br />**Syntax 3:** `hsla hue spectrum lightness alpha`<br />**Syntax 4:** `hsla(hue spectrum lightness alpha)` | `hsla(180,50%,50%,0.5)`, `hsla(180,50%,50%,30%)`, `hsla(180deg,50%,50%,30%)`, `hsla(4rad,50%,50%,30%)`, `hsla(4ang,50%,50%,30%)`,`hsla 180,50%,50%,0.5`, `hsla 180 50% 50% 0.5`, `hsla 180 50% 50% / 0.5`
| HSVNotation | [HSVA color space](https://en.wikipedia.org/wiki/HSL_and_HSV) | **Syntax 1:** `hsla(hue, spectrum, lightness, alpha)`<br />**Syntax 2:** `hsla hue, spectrum, lightness / alpha`<br />**Syntax 3:** `hsla hue spectrum lightness alpha`<br />**Syntax 4:** `hsla(hue spectrum lightness alpha)` | `hsla(180,50%,50%,0.5)`, `hsla(180,50%,50%,30%)`, `hsla(180deg,50%,50%,30%)`, `hsla(4rad,50%,50%,30%)`, `hsla(4ang,50%,50%,30%)`,`hsla 180,50%,50%,0.5`, `hsla 180 50% 50% 0.5`, `hsla 180 50% 50% / 0.5`

### 1. **KnownColorNameNotation**
#### Description
Color names in English containing by [KnownColor](https://docs.microsoft.com/en-us/dotnet/api/system.drawing.knowncolor?view=net-5.0&viewFallbackFrom=netstandard-2.0) enumerable object. It's contains all color names using by browsers. Colors are in RGB color space. Every color corresponding specify RBG value.
#### Syntax
`colorname`
#### Samples
* `silver`
* `blue`
* `black`
* `green`
* `yellow`
* `darkblue`
### 2. HexRGBANotation
#### Description
RGB or RGBA color expressed through hexadecimal value with # prefix (prefix not necessary to correct recognition). Color can be expressed as three, six or eight hexadecimal characters (0–9, A–F).
#### Syntax
1. `#RRGGBB[AA]`
1. `#RGB[A]`
#### Samples
* `#FFFFFF`
* `#abc`
* `#20ee33`
* `#ff1250cc`
### 3. RGBNotation
#### Description
[RGB color](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#rgb_colors)
#### Syntax
1. rgb(R, G, B)
1. rgb R G B
#### Samples
* `rgb(255,255,0)`
* `rgb( 255, 255, 255 )`
### 4. RGBANotation
#### Description
The same as RGBNotation but with additional alpha channel.
#### Syntax
1. rgba(R, G, B, A)
1. rgba R G B A
1. rgba R G B / A
1. rgba(R G B / A)
#### Samples
* `rgba(255,255,0,0.5)`
* `rgba( 255, 255, 255, 100% )`
### 5. HSLNotation
#### Description
[HSLA color space](https://en.wikipedia.org/wiki/HSL_and_HSV)
#### Syntax
1. `hsl(hue, spectrum, lightness)`
2. `hsl hue, spectrum, lightness`
3. `hsla(hue spectrum lightness)`
#### Samples
* `hsla(180,50%,50%,0.5)`
* `hsla(180,50%,50%,30%)`
* `hsla(180deg,50%,50%,30%)`
* `hsla(4rad,50%,50%,30%)`
* `hsla(4ang,50%,50%,30%)`
* `hsla 180,50%,50%,0.5`
* `hsla 180 50% 50% 0.5`
* `hsla 180 50% 50% / 0.5`
### 6. HSLANotation
#### Description
The same as HSLNotation but with additional alpha channel.
#### Syntax
1. `hsla(hue, spectrum, lightness, alpha)`
1. `hsla hue, spectrum, lightness / alpha`
1. `hsla hue spectrum lightness alpha`
1. `hsla(hue spectrum lightness alpha)`
#### Samples
* `hsla(180,50%,50%,0.5)`
* `hsla(180,50%,50%,30%)`
* `hsla(180deg,50%,50%,30%)`
* `hsla(4rad,50%,50%,30%)`
* `hsla(4ang,50%,50%,30%)`
* `hsla 180,50%,50%,0.5`
* `hsla 180 50% 50% 0.5`
* `hsla 180 50% 50% / 0.5`
### 7. HSVNotation
#### Description
[HSVA color space](https://en.wikipedia.org/wiki/HSL_and_HSV)
#### Syntax
1. `hsla(hue, spectrum, lightness, alpha)`
2. `hsla hue, spectrum, lightness / alpha`
3. `hsla hue spectrum lightness alpha`
4. `hsla(hue spectrum lightness alpha)`
#### Syntax
* `hsla(180,50%,50%,0.5)`
* `hsla(180,50%,50%,30%)`
* `hsla(180deg,50%,50%,30%)`
* `hsla(4rad,50%,50%,30%)`
* `hsla(4ang,50%,50%,30%)`
* `hsla 180,50%,50%,0.5`
* `hsla 180 50% 50% 0.5`
* `hsla 180 50% 50% / 0.5`

-------------
**R** (red), **G** (green), **B** (blue) - number between 0 and 255.

**A** - decimal number between 0 and 1 or percentage value between 0% and 100%
Expand Down

0 comments on commit e53fc18

Please sign in to comment.