Last active
August 8, 2023 09:45
-
-
Save sashuk/410397686c987bb7a91eac6548d7f3c9 to your computer and use it in GitHub Desktop.
Identify camelCase TS files
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 fs = require('fs'); | |
const path = require('path'); | |
function isCamelCase(str) { | |
return /^[a-z][a-zA-Z0-9]*$/.test(str); | |
} | |
function findCamelCaseFilesRecursively(folderPath) { | |
fs.readdir(folderPath, (err, files) => { | |
if (err) { | |
console.error('Error reading directory:', err); | |
return; | |
} | |
files.forEach(file => { | |
const filePath = path.join(folderPath, file); | |
fs.stat(filePath, (err, stats) => { | |
if (err) { | |
console.error('Error reading file stats:', err); | |
return; | |
} | |
const fileName = path.parse(file).name; | |
const ext = path.parse(file).ext; | |
if (stats.isFile() && isCamelCase(fileName) && ext === '.ts' && /[A-Z]/.test(fileName)) { | |
console.log(filePath); | |
} else if (stats.isDirectory() && filePath.indexOf('node_modules') === -1) { | |
findCamelCaseFilesRecursively(filePath); | |
} | |
}); | |
}); | |
}); | |
} | |
const folderPath = './'; // Replace with your folder path | |
findCamelCaseFilesRecursively(folderPath); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment