mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-18 15:00:00 +00:00
18 lines
618 B
TypeScript
18 lines
618 B
TypeScript
![]() |
import * as t from "io-ts";
|
||
|
import { either } from "fp-ts/lib/Either";
|
||
|
import { convertDelayStringToMS } from "../utils";
|
||
|
import { parseColor } from "./parseColor";
|
||
|
import { rgbToInt } from "./rgbToInt";
|
||
|
import { intToRgb } from "./intToRgb";
|
||
|
|
||
|
export const tColor = new t.Type<number, string>(
|
||
|
"tColor",
|
||
|
(s): s is number => typeof s === "number",
|
||
|
(from, to) =>
|
||
|
either.chain(t.string.validate(from, to), input => {
|
||
|
const parsedColor = parseColor(input);
|
||
|
return parsedColor == null ? t.failure(from, to, "Invalid color") : t.success(rgbToInt(parsedColor));
|
||
|
}),
|
||
|
s => intToRgb(s).join(","),
|
||
|
);
|