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
Reset = "\x1b[0m%s\x1b[0m" | |
Bright = "\x1b[1m%s\x1b[0m" | |
Dim = "\x1b[2m%s\x1b[0m" | |
Underscore = "\x1b[4m%s\x1b[0m" | |
Blink = "\x1b[5m%s\x1b[0m" | |
Reverse = "\x1b[7m%s\x1b[0m" | |
Hidden = "\x1b[8m%s\x1b[0m" | |
FgBlack = "\x1b[30m%s\x1b[0m" | |
FgRed = "\x1b[31m%s\x1b[0m" |
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 convertQueryToMap(query) { | |
const result = {}; | |
if (!query) return result; | |
query.split('&').forEach((pair) => { | |
const [pathway, value] = pair.split('='); | |
const pathwaySplit = pathway.split('.'); | |
let obj = result; | |
pathwaySplit.forEach((prop, index) => { | |
if (index === pathwaySplit.length - 1) { | |
obj[prop] = decodeURIComponent(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
{ | |
"editor.formatOnSave": true, | |
"editor.suggestSelection": "first", | |
"terminal.integrated.fontFamily": "'Cascadia Code',sans-serif", | |
"terminal.integrated.fontSize": 14, | |
"workbench.iconTheme": "catppuccin-perfect-latte", | |
"editor.fontFamily": "'Cascadia Code',sans-serif", | |
// "editor.fontFamily": " 'Fira Code', sans-serif", | |
// "editor.fontFamily": "Operator Mono Medium", | |
// "synthwave84.brightness": 0.45, |
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 promisify = (fn) => (...args) => { | |
const promise = new Promise((resolve, reject) => { | |
const callback = (err, data) => { | |
if (err) reject(err); | |
else resolve(data); | |
}; | |
fn(...args, callback); | |
}); | |
return promise; | |
}; |
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
class AsyncTaskQueue { | |
private tasks: (() => Promise<void>)[] = []; | |
private isRunning = false; | |
public addTask(task: () => Promise<void>, signal?: AbortSignal): Promise<void> { | |
return new Promise((resolve, reject) => { | |
const wrappedTask = async () => { | |
if (signal?.aborted) return reject(new Error('Task aborted')); | |
try { | |
await task(); |
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 obj = {}; | |
let weakRef = new WeakRef(obj); | |
let finalizationRegistry = new FinalizationRegistry(() => { | |
console.log('Object has been collected'); | |
}); | |
finalizationRegistry.register(obj); | |
obj = null; |
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 chain(prev = null) { | |
const cur = () => { | |
if (cur.prev) { | |
cur.prev.next = cur; | |
cur.prev(); | |
} else { | |
cur.forward(); | |
} | |
}; |
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 fs from "fs"; | |
import { addAbortSignal } from "stream"; | |
import { setTimeout as delay } from "timers/promises"; | |
const controller = new AbortController(); | |
setTimeout(() => controller.abort(), 50); | |
const inputStream = addAbortSignal( | |
controller.signal, | |
fs.createReadStream("text.txt") |