Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

74
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda