aboutsummaryrefslogtreecommitdiff
path: root/lib/arguments/tinyColor.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arguments/tinyColor.ts')
-rw-r--r--lib/arguments/tinyColor.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/arguments/tinyColor.ts b/lib/arguments/tinyColor.ts
new file mode 100644
index 0000000..148c078
--- /dev/null
+++ b/lib/arguments/tinyColor.ts
@@ -0,0 +1,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;
+};