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

147
Views
How to convert between camelCase PascalCase snake_case kebab-case (JS)

Maybe someone will find it useful - How to convert between camelCase PascalCase snake_case kebab-case (JS)

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

'use strict'

const log = console.log.bind(console);

const toCamel = val => val.trim().replace(/([-_ ]+)./g, $ => $.at(-1).toUpperCase());
const toKebab = val => toCamel(val).replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, o) => (o ? "-" : "") + $.toLowerCase())
const toSnake = val => toCamel(val).replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, o) => (o ? "_" : "") + $.toLowerCase())
const toPascal = val => toCamel(val).replace(/^./, $ => $.toUpperCase());

const testCase = [
    'StackOverflow',
    'camelCase',
    'alllowercase',
    'JSONdata',
    '         aaa--------bbb-ccc',
    'aaa_______bbb__ccc_dddddddddd',
    'aaa          bbb -ccc',
    'ddd-eee-fff',
];

log(testCase.map(toCamel));
about 4 years ago · Santiago Gelvez Report

0

You can use lodash package.

      _.kebabCase('Foo Bar');
    // => 'foo-bar'

    _.snakeCase('Foo Bar');
    // => 'foo_bar'


 startCase(camelCase(str)).replace(/ /g, '');
about 4 years ago · Santiago Gelvez 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!