router.get('/', cacheMiddleware(60 * 60), mainController);
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
// React hook useObserver | |
// It also works in next.js | |
import { useEffect, useRef } from 'react'; | |
const useObserver = (ref, callback, options, shouldWork = null) => { | |
const observer = useRef(); | |
useEffect(() => { | |
if (observer.current) { |
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 { URL } = require('url'); | |
/** | |
* This function adds params to url | |
* | |
* @param {stirng} url - Url | |
* @param {...any} params - Params. E.g. url, param1, param1value, param2, param2value | |
*/ | |
const addParamsToUrl = (url = '', ...params) => { | |
const myUrl = new URL(url); |
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 getRandomId = () => `_${Math.random().toString(36).substring(2, 9)}`; | |
const createFakeArray = (length = 10) => | |
new Array(length).fill('_').map(() => getRandomId()); |
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 PropTypes from 'prop-types'; | |
import { forwardRef } from 'react'; | |
import NextLink from 'next/link'; | |
const MyLink = forwardRef(({ href, prefetch, className, children }, ref) => ( | |
<NextLink href={href} prefetch={prefetch} passHref> | |
<a className={className} ref={ref}> | |
{children} | |
</a> | |
</NextLink> |
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 getObjectProperty = (object = {}, property = '') => { | |
const properties = Array.isArray(property) ? property : property.split('.'); | |
const propertyName = properties[0]; | |
const value = object[propertyName]; | |
if (properties.length <= 1) { | |
return value; | |
} | |
if (value === null || typeof value !== 'object') { |
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 PropTypes from 'prop-types'; | |
import Link from 'next/link'; | |
import { Box } from '@mui/material'; | |
/** | |
* @returns {number} - Image padding bottom | |
*/ | |
const getImagePaddingBottom = (width = 0, height = 0) => 100 * (height / width); | |
const PreviewImage = ({ link, src, width, height, alt }) => { |
An analog of sort-keys-recursive (https://www.npmjs.com/package/sort-keys-recursive) that sorts object keys alphabetically and arrays in objects.
This function collects object values { a: 1, b: 2 } => [1, 2] { c: { d: 3, e: 4 } } => [3, 4]
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 createMD5Signature from './createMD5Signature'; | |
describe('createMD5Signature', () => { | |
it('should return a correct hash', () => { | |
expect(createMD5Signature('JohnSmith:9129s$aW}a1')).toBe( | |
'6436241bc4170549efac409b8a4fc43f' | |
); | |
}); | |
}); |
OlderNewer