Skip to content

Instantly share code, notes, and snippets.

@bn-l
bn-l / recursive-file-lister-generator.js
Created May 9, 2024 09:54
Very cool snippet showing the use of a JS generator to walk a directory recursively. Yields the path of files found.
/**
* @param {string} rootPath
* @returns {Generator<string>}
*/
function* walk(rootPath) {
for (const entry of fs.readdirSync(rootPath, { withFileTypes: true })) {
const filePath = path.join(rootPath, entry.name);
if (entry.isDirectory()) yield* walk(filePath);
else yield filePath;
@bn-l
bn-l / RegexPipe.mts
Created March 18, 2024 13:20
Using minipass to create a regex transform stream
import { Minipass } from "minipass";
export class RegexPipe extends Minipass<string, string> {
public regex: RegExp;
protected hasGroup: boolean;
private buffer: string = "";
constructor({ regex, hasGroup }: { regex: RegExp; hasGroup: boolean }) {
@bn-l
bn-l / cli-qol.md
Last active March 23, 2024 17:37
CLI QoL
@bn-l
bn-l / only_needed_components_lodash.md
Last active February 10, 2017 07:44
Importing only needed components from lodash

Keeping your bundle small

If you're concerned about the extra weight that lodash will add to your bundle you can install babel-plugin-lodash

npm install --save-dev babel-plugin-lodash

and add it to your .babelrc