This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DiffClamp { | |
constructor(min, max) { | |
this.min = min; | |
this.max = max; | |
this.lastValue = 0; | |
this.value = 0; | |
} | |
getValue(value) { | |
const diff = value - this.lastValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(array, result = []) { | |
if (array.length === 0) { | |
return result; | |
} | |
const randomIndex = Math.floor(Math.random() * (array.length - 1)); | |
const item = array[randomIndex]; | |
const tail = [ | |
...array.slice(0, randomIndex), | |
...array.slice(randomIndex + 1), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getModulo(value, modulus) { | |
return ( | |
((value % modulus) + modulus) % modulus | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^(ftp|https?):\/\/([^\s]+)\.([^\s|^\.]+)$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getPath (path, obj = {}) { | |
const [head , ...tail] = Array.isArray(path) ? path : path.split(/\./g) | |
const value = obj[head] | |
if (tail.length === 0 || value === undefined) { | |
return value | |
} | |
return getPath(tail, obj[head]) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hexToRgbA(hex, opacity){ | |
var c; | |
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){ | |
c= hex.substring(1).split(''); | |
if(c.length== 3){ | |
c= [c[0], c[0], c[1], c[1], c[2], c[2]]; | |
} | |
c= '0x'+c.join(''); | |
return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+','+opacity+')'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createLoop (callback, delay, duration, animationEnd) { | |
let start = null; | |
let last = null; | |
let endAnimation = null; | |
function loop (timestamp) { | |
if (!start) { | |
start = timestamp; | |
last = timestamp; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(current + length + direction) % length | |
(current + direction) % length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeExtension (path) { | |
return path.split(/\.(\w{3}|(\w{4}))$/, 1)[0] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function generateHex() { | |
const min = 1118481; // parseInt('111111', 16) | |
const max = 16777215; // parseInt('FFFFFF', 16) | |
const randomColor = Math.floor(Math.random() * (max - min + 1)) + min; | |
return `#${randomColor.toString(16)}`; | |
} |
NewerOlder