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
$('.ql-editor[contenteditable="true"]').innerHTML | |
/** @note escape characters */ | |
.replace(/\#/g, '\\#') | |
.replace(/\*/g, '\\*') | |
/** @note convert headings */ | |
.replace(/<\/h[1-6]>/g, '\n') | |
.replace(/<h1>/g, '# ') | |
.replace(/<h2>/g, '## ') | |
.replace(/<h3>/g, '### ') | |
.replace(/<h4>/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
export const useStateChangeEffect = <S>( | |
initialState: S, | |
effect: (arg: S) => void, | |
runIf: (arg: S) => boolean = isTrue => !!isTrue, | |
) => { | |
const [state, setState] = useState(initialState); | |
const prevState = useRef(state); | |
const triggerEffect = runIf(state) && state !== prevState.current; | |
useEffect(() => void (triggerEffect && effect(state)), [effect, state, triggerEffect]); |
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 renameObjKey = <T extends Record<string, any>>( | |
oldKey: string, | |
newKey: string, | |
{[oldKey]: value, ...obj}: T, | |
) => Object.assign({[newKey]: value}, obj); |
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
// note: the existing item needs to appear after so that this can put stuff at the start of the array | |
// note: if an i > length is used, it will just be added to the last place | |
const insertAt = <T>(arr: T[], i:number, item: T) => | |
arr.slice(0, i).concat([item]).concat(arr.slice(i)); // prettier-ignore | |
const removeAt = <T>(arr: T[], i: number) => | |
arr.slice(0, i).concat(arr.slice(i + 1)) // prettier-ignore | |
const setAt = <T>(arr: T[], i: number, item: T) => | |
arr.slice(0, i).concat([item]).concat(arr.slice(i + 1)); // prettier-ignore |
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
items.map((result, item, i, {[i+1]: nextItem}) => [item, nextItem]); |
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} from 'react'; | |
export const useVector = <T>(initialValue: T, arity = 3) => { | |
const [vector, setVector] = useState<T[]>([...Array(arity)].fill(initialValue)); | |
const updateVector = (newValue: T) => setVector([newValue].concat(vector.slice(1))); | |
return [vector, updateVector] as const; | |
}; |
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
/\ | |
_\/_/ | |
/ / | |
/\ | |
/ / |
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 spaceCase = txtWithNoSpaces => | |
txtWithNoSpaces | |
.split(/_|-/g) // snake_case & kebab-case | |
.join(' ') | |
.replace(/([A-Z])/g, ' $1') // PascalCase & camelCase | |
.split(' ') | |
.map(word => word.charAt(0).toUpperCase() + word.slice(1)) | |
.join(' ') | |
.replace(/\s+/, ' ') // dashed entries create two spaces, bump that down to one | |
.replace(/([A-Z])\s(?=[A-Z]\b)/g, '$1') // e.g. "U U I D" => "UUID" |
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
.hue-gradient | |
{ | |
background:linear-gradient(to right, | |
#f00 0%, | |
#ff0 16.66%, | |
#0f0 33.33%, | |
#0ff 50%, | |
#00f 66.66%, | |
#f0f 83.33%, | |
#f00 100% |
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
<!Doctype html> | |
<style> | |
div | |
{ | |
background:linear-gradient(to right, | |
#f00 0%, | |
#ff0 16.66%, | |
#0f0 33.33%, | |
#0ff 50%, | |
#00f 66.66%, |
NewerOlder