Skip to content

Instantly share code, notes, and snippets.

@kyrene-chew
Last active May 9, 2017 08:36
Show Gist options
  • Save kyrene-chew/c8024eb65cdc888634ae7986f0de5ffb to your computer and use it in GitHub Desktop.
Save kyrene-chew/c8024eb65cdc888634ae7986f0de5ffb to your computer and use it in GitHub Desktop.
JavaScript - String Handling
var string = {
// pad string with 0 from the left
padLeft: function (nr, n, str) { // pad string with 0 from the left
if (typeof nr === 'undefined' || nr === '') {
return '';
}
return Array(n - String(nr).length + 1).join(str || '0') + nr;
},
// camelcase
camelcase: function (str) {
return str.slice(0, 1).toUpperCase() + str.slice(1, str.length);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment