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 highlightPattern(text, pattern) { | |
const splitText = text.split(pattern); | |
if (splitText.length <= 1) { | |
return text; | |
} | |
const matches = text.match(pattern); | |
return splitText.reduce((arr, element, index) => (matches[index] ? [ |
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 fs from 'node:fs'; | |
import path from 'node:path'; | |
function readdirSyncDeep(dir: string, rootDir: string = dir) { | |
const files = fs.readdirSync(dir); | |
const filelist: string[] = []; | |
files.forEach((file) => { | |
const filePath = path.join(dir, file); |
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 findScrollContainer = (element) => { | |
if (!element) { | |
return undefined; | |
} | |
let parent = element.parentElement; | |
while (parent) { | |
const { overflow } = window.getComputedStyle(parent); | |
if (overflow.split(' ').every(o => o === 'auto' || o === 'scroll')) { | |
return parent; |
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
/** | |
* Allows to use multiple refs on a single React element. | |
* Supports both functions and ref objects created using createRef() and useRef(). | |
* | |
* Usage: | |
* ```jsx | |
* <div ref={mergeRefs(ref1, ref2, ref3)} /> | |
* ``` | |
* | |
* @param {...Array<Function|Object>} inputRefs Array of refs |
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
/** | |
* Transforms HTML table into JSON data. | |
* | |
* Sample input: | |
* | |
* <table> | |
* <thead> | |
* <tr> | |
* <th>Heading 1</th> | |
* <th>Heading 2</th> |
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 toPx(val) { | |
return typeof val === 'number' ? `${val}px` : val; | |
} | |
/** | |
* Creates a text outline of a given width and color. | |
* | |
* Sample usage in styled-components: | |
* ${props => textOutline('2px', props.color)} | |
* |
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 toPx(val) { | |
return typeof val === 'number' ? `${val}px` : val; | |
} | |
/** | |
* Creates a background with a single line, e.g. for simulating underline. | |
* | |
* Sample usage in styled-components: | |
* ${props => lineBackground('to bottom', '2px', props.color)} | |
* |
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 round(value, decimals) { | |
return Number(`${Math.round(`${value}e${decimals}`)}e-${decimals}`); | |
} | |
function roundPath(path, decimals = 3) { | |
function roundPathPoint(pathPoint) { | |
function roundPathPointElement(pathPointElement) { | |
if (pathPointElement.match(/^[A-Za-z]/)) { | |
return `${pathPointElement[0]}${pathPointElement.slice(1) && round(pathPointElement.slice(1), decimals)}`; | |
} |
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
if (!('open' in document.createElement('details'))) { | |
const DETAILS = 'details'; | |
const SUMMARY = 'summary'; | |
function injectStyle(style) { | |
const styleElement = document.createElement('style'); | |
styleElement.innerHTML = style; | |
document.getElementsByTagName('head')[0].appendChild(styleElement); | |
} |
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
.pnp.* | |
.yarn/* | |
!.yarn/patches | |
!.yarn/plugins | |
!.yarn/releases | |
!.yarn/sdks | |
!.yarn/versions |
OlderNewer