Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
Camel case matching in package.json

I need to write a task in package.json. It looks like this:

"nyc": {
  "all": true,
  "include": [
    "src/main/**/*.tsx" // here i need to match all camelCase file names
  ]
},

Here"src/main/**/*.tsx" i need to match all camelCase titles of files.
ex: correct "src/main/**/catBlack.tsx", "src/main/**/carBlack.tsx"
not correct "src/main/**/cat.tsx", "src/main/**/test-file.tsx"
Who can help?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create a function to check if a string is camelCase using regex

function isCamelCased(str){
  const rgx = new RegExp('[a-z]{1,}([A-Z][a-z]{1,}){1,}$');
  return rgx.test(str);
}

you may want to create another function to remove the path and file extension:

function getFileName(str){
  let file;
   // remove the path
  file = str.split('/');
  file = file[file.length -1 ];
  // remove the extention
  return file.split('.')[0];
}

Test:

const arr =  [
    '/main/camelCase.txt',
    '/main/CamelCase.txt',
    '/camel.txt',
    '/main/camel-case.txt',
    '/main/camel2Case.txt', 
    '/main/camelCase2.txt', 
    ''
]
let file;
arr.forEach((str) => {
  file = getFileName(str);
  console.log(`${file} => ${isCamelCased(file)}`);
});

output:

"camelCase => true"
"CamelCase => true"
"camel => false"
"camel-case => false"
"camel2Case => false"
"camelCase2 => false"
" '' => false"
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!