summaryrefslogtreecommitdiff
path: root/resources/js/helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/helpers.js')
-rw-r--r--resources/js/helpers.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/resources/js/helpers.js b/resources/js/helpers.js
new file mode 100644
index 0000000..019f822
--- /dev/null
+++ b/resources/js/helpers.js
@@ -0,0 +1,45 @@
+/**
+ * @param {string} slug
+ *
+ * @returns {(string|MonsterSlug|TechniqueSlug)}
+ */
+function slugToName (slug) {
+ return slug.split('_').map((item) => item.charAt(0).toUpperCase() + item.slice(1)).join(' ');
+}
+
+/**
+ * @param {string} color
+ *
+ * @returns {string}
+ */
+function standardizeColor (color) {
+ var ctx = document.createElement('canvas').getContext('2d');
+ ctx.fillStyle = color;
+
+ return ctx.fillStyle;
+}
+
+/**
+ * @param {...string} colors
+ *
+ * @returns {string} rgb
+ */
+function mixColors(...colors) {
+ let r = 0;
+ let g = 0;
+ let b = 0;
+
+ for (const color of colors) {
+ const [cr, cg, cb] = color.match(/\w\w/g).map((c) => parseInt(c, 16));
+
+ r += cr;
+ g += cg;
+ b += cb;
+ }
+
+ r = r / colors.length;
+ g = g / colors.length;
+ b = b / colors.length;
+
+ return `rgb(${r}, ${g}, ${b})`;
+}