This file contains hidden or 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: this code was originally written for objects containing translations, that is why | |
// at some places type argument names have references to language related things. | |
export type ObjectKeyPaths<ObjectType extends object, Separator extends string = "."> = { | |
[Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object | |
? `${Key}` | `${Key}${Separator}${ObjectKeyPaths<ObjectType[Key], Separator>}` | |
: `${Key}`; | |
}[keyof ObjectType & (string | number)]; | |
export type Split<S extends string, D extends string> = |
This file contains hidden or 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
{ | |
"name": "debug everything", | |
"type": "node", | |
"request": "launch", | |
"runtimeArgs": ["-r", "ts-node/register"], | |
"args": ["${workspaceRoot}/src/compile.ts"] | |
} |
This file contains hidden or 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
data Nat = Zero | Suc Nat deriving (Show) | |
data List a = Nil | Cons a (List a) deriving (Show) | |
addNat :: Nat -> Nat -> Nat | |
addNat Zero x = x | |
addNat (Suc x) y = Suc (addNat x y) | |
mulNat :: Nat -> Nat -> Nat | |
mulNat Zero _ = Zero | |
mulNat (Suc x) y = addNat y (mulNat x y) |
This file contains hidden or 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 getChildWithClassName(element, className) { | |
if (!element || !className) return null; | |
const toIterable = elemList => (elemList ? [...elemList] : []) | |
const searcher = nodes => { | |
if (!nodes || nodes.length < 1) return null; | |
return nodes.find(node => toIterable(node.classList).includes(className)) | |
|| nodes.map(node => searcher(toIterable(node.childNodes))).find(x => x) // 🚀 | |
} |
This file contains hidden or 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
console.time('start') | |
async function myFunction() { | |
const success = Promise.resolve('Yaaay') | |
const promise = new Promise((_, reject) => setTimeout(() => { | |
console.timeEnd('start') | |
reject('Rejection reason') | |
}, 200)) | |
const autoCatchedPromise = promise.catch(error => { | |
console.info('Error caught:', error) |
This file contains hidden or 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 getPropertyDeep = function(rootObject, queryString) { | |
if (queryString.indexOf('.') === -1) return rootObject[queryString] | |
const partialQueryString = queryString.split('.') | |
const partialObject = rootObject[partialQueryString[0]] | |
return getPropertyDeep(partialObject, partialQueryString.slice(1).join('.')) | |
} |