Skip to content

Instantly share code, notes, and snippets.

View Jberivera's full-sized avatar

Juan Bernardo Rivera Arias Jberivera

View GitHub Profile
@Jberivera
Jberivera / equal.js
Last active September 25, 2018 19:05
function isEqual(obj1, obj2, customizer = {}) {
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length) return false;
return keys1.every(key => {
const item1 = obj1[key];
const item2 = obj2[key];
function capitalize (str) {
return str.replace(/(\w)\w+/g, (match, g1) => `${g1.toUpperCase()}${match.substring(1)}`)
}
/**
* getLastWord - Splits the given string in
* its last word and pass the result into the callback
*
* @param {String} str
* @param {Function} callback - Takes as arguments the first part of the text (without the last word) and the last word.
*/
export function getLastWord(str, callback) {
if (typeof str !== 'string') str = '';
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)}`;
}
function removeExtension (path) {
return path.split(/\.(\w{3}|(\w{4}))$/, 1)[0]
}
(current + length + direction) % length
(current + direction) % length
function createLoop (callback, delay, duration, animationEnd) {
let start = null;
let last = null;
let endAnimation = null;
function loop (timestamp) {
if (!start) {
start = timestamp;
last = timestamp;
};
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+')';
}
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])
}
^(ftp|https?):\/\/([^\s]+)\.([^\s|^\.]+)$