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 removeSpecialChars(str: string): string { | |
return str.replace(/[^0-9a-zA-Z]/g, ''); | |
} | |
function camelize(str: string): string { | |
return str | |
.replace(/(?:^\w|[A-Z]|\b\w)/g, function (word, index) { | |
return index === 0 ? word.toLowerCase() : word.toUpperCase(); | |
}) | |
.replace(/\s+/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
type ScoreObj = { [key: string]: number }; | |
// Since we are sure that "scoreObj" is always of type {[key: string]: number;} | |
// we can use our own typing for Object.entries(). | |
// It is still using a type assertion ("as any") which is not ideal, | |
// but gives us the right typings in subsequnt methods | |
type Entries<T> = { [K in keyof T]: [K, T[K]] }[keyof T]; | |
function objectEntries<T extends object>(t: T): Entries<T>[] { | |
return Object.entries(t) as any; | |
} |
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 getDatetimeDefaultValue = (timestamp: Date | string): string => { | |
let ts = new Date(); | |
if (timestamp) { | |
ts = new Date(timestamp); | |
} | |
ts.setMinutes(ts.getMinutes() - ts.getTimezoneOffset()); | |
ts.setMilliseconds(null); | |
ts.setSeconds(null); | |
return ts.toISOString().slice(0, -1); | |
}; |
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
// Fire useEffect only once on mount | |
cosnt executedRef = useRef(false); | |
useEffect(() => { | |
if(executedRef.current) { | |
return; | |
} | |
// doSomething(); |
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 matcMultiple(subject: string, strings: string[]) { | |
const regexMetachars = /[(){[*+?.\\^$|]/g; | |
for (let i = 0; i < strings.length; i++) { | |
strings[i] = strings[i].replace(regexMetachars, '\\$&'); | |
} | |
const regex = new RegExp('\\b(?:' + strings.join('|') + ')\\b', 'gi'); | |
return subject.match(regex) || []; |
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
#001627,#01151A,#1D3B53,#D5DDEA,#01121F,#D5DDEA,#77CEBF,#F0546F,#001627,#D5DDEA |
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
// define formatter | |
const locales: string | string[] = 'en-US'; | |
const options: Intl.DateTimeFormatOptions = { | |
year: 'numeric', | |
month: 'short', | |
day: 'numeric', | |
hour: 'numeric', | |
minute: '2-digit' | |
}; | |
const formatter: Intl.DateTimeFormat = new Intl.DateTimeFormat( |
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
{ | |
"Right Option Key Sends" : 0, | |
"Tags" : [ | |
], | |
"Ansi 12 Color" : { | |
"Red Component" : 0.50980395078659058, | |
"Color Space" : "sRGB", | |
"Blue Component" : 1, | |
"Alpha Component" : 1, |
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
/* | |
Josh Comeau's Modern CSS Reset | |
https://www.joshwcomeau.com/css/custom-css-reset/ | |
*/ | |
*, *::before, *::after { | |
box-sizing: border-box; | |
} | |
* { | |
margin: 0; | |
} |
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
{ | |
"arrowParens": "avoid", | |
"bracketSpacing": true, | |
"singleQuote": true, | |
"tabWidth": 2, | |
"trailingComma": "none" | |
} |
NewerOlder