Last active
          April 26, 2023 10:22 
        
      - 
      
 - 
        
Save ronaldaug/a116226a50f628aebf70d3a4895f1141 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
ronaldaug revised this gist
Apr 26, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ function copyFolderSync(from, to) { ``` ## Found word's line number ```javascript  - 
        
ronaldaug revised this gist
Apr 26, 2023 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -70,4 +70,19 @@ function copyFolderSync(from, to) { }); } ``` ## Get Found word line ```javascript const content = `Lorem ipsum dolor, sit amet consectetur adipisicing elit. \n Facilis deleniti abc ipsam quibusdam odit.`; const lineNumbers = (needle, haystack) => haystack .split(/^/gm) .map((v, i) => v.match(needle) ? i + 1 : 0) .filter(a => a); console.log(lineNumbers('abc',content)) // [2] ```  - 
        
ronaldaug revised this gist
Jan 16, 2023 . 1 changed file with 8 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -59,23 +59,15 @@ function readFileContents(dir) { ```javascript function copyFolderSync(from, to) { fs.mkdirSync(to); fs.readdirSync(from).forEach(element => { if (fs.lstatSync(path.join(from, element)).isFile()) { fs.copyFileSync(path.join(from, element), path.join(to, element)); } else { copyFolderSync(path.join(from, element), path.join(to, element)); } }); } ```  - 
        
ronaldaug revised this gist
Nov 24, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -47,7 +47,7 @@ init(); function readFileContents(dir) { const files = []; fs.readdirSync(dir).forEach(filename => { const data = fs.readFileSync(dir+'/'+filename, 'utf-8') files.push(data) }); return files;  - 
        
ronaldaug revised this gist
Mar 9, 2021 . 2 changed files with 81 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,24 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ ## Prompt to get the value ```javascript const { stdin, stdout } = process; // Prompt function function prompt(question) { return new Promise((resolve, reject) => { stdin.resume(); stdout.write(question); stdin.on('data', data => resolve(data.toString().trim())); stdin.on('error', err => reject(err)); }); } // Init async function init() { try { let value = await prompt('Please type something') console.log(value) stdin.pause(); } catch(error) { console.log("There's an error!"); console.log(error); } process.exit(); } init(); ``` ## Read File Content ```javascript /** * Read Files Content */ function readFileContents(dir) { const files = []; fs.readdirSync(dir).forEach(filename => { const data = fs.readFileSync(dir+filename, 'utf-8') files.push(data) }); return files; } ``` ## Copy Directory ```javascript async function copyDir(src, dest) { const doneCheck = new Promise(async(resolve,reject)=>{ await fs.mkdir(dest, { recursive: true }); let entries = await fs.readdir(src, { withFileTypes: true }); for (let entry of entries) { let srcPath = path.join(src, entry.name); let destPath = path.join(dest, entry.name); entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs.copyFile(srcPath, destPath); } resolve('done'); }) return doneCheck; } ```  - 
        
ronaldaug revised this gist
Mar 9, 2021 . No changes.There are no files selected for viewing
 - 
        
ronaldaug created this gist
Mar 9, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ Copy Directory ```javascript async function copyDir(src, dest) { const doneCheck = new Promise(async(resolve,reject)=>{ await fs.mkdir(dest, { recursive: true }); let entries = await fs.readdir(src, { withFileTypes: true }); for (let entry of entries) { let srcPath = path.join(src, entry.name); let destPath = path.join(dest, entry.name); entry.isDirectory() ? await copyDir(srcPath, destPath) : await fs.copyFile(srcPath, destPath); } resolve('done'); }) return doneCheck; } ```