Skip to content

Instantly share code, notes, and snippets.

View wojtekmaj's full-sized avatar

Wojciech Maj wojtekmaj

View GitHub Profile
@wojtekmaj
wojtekmaj / readdirSyncDeep.rs
Last active April 11, 2024 13:06
Recursive fs.readdirSync
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);
@wojtekmaj
wojtekmaj / react-highlight-text-by-pattern.js
Last active August 15, 2024 10:19
Highlight text in React by providing text and RegExp pattern.
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] ? [