aboutsummaryrefslogtreecommitdiff
path: root/lib/arguments/tinyColor.ts
blob: 148c078a44b47b34f08530ae83bb34f7b8fdad8b (plain)
1
2
3
4
5
6
7
8
9
10
import type { BushArgumentTypeCaster } from '#lib';
import assert from 'assert/strict';
import tinycolorModule from 'tinycolor2';
assert(tinycolorModule);

export const tinyColor: BushArgumentTypeCaster<string | null> = (_message, phrase) => {
	// if the phase is a number it converts it to hex incase it could be representing a color in decimal
	const newPhase = isNaN(phrase as any) ? phrase : `#${Number(phrase).toString(16)}`;
	return tinycolorModule(newPhase).isValid() ? newPhase : null;
};