Skip to content

Instantly share code, notes, and snippets.

@Swivelgames
Last active December 2, 2016 04:44
Show Gist options
  • Select an option

  • Save Swivelgames/19b382f11aea5354cc67aa316955fbaa to your computer and use it in GitHub Desktop.

Select an option

Save Swivelgames/19b382f11aea5354cc67aa316955fbaa to your computer and use it in GitHub Desktop.
camelCase: Like camelCase npm package, formats hyphen, period, underscore, or space separated strings in camelCase.
const camelCase = (...args) => {
let str = args.join("-")
.replace(/[ _.-]+[A-Za-z]{1}/g,
(m) => m.replace(/[^A-Za-z]/g, '').toUpperCase()
).replace(/[ _.-]/g, '');
return str[0].toLowerCase() + str.substr(1);
}
var str = "__foo___bar____---";
camelCase(str); // fooBar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment