Last active
March 25, 2016 16:01
-
-
Save ruyaoyao/a8314aa0a6186d26a125 to your computer and use it in GitHub Desktop.
leftPad implementation
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
// ES6 leftPad by Guillermo Rauch | |
// https://twitter.com/rauchg/status/712799807073419264 | |
export default (v, n, c = '0') => String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n); | |
// for ES6 less | |
function leftPad(v, n, c){ | |
c = c ? '0' : c; | |
return String(v).length >= n ? '' + v : (String(c).repeat(n) + v).slice(-n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment