Skip to content

Instantly share code, notes, and snippets.

@ruyaoyao
Last active March 25, 2016 16:01
Show Gist options
  • Save ruyaoyao/a8314aa0a6186d26a125 to your computer and use it in GitHub Desktop.
Save ruyaoyao/a8314aa0a6186d26a125 to your computer and use it in GitHub Desktop.
leftPad implementation
// 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