Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: dotnet pack src/ColorHashSharp/ColorHashSharp.csproj --configuration Release --no-build --output artifacts -p:Version=$env:RELEASE_VERSION -p:PackageVersion=$env:RELEASE_VERSION

- name: Upload package
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@v6
with:
name: nuget-package
path: artifacts/ColorHashSharp.${{ steps.version.outputs.version }}.nupkg
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
dotnet-version: 11.0.x

- name: Download package
uses: actions/download-artifact@v4
uses: actions/download-artifact@v7
with:
name: nuget-package
path: artifacts
Expand Down
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# ColorHashSharp
# ColorHashSharp

Generate color based on the given string. C# port of [ColorHash Javascript Library](https://github.com/zenozeng/color-hash).

[![NuGet version (ColorHashSharp)](https://img.shields.io/nuget/v/ColorHashSharp.svg?style=flat-square)](https://www.nuget.org/packages/ColorHashSharp/)   [![NuGet Downloads](https://img.shields.io/nuget/dt/ColorHashSharp.svg)](https://www.nuget.org/packages/ColorHashSharp/)  

[![CodeFactor](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp/badge)](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/7b256a3706a2434e9984dfb9f0d3da93)](https://app.codacy.com/gh/fernandezja/ColorHashSharp/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![CodeFactor](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp/badge)](https://www.codefactor.io/repository/github/fernandezja/colorhashsharp)



[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml)  [![Build status](https://fernandezja.visualstudio.com/ColorHashSharp/_apis/build/status/ColorHashSharp-CI)](https://fernandezja.visualstudio.com/ColorHashSharp/_build/latest?definitionId=4)
[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml)


#### Status
Expand All @@ -18,9 +19,18 @@ Generate color based on the given string. C# port of [ColorHash Javascript Libra
|CI |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg?branch=main)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml) |[![CI](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml/badge.svg?branch=develop)](https://github.com/fernandezja/ColorHashSharp/actions/workflows/ci-dotnet.yml) |


#### Basic
## Installation

```sh
dotnet add package ColorHashSharp
```

## Basic usage

```csharp
using System.Diagnostics;
using Fernandezja.ColorHashSharp;

Debug.WriteLine($"ColorHash > Hello World");

var colorHash = new ColorHash();
Expand Down Expand Up @@ -85,7 +95,7 @@ passed to a custom hash.

### Publishing to NuGet.org

[Publish to NuGet](.github/workflows/publish-nuget.yml) builds and tests each release before packing it. The package version comes from the tag without its leading `v`. Use a stable tag such as `v2.0.0` or a prerelease tag such as `v2.0.0-rc.1`. Omit build metadata (`+...`) because NuGet.org normalizes it out of version identifiers.
[Publish to NuGet](https://github.com/fernandezja/ColorHashSharp/blob/main/.github/workflows/publish-nuget.yml) builds and tests each release before packing it. The package version comes from the tag without its leading `v`. Use a stable tag such as `v2.0.0` or a prerelease tag such as `v2.0.0-rc.1`. Omit build metadata (`+...`) because NuGet.org normalizes it out of version identifiers.

1. In GitHub, open **Settings → Environments → nuget**. Under **Environment variables**, set `NUGET_USER` to the NuGet.org profile name `fernandezja`. Under **Deployment branches and tags**, select **Selected branches and tags** and add a **Tag** rule for `v*.*.*`.
2. On [NuGet.org → Trusted Publishing](https://www.nuget.org/account/trustedpublishing), add a GitHub Actions policy named `ColorHashSharp GitHub Actions` for the package owner. Set **Repository Owner** to `fernandezja`, **Repository** to `ColorHashSharp`, **Workflow File** to `publish-nuget.yml`, and **Environment** to `nuget`. Select **Push only new package versions** and enter `ColorHashSharp` under **Glob Patterns and Packages**. The workflow exchanges its OIDC token for a short-lived API key when the package is ready to publish.
Expand All @@ -97,3 +107,7 @@ passed to a custom hash.
```

Check **Actions → Publish to NuGet** for the result, then verify the version on the [ColorHashSharp package page](https://www.nuget.org/packages/ColorHashSharp/).

## Feedback and contributions

Report issues and suggest improvements on [GitHub](https://github.com/fernandezja/ColorHashSharp/issues). Contributions are welcome through [pull requests](https://github.com/fernandezja/ColorHashSharp/pulls).
Binary file added assets/icon/ColorHashSharp-40x40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/ColorHashSharp.Tests/ColorConversionEdgeCasesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ public void TransformSaturationAndBrightness_ExtremeValues()
5.0,
5.0);

Assert.NotNull(result);
var expected = SimpleColorTransforms.HsBtoRgb(210, 1, 1);
Assert.Equal(expected, result);
}

#endregion
Expand Down
1 change: 0 additions & 1 deletion src/ColorHashSharp.Tests/ColorToRgbTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public void ToRgb1_AllSectors_ShouldConvert(double hue)
{
var result = ColorToRgb.ToRgb1(hue, 1, 0.5);

Assert.NotNull(result);
Assert.Equal(255, result.A);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ColorHashSharp.Tests/SimpleColorTransformsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public void TransformSaturationAndBrightness_ZeroSaturationWithIncrease_ShouldIn
2.0,
1.0);

Assert.NotNull(result);
Assert.True(result.GetSaturation() > color.GetSaturation());
}

[Fact(DisplayName = "TransformSaturationAndBrightness_ZeroBrightnessWithIncrease_ShouldIncrease")]
Expand All @@ -397,7 +397,7 @@ public void TransformSaturationAndBrightness_ZeroBrightnessWithIncrease_ShouldIn
1.0,
2.0);

Assert.NotNull(result);
Assert.True(result.GetBrightness() > color.GetBrightness());
}

[Fact(DisplayName = "TransformSaturationAndBrightness_WithCustomAlpha_ShouldSetAlpha")]
Expand Down
4 changes: 3 additions & 1 deletion src/ColorHashSharp/ColorHashSharp.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net48;net481;net10.0;net11.0</TargetFrameworks>
Expand All @@ -13,6 +13,7 @@
<License>https://licenses.nuget.org/MIT</License>
<PackageProjectUrl></PackageProjectUrl>
<PackageIcon>ColorHashSharp-icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryUrl>https://github.com/fernandezja/ColorHashSharp</RepositoryUrl>
<PackageTags>color hash string hsl hex hexadecimal</PackageTags>
<PackageReleaseNotes>Generate color based on the given string. C# port of ColorHash Javascript Library. See https://github.com/fernandezja/ColorHashSharp</PackageReleaseNotes>
Expand All @@ -28,5 +29,6 @@
</ItemGroup>
<ItemGroup>
<None Include="Images\ColorHashSharp-icon.png" Pack="true" PackagePath=""/>
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
</ItemGroup>
</Project>