Skip to content

Instantly share code, notes, and snippets.

View maradondt's full-sized avatar

VladimirZhigalev maradondt

View GitHub Profile
@maradondt
maradondt / declOfNum.ts
Created June 16, 2022 10:40
склонение
/**
* @description
* https://realadmin.ru/coding/sklonenie-na-javascript.html
* @param n number
* @param text_forms string[]
* @returns string
*
* @example
* ```js
* declOfNum(1, ['минута', 'минуты', 'минут']); // вернёт — минута
export const separateFlie = (file: File, batchSizeMb?: number): Blob[] => {
const batchSizeBytes = (batchSizeMb || 50) * Math.pow(10, 6);
const sliceCount = file.size / batchSizeBytes;
const result: Blob[] = [];
let start = 0;
let end = batchSizeBytes;
for (let i = 0; i <= sliceCount; i++) {
const slice = file.slice(start, end);
@maradondt
maradondt / addVariablesToCSSfromJS.ts
Created April 13, 2022 10:14
added css vars from js
const addStyles = (style: HTMLStyleElement) => {
document.querySelector('head')?.appendChild(style);
};
const createStyleVariablesFromObject = (prefix: string, vars: { [k: string]: string }) => {
const style = document.createElement('style');
style.textContent = `
:root {
${Object.entries(vars)
.position-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
/* JS */
/* position: 'absolute',
top: '50%',
left: '50%',
.visually-hidden {
position: absolute;
clip: rect(0 0 0 0);
width: 1px;
height: 1px;
margin: -1px;
}