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
/** | |
* @param {String} data | |
* @return {{data: String|null, type: String|null}} | |
*/ | |
export function dataURLMime(data) | |
{ | |
const decompose = { type: null, data: null }, | |
regexp = /data:(image\/.+);base64,/ | |
decompose.data = data.replace(regexp, (h, t) => { |
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 caps = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), | |
lower = Array.from('abcdefghijklmnopqrstuvwxyz'), | |
numbers = Array.from('0123456789') | |
export function symbols(set = 'all') | |
{ | |
return set === 'all' ? Array.from([...caps,...lower,...numbers]) : Array.from({ caps, lower, numbers }[set]) | |
} | |
export function rndstring(length = 7, signs = 'all') |
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 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))) | |
} |
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
/** | |
* @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 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 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 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 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 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 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) | |
} |