Skip to content

Instantly share code, notes, and snippets.

@sashuk
Last active August 8, 2023 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashuk/410397686c987bb7a91eac6548d7f3c9 to your computer and use it in GitHub Desktop.
Save sashuk/410397686c987bb7a91eac6548d7f3c9 to your computer and use it in GitHub Desktop.
Identify camelCase TS files
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