Skip to content

Instantly share code, notes, and snippets.

@carlhannes
carlhannes / debounce.ts
Last active June 24, 2024 19:17
ES6 Async Debounce JavaScript & TypeScript Helper Functions
// ES6 Async version of the "classic" JavaScript Debounce function.
// Works both with and without promises, so you can replace your existing
// debounce helper function with this one (and it will behave the same).
// The only difference is that this one returns a promise, so you can use
// it with async/await.
//
// I've converted this into a TypeScript module, and added a few more
// features to it, such as the ability to cancel the debounce, and also
// execute the function immediately, using the `doImmediately` method.
//
@barraponto
barraponto / idletime.js
Last active April 3, 2024 11:17
ES6+ event-based browser idle timer.
const DOCUMENT_EVENTS = [
'mousemove', 'mousedown', 'click',
'touchmove', 'touchstart', 'touchend',
'keydown', 'keypress'
];
export class IdleTimer {
constructor(onIdleTimeout, timeout) {
this.onIdleTimeout = onIdleTimeout;
this.timeout = timeout;
@KRostyslav
KRostyslav / tsconfig.json
Last active July 22, 2024 16:00
tsconfig.json с комментариями.
// Файл "tsconfig.json":
// - устанавливает корневой каталог проекта TypeScript;
// - выполняет настройку параметров компиляции;
// - устанавливает файлы проекта.
// Присутствие файла "tsconfig.json" в папке указывает TypeScript, что это корневая папка проекта.
// Внутри "tsconfig.json" указываются настройки компилятора TypeScript и корневые файлы проекта.
// Программа компилятора "tsc" ищет файл "tsconfig.json" сначала в папке, где она расположена, затем поднимается выше и ищет в родительских папках согласно их вложенности друг в друга.
// Команда "tsc --project C:\path\to\my\project\folder" берет файл "tsconfig.json" из папки, расположенной по данному пути.
// Файл "tsconfig.json" может быть полностью пустым, тогда компилятор скомпилирует все файлы с настройками заданными по умолчанию.
// Опции компилятора, перечисленные в командной строке перезаписывают собой опции, заданные в файле "tsconfig.json".