79272592

Date: 2024-12-11 17:11:20
Score: 1.5
Natty:
Report link

I needed this too, and I wanted it to be robust and as international-friendly as possible. I used regex and character classes to get the characters I want and array ops to split/join it together:

export function camelize(s) {
    const sa = s
        .replace(/[^\w\d\s]/g, '')
        .toLowerCase()
        .split(/\s+/);

    return sa
        .filter(v => !!v)
        .map((w, i) => (i > 0 ? w[0].toUpperCase() + w.substr(1) : w))
        .join('');
}

Enjoy!

Reasons:
  • Blacklisted phrase (0.5): I need
  • RegEx Blacklisted phrase (1): I want
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Scott Means