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 Document, { | |
Main, | |
NextScript, | |
Head, | |
Html | |
} from 'next/document' | |
import {readFileSync} from "fs" | |
import {join} from "path" | |
class InlineStylesHead extends Head { |
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
function memoize<T extends (...args: any[]) => any>( | |
func: T | |
): (...funcArgs: Parameters<T>) => ReturnType<T> { | |
const results = {}; | |
return (...args: Parameters<T>): ReturnType<T> => { | |
const cacheKey = JSON.stringify(args); | |
if (!results[cacheKey]) { | |
results[cacheKey] = func(...args); |
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
function isTargetElement(element, selector) { | |
let target = element; | |
while (target) { | |
if (target?.matches && target?.matches(selector)) { | |
break; | |
} | |
target = target?.parentNode; | |
} |
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
function getHash(value, length = 16) { | |
let hash = 0; | |
for (let index = 0; index < value.length; index++) { | |
hash = (hash << 5) - hash + value.charCodeAt(index); | |
hash = hash & hash; | |
} | |
hash = Math.abs(hash); |
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
function isPrimeNumber(value) { | |
for(let index = 2; index < value; index++) { | |
if(value % index === 0) { | |
return false; | |
} | |
return value > 1; | |
} | |
return false; |
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
function debounce(callback, frequency = 250, timer = null) { | |
return (...args) => ( | |
clearTimeout(timer), (timer = setTimeout(callback, frequency, ...args)) | |
); | |
} |