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
import { useState, useEffect } from 'react'; | |
import moment from 'moment'; | |
type TimerHook = { | |
time: string; | |
stop: () => void; | |
}; | |
const useTimer = (endTime: string): TimerHook => { | |
const duration = moment.duration(moment(endTime, 'HH:mm:ss').diff(moment(moment().format('HH:mm:ss'), 'HH:mm:ss'))); |
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
interface Array<T> { | |
has(key: string, value: any): [keyof T, any] | [] | |
} | |
Array.prototype.has = function(key, value) { | |
return this.filter((item) => item[key] === value) | |
} |
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
interface Date { | |
setDays(days: number): Date | |
} | |
Date.prototype.setDays = function(days: number) { | |
const date = new Date(this.valueOf()) | |
date.setDate(date.getDate() + days) | |
return date | |
} |
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
/* REGEXes */ | |
const REGEX_INT = /^-?\d+$/; | |
const REGEX_EMAIL = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/g; | |
const REGEX_PASSWORD = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[a-zA-Z]).{8,}$/gm; | |
const REGEX_IPv4 = /\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b/ig; | |
const REGEX_IPv6 = /(([a-fA-F0-9]{1,4}|):){1,7}([a-fA-F0-9]{1,4}|:)/gm; |
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 permissions = { | |
Admin: ['/', '/users'], | |
undefined: ['/login'], | |
null: ['/login'], | |
}; | |
const initialState = { | |
status: 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
function concatArrays (firstArr, secondArr) { | |
return [...firstArr, ...secondArr] | |
} | |
concatArrays ([1,2,3], ["Hello world!", "Mondongo"]) | |
// [ 1, 2, 3, 'Hello world!', 'Mondongo' ] |
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 countDuplicate = (array) => { | |
let object = array.reduce((prev, cur) => ((prev[cur] = prev[cur] + 1 || 1), prev), {}) | |
console.log(object); | |
} | |
countDuplicate(['test', 'test', 'test2']) |
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
let result = [] | |
const REGEX_INT = /^-?\d+$/; | |
const isNumber = (value) => { | |
return REGEX_INT.test(value); | |
} | |
const fakeBinary = (param) => { | |
if (isNumber(param)){ |
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 everyWeek = (x) => { | |
let prev = new Date(); | |
prev.setDate(prev.getDate() + (x+(7+prev.getDay())) % 7); | |
return prev | |
.toISOString() | |
.slice(0, 10) | |
.replace('T',' '); | |
} |