From cc685bfe02b42b592987117fa008a4461785f53c Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 17 Aug 2023 02:53:14 +0200 Subject: refactor --- resources/js/helpers.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 resources/js/helpers.js (limited to 'resources/js/helpers.js') 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})`; +} -- cgit v1.2.3