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
| /** | |
| * @see https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/queueMicrotask | |
| */ | |
| export const queueMicrotask = (function() { | |
| const queueMicrotask = typeof window !== 'undefined' | |
| ? window.queueMicrotask | |
| : undefined | |
| return queueMicrotask || (cb => { | |
| Promise.resolve().then(cb).catch(e => setTimeout(() => { throw e })) |
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 noop = () => {} | |
| export class Cancelable extends Promise | |
| { | |
| constructor(executor = noop) | |
| { | |
| super((resolve, reject) => { | |
| executor(v => { | |
| /** |
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
| /** "Lorem ipsum" style text. */ | |
| /** | |
| * Produces a random number | |
| * @return {Number} Random number | |
| */ | |
| export function gauss() | |
| { | |
| return (Math.random() * 2 - 1) + (Math.random() * 2 - 1) + (Math.random() * 2 - 1) | |
| } |
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
| export function Renderer({ minScale, maxScale, scaleSensitivity = 10 }) | |
| { | |
| const getInitialState = () => ({ | |
| minScale, | |
| maxScale, | |
| scaleSensitivity, | |
| transformation: { | |
| originX: 0, | |
| originY: 0, | |
| translateX: 0, |
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 document = typeof window !== 'undefined' && typeof window.document !== 'undefined' ? window.document : {} | |
| export const fullscreen = (function(fullscreen) { | |
| const isEnabled = false, fn = {} | |
| if (!fullscreen.some(map => { | |
| if (map[1] in document) { | |
| for (let i = 0; i < map.length; i++) { | |
| fn[fullscreen[0][i]] = map[i] | |
| } |
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
| /** | |
| * @example declination(5, ['комментарий','комментария','комментариев']) | |
| * @param {Number} n The number for which the ending will be calculated | |
| * @param {Array} titles Word variants for 1,2,5 | |
| * @returns {String} | |
| */ | |
| export function declination(n, titles) | |
| { | |
| return titles[(n % 10 === 1 && n % 100 !== 11) ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2] | |
| } |
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
| /** | |
| * @param {Number} bytes | |
| * @param {Number} decimals | |
| * @return {string} | |
| */ | |
| export function format(bytes, decimals = 2) | |
| { | |
| if (bytes === 0) return '0 B' | |
| const dim = ['B','KB','MB','GB','TB','PB','EB','ZB','YB'], |
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 nodes = [] | |
| export function removeNodes() | |
| { | |
| nodes.forEach(el => el.parentNode && el.parentNode.removeChild(el)) | |
| nodes.splice(0, nodes.length) | |
| } | |
| /** | |
| * @param {String} link |
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
| /** | |
| * @param {{r: number, g: number, b: number}} | |
| * @return {string} | |
| */ | |
| export function rgbToHex({ r, g, b }) | |
| { | |
| return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1) | |
| } |
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
| export function shift(arr, direction, n) | |
| { | |
| const times = n > arr.length ? n % arr.length : n | |
| return arr.concat(arr.splice(0, (direction > 0 ? arr.length - times : times))) | |
| } |