I'm Jivaros GBETO, a software engineer working with a lot of modern technology (React, Node, Python , NestJs ...) and who likes to build high quality products but also loves code.🤝 I am open to any kind of technical collaboration or any interesting product.
-
💬 Ask me about ReactJs,NodeJs,Pyhton,Flutter,Dart,TypeScript,Javascript
-
📫 How to reach me jivarosgbeto@gmail.com
Generator in
JS
# Small function with the generators to list the files of the current folder
import * as fs from 'fs/promises';
import { join } from 'path';
async function* findFilesInCurrentDirectory(
directoryLocation: string
): AsyncGenerator<string, void, unknown> {
const dirents = await fs.readdir(directoryLocation, { withFileTypes: true });
for (const dirent of dirents) {
const fullPathName = join(directoryLocation, dirent.name);
if (dirent.isDirectory()) {
yield* findFilesInCurrentDirectory(fullPathName);
} else {
yield fullPathName;
}
}
}
const [directoryLocation = process.cwd()] = process.argv.slice(2);
/* eslint-disable */
(async () => {
const response = findFilesInCurrentDirectory(directoryLocation);
let isDone: boolean | undefined = false;
while (!isDone) {
const { value, done } = await response.next();
isDone = done;
console.log(value);
}
})();
# Small function to extract numbers in a string
const article = `
Lorem Ipsum is 12 simply dummy text of the printing and 40 typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500 s,
typesetting, remaining essentially unchanged. It was popularised in the 1960s with the
release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like 500.89.56 Aldus PageMaker including versions
of Lorem 200 Ipsum
`;
function* findNumberInSting(text: string) {
let currentNumberAsString = '';
for (const char of text) {
if (isNumber(char)) {
currentNumberAsString += char;
} else if (currentNumberAsString) {
yield Number(currentNumberAsString);
currentNumberAsString = '';
}
}
if (currentNumberAsString) {
yield Number(currentNumberAsString);
}
}
function isNumber(char: string) {
return /[0-9]/.test(char);
}
const iterator = findNumberInSting(article);
let isDone: boolean | undefined = false;
while (!isDone) {
const { value, done } = iterator.next();
isDone = done;
console.log(value);
}