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
"use strict"; | |
let fps = 1; | |
let times = []; | |
const debug = true; | |
const fpsLoop = (timestamp = 0, debug) => { | |
while (times.length > 0 && times[0] <= timestamp - 1000) { | |
times.shift(); | |
} | |
times.push(timestamp); | |
fps = times.length; |
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
/** | |
* Проверяет, можно использовать браузерное API в текущем окружении. | |
* | |
* @example | |
* if (canUseDOM()) { | |
* document.querySelector('...') | |
* } | |
*/ | |
export const canUseDOM = (): boolean => { | |
return ( |
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 { useEffect, useState } from 'react'; | |
export const useWindowFocused = () => { | |
const [windowIsActive, setWindowIsActive] = useState(true); | |
function handleActivity(forcedFlag) { | |
if (typeof forcedFlag === 'boolean') { | |
return forcedFlag ? setWindowIsActive(true) : setWindowIsActive(false); | |
} |
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 type Primitive = string | number | boolean | bigint | symbol | undefined | null; | |
export type Builtin = Primitive | Function | Date | Error | RegExp; | |
/** | |
* TypeScript type to return a deep readonly object (recursively). | |
*/ | |
// prettier-ignore | |
export type DeepReadonly<T> = T extends Builtin | |
? T | |
: T extends Map<infer K, infer V> |
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 hex = (e: number): string => '0x' + e .toString(16); | |
/* Usage: console.log(hex(255)) */ |
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 webpSupported = undefined; | |
/* export ES6+ */ async function isWebpSupported() { | |
if (webpSupported !== undefined) { | |
return webpSupported; | |
} | |
const promise = new Promise(resolve => { | |
const image = new Image(); | |
image.onload = function () { |
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
/** | |
* Improved Time Zone resolver | |
* | |
* @see {@link https://402.ecma-international.org/1.0/#sec-12.1} reference | |
* @see {@link https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat} reference | |
* @see {@link https://en.wikipedia.org/wiki/List_of_tz_database_time_zones} reference | |
* | |
* @return {String|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
/usr/bin/python3 -m pip install --upgrade pip |
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 React, { useState, useEffect } from 'react'; | |
/** | |
* Works in Chrome 90.0.4430.72 | |
* | |
* @method Bug | |
*/ | |
const Bug = () => { | |
/** | |
* Current IMG src attr |
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
npx -p typescript tsc --init |