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 numberOperators = ['$lt', '$gt', '$gte', '$lte', '$eq', '$ne']; | |
// TODO: Добавить поддержку otherOperators | |
const otherOperators = ['$eq', '$ne']; | |
/* | |
Пример объекта на вход: | |
const valueRaw = { | |
prepayment: { | |
value: { | |
$gte: '10000', | |
$lte: '20000' |
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 getCorrectWord = (count, words = []) => { | |
const cases = [2, 0, 1, 1, 1, 2]; | |
return words[(count % 100 > 4 && count % 100 < 20) ? 2 : cases[(count % 10 < 5) ? count % 10 : 5]]; | |
} | |
/* | |
EXAMPLE | |
const minutes = 33; | |
const message = `До приезда осталось ${minutes} ${getCorrectWord(minutes, ['минута', 'минуты', 'минут'])}` |
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 { useState, useEffect, useRef } from 'react'; | |
export default function useThrottle(value, limit) { | |
const [throttledValue, setThrottledValue] = useState(value); | |
const lastRan = useRef(Date.now()); | |
useEffect( | |
() => { | |
const handler = setTimeout(function() { | |
if (Date.now() - lastRan.current >= limit) { |
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 { useState, useEffect } from 'react'; | |
export default function useDebounce(value, delay) { | |
const [debouncedValue, setDebouncedValue] = useState(value); | |
useEffect( | |
() => { | |
const handler = setTimeout(() => { | |
setDebouncedValue(value); | |
}, delay); |
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 compareObjects = (obj1, obj2) => { | |
for (let p in obj1) { | |
if (obj1.hasOwnProperty(p) !== obj2.hasOwnProperty(p)) return false; | |
switch (typeof (obj1[p])) { | |
case 'object': | |
if (!compareObjects(obj1[p], obj2[p])) return false; | |
break; | |
case 'function': | |
if (typeof (obj2[p]) === 'undefined' || (p !== 'compare' && obj1[p].toString() !== obj2[p].toString())) return false; | |
break; |