-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [WIP] deno * [WIP] deno test; add sha256 for #27, for #30 * style: const range * style: color-hash.ts -> mod.ts * refactor: deno test for class ColorHash * feature: use sha256 as default hash function, fixes #27, fixes #30 * chore: Makefile * chore: package-lock.json * chore: make build * chore: update ci * chore(workflows): setup deno with version 1.x * chore: update ci * chore: update ci * docs: update usage
- Loading branch information
Showing
36 changed files
with
372 additions
and
4,295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.lint": true, | ||
"deno.unstable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test: | ||
deno test | ||
|
||
build: | ||
mkdir -p dist | ||
deno bundle mod.ts > dist/bundle.js | ||
npx tsc --allowJs dist/bundle.js --outDir tmp | ||
cp tmp/bundle.js dist/color-hash.js | ||
rm -rf tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {assertEquals, assert} from 'https://deno.land/[email protected]/testing/asserts.ts'; | ||
import {generate as generateUUID} from 'https://deno.land/[email protected]/uuid/v4.ts'; | ||
import {HSL2RGB, RGB2HEX} from './lib/colors.ts'; | ||
import ColorHash from './mod.ts'; | ||
|
||
Deno.test("ColorHash#Hue: should return the hash color based on default hue", () => { | ||
const hash = new ColorHash(); | ||
for (let i = 0; i < 100; i++) { | ||
const hue = hash.hsl(generateUUID())[0]; | ||
assertEquals(hue >= 0 && hue < 359, true); // hash % 359 means max 358 | ||
} | ||
}) | ||
|
||
Deno.test("ColorHash#Hue: should return the hash color based on given hue value", () => { | ||
const hash = new ColorHash({hue: 10}); | ||
for (let i = 0; i < 100; i++) { | ||
const hue = hash.hsl(generateUUID())[0]; | ||
assertEquals(hue, 10); | ||
} | ||
}) | ||
|
||
Deno.test("ColorHash#Hue: should return the hash color based on given hue range", () => { | ||
for (let min = 0; min < 361; min += 60) { | ||
for (let max = min + 1; max < 361; max += 60) { | ||
const hash = new ColorHash({hue: {min, max}}); | ||
for (let i = 0; i < 100; i++) { | ||
const hue = hash.hsl(generateUUID())[0]; | ||
assertEquals(hue >= min && hue < max, true); | ||
} | ||
} | ||
} | ||
}) | ||
|
||
Deno.test("ColorHash#Hue: should work for multiple hue ranges", () => { | ||
var ranges = [ | ||
{min: 30, max: 90}, | ||
{min: 180, max: 210}, | ||
{min: 270, max: 285} | ||
]; | ||
const hash = new ColorHash({hue: ranges}); | ||
for (let i = 0; i < 100; i++) { | ||
const hue = hash.hsl(generateUUID())[0]; | ||
assertEquals(ranges.some((range) => hue >= range.min && hue < range.max), true); | ||
} | ||
}) | ||
|
||
Deno.test("ColorHash#LS: should return color based on given lightness and saturation", () => { | ||
const hash = new ColorHash({lightness: 0.5, saturation: 0.5}); | ||
const [h, s, l] = hash.hsl(generateUUID()); | ||
assertEquals(s, 0.5); | ||
assertEquals(l, 0.5); | ||
}) | ||
|
||
Deno.test("ColorHash should return the hash color based on given lightness array and saturation array", () => { | ||
const hash = new ColorHash({ | ||
lightness: [0.9, 1], | ||
saturation: [0.9, 1] | ||
}) | ||
const [h, s, l] = hash.hsl(generateUUID()); | ||
assertEquals([0.9, 1].includes(s), true); | ||
assertEquals([0.9, 1].includes(l), true); | ||
}) | ||
|
||
Deno.test("Custom hash function", () => { | ||
const customHash = function (str: string) { | ||
var hash = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
hash += str.charCodeAt(i); | ||
} | ||
return hash; | ||
}; | ||
|
||
const hash = new ColorHash({hash: customHash}); | ||
const h = customHash('abc') % 359; | ||
|
||
assertEquals(hash.hsl('abc')[0], h); | ||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.