Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

66
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda