Last active
May 9, 2017 08:36
-
-
Save kyrene-chew/c8024eb65cdc888634ae7986f0de5ffb to your computer and use it in GitHub Desktop.
JavaScript - String Handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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