This file contains 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 round(number, places) { | |
places = Math.max(0, Math.min(places || 0, String(number).split(".")[1].length || 0)); | |
return Math.round(number * Math.pow(10, places)) / Math.pow(10, places); | |
} |
This file contains 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 swapDomNodes(a, b) { | |
var afterA = a.nextSibling; | |
if (afterA == b) { | |
swapDomNodes(b, a); | |
return; | |
} | |
var aParent = a.parentNode; | |
b.parentNode.replaceChild(a, b); | |
aParent.insertBefore(b, afterA); | |
} |
This file contains 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
// Getting a random number between 0 (inclusive) and 1 (exclusive) | |
function getRandom() { | |
return Math.random(); | |
} | |
// Getting a random number between two values | |
function getRandomArbitrary(min, max) { | |
return Math.random() * (max - min) + min; | |
} |
This file contains 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
/** Whether we are using a Mac or not. */ | |
function isMac() { | |
return /Mac/.test(navigator.platform); | |
} | |
/** Whether this is on the Windows platform or not. */ | |
function isWindows() { | |
return /Win/.test(navigator.platform); | |
} |
This file contains 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 getOffset(element) { | |
var left = element.offsetLeft; | |
var top = element.offsetTop; | |
while (element = element.offsetParent) { | |
left += element.offsetLeft + element.clientLeft - element.scrollLeft; | |
top += element.offsetTop + element.clientTop - element.scrollTop; | |
} | |
return { | |
left: left, | |
top: top |
This file contains 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
/** | |
* Return the first ancestor for which the {@code predicate} returns true. | |
* @param {Node} node The node to check. | |
* @param {function(Node):boolean} predicate The function that tests the | |
* nodes. | |
* @return {Node} The found ancestor or null if not found. | |
*/ | |
function findAncestor(node, predicate) { | |
var last = false; | |
while (node != null && !(last = predicate(node))) { |
This file contains 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 getRandomColor() { | |
var x = Math.round(0xffffff * Math.random()).toString(16); | |
var y = (6 - x.length); | |
var z = '000000'; | |
var z1 = z.substring(0, y); | |
return '#' + z1 + x; | |
} |
Add below code in package.json script
{
"scripts": {
"rmdir": "node -e \"var fs = require('fs'); process.argv.slice(1).map((fpath) => fs.rmdirSync(fpath, { recursive: true })); process.exit(0);\"",
}
}
Then execute as below in command window
OlderNewer