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
| function getUrlParameter(param) { | |
| var pageUrl = decodeURIComponent(window.location.search.substring(1)), | |
| urlVariables = pageUrl.split('&'), | |
| parameterName, | |
| i; | |
| for (i = 0; i < urlVariables.length; i++) { | |
| parameterName = urlVariables[i].split('='); | |
| if (parameterName[0] === param) { |
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
| // time const in millisecond | |
| export const SECOND = 1000; | |
| export const MINUTE = 60 * SECOND; // 60 000 | |
| export const HOUR = 60 * MINUTE; // 3 600 000 | |
| export const DAY = 24 * HOUR; // 86 400 000 | |
| export const WEEK = 7 * DAY; // 604 800 000 | |
| // export const YEAR = 365 * DAY; // 31 536 000 000 | |
| export const YEAR = 365.25 * DAY; // 31 557 600 000 |
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
| class ObjectArray extends Object { | |
| /** | |
| * @param {Object} obj | |
| */ | |
| constructor(obj = {}) { | |
| super(); | |
| this.length = 0; | |
| const keys = Object.keys(obj); | |
| keys.forEach((key) => { | |
| this.length += 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
| function getBoundingClientRect(el) { | |
| return new Promise((res, rej) => { | |
| requestAnimationFrame(() => { | |
| res(el.getBoundingClientRect()); | |
| }); | |
| }); | |
| } |
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
| function find2(str) { | |
| let _helper = []; | |
| return str | |
| .split('') | |
| .reduce((acum, item, i, originalArr) => { | |
| if (_helper.some(char => char === item)) { | |
| acum.push(_helper); | |
| _helper = []; | |
| } | |
| _helper.push(item); |
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
| function flatter(arr) { | |
| return arr.flat(Infinity); | |
| } | |
| flatter( | |
| [1, 2, [3, 4, [5]], 6, [[7, [8]], 9]], | |
| ); | |
| function flatter2(arr) { | |
| const arrCopy = arr.slice(); |
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: | |
| * const aObj = { | |
| * b: () => 42, | |
| * c: () => "hello" | |
| * } | |
| * type ObjExample = ReturnedValueFromObjectMethodByKey<typeof aObj>; | |
| * ObjExample type will be: {b: number; c: string} | |
| */ |
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
| (function() { | |
| // 1 | |
| function smartJoin(arrA, arrB) { | |
| let aIndex = 0; | |
| let bIndex = 0; | |
| const result = []; | |
| while (aIndex < arrA.length || bIndex < arrB.length) { | |
| const itemA = arrA[aIndex]; |
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
| /** | |
| * Call fn not more often but and not less then ms | |
| * @param {function} fn - function what need to call not often but and not less then ms | |
| * @param {number} ms - time in milliseconds | |
| * @return (any[]) => void | |
| */ | |
| export const throttle = (fn: (...args: any[]) => void, ms: number = 0) => { | |
| let timeoutId = null; | |
| let lastCall = 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
| import { Location } from "history"; | |
| import React, { useEffect, useState } from "react"; | |
| import { Prompt } from "react-router-dom"; | |
| import { SubmitDialogComponent } from "./Modal"; | |
| interface Props { | |
| when?: boolean | undefined; // just use true | |
| navigate: (path: string) => void; // (path) => history.push(path) | |
| shouldBlockNavigation: (location: Location) => boolean; | |
| } |