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
export const getUUID = ()=>{ | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace( /[xy]/g , | |
function(c) { | |
var rnd = Math.random()*16 |0, v = c === 'x' ? rnd : (rnd&0x3|0x8) ; | |
return v.toString(16); | |
} | |
); | |
} |
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
/** | |
* isElement - Checks if the argument is a DOM element. from https://stackoverflow.com/a/36894871/7197027 | |
* | |
* @param {object} element Argument to be tested | |
* | |
* @returns {Boolean} Result if the argument is a DOM element or not. | |
*/ | |
export const isElement = element=> element instanceof Element || element instanceof HTMLDocument; |
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
git config --global alias.gone "! git fetch -p && git for-each-ref --format '%(refname:short) %(upstream:track)' | awk '\$2 == \"[gone]\" {print \$1}' | xargs -r git branch -D" |
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
// Derived from https://stackoverflow.com/a/52854585/7197027 | |
export const hasPointer = ()=>window.matchMedia("(any-hover: none)").matches === false |
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
Number(num) != NaN && Number.isInteger(Number(num)) |
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
// From https://gist.github.com/yeah/1283961 | |
const diacriticsMap = [ | |
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g}, | |
{'base':'AA','letters':/[\uA732]/g}, | |
{'base':'AE','letters':/[\u00C4\u00C6\u01FC\u01E2]/g}, | |
{'base':'AO','letters':/[\uA734]/g}, | |
{'base':'AU','letters':/[\uA736]/g}, | |
{'base':'AV','letters':/[\uA738\uA73A]/g}, | |
{'base':'AY','letters':/[\uA73C]/g}, | |
{'base':'B', 'letters':/[\u0042\u24B7\uFF22\u1E02\u1E04\u1E06\u0243\u0182\u0181]/g}, |
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
/** | |
* Format the number to a string space padded every 3 decimals | |
*/ | |
export const formatNumber = (n, suffix="")=>{ | |
let num = String(n).split(".")[0]; | |
let decimal = String(n).split(".")[1]; | |
decimal = decimal ? "," + decimal : ""; | |
let numStr = ""; | |
let l = num.length-1; | |
let i = num.length; |
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
export const roundOff = (num, decimalPoints)=>Math.round( num * Math.pow(10, decimalPoints) ) / Math.pow(10, decimalPoints) |
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
/** | |
* Checks if the value is a Number. | |
* For a longer discussion on the solution see: https://medium.com/javascript-in-plain-english/how-to-check-for-a-number-in-javascript-8d9024708153 | |
*/ | |
export const isNumber = val=>Number.isFinite(val); |
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
const randomColour = () => '#'+(Math.random()*0xFFFFFF<<0).toString(16); |
NewerOlder