-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
37 lines (35 loc) · 918 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* helper function for clamping a number
* @param {number} n
* @param {number} lo
* @param {number} hi
* @returns {number}
*/
export function clamp(n, lo, hi) {
return Math.min(hi, Math.max(n, lo));
}
/**
* converts string given by color input to array of four (normalized)
* @param {string} str
*/
export function hexColorToVector(str) {
str = str.slice(1) + "ff"; // get rid of first char
const vals = str.match(/..?/g); // split into groups of two
const vec = vals.map(n => parseInt(n, 16) / 255);
return vec;
}
/**
* gets the string value of variable from query string
* @param {string} variable
*/
export function getVariable(variable) {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (let i = 0; i < vars.length; i++) {
let pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return undefined;
}