Created
July 14, 2014 19:22
-
-
Save OhMeadhbh/21508f6fe4210b9f0877 to your computer and use it in GitHub Desktop.
javascript utility functions
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
// function _pad() | |
// | |
// pads the input with count numbers of char characters. Examples: | |
// _pad( "7" ) => "7" | |
// _pad( "A", 4 ) => " A" | |
// _pad( "7", 4, "*" ) => "***7" | |
function _pad( input, count, char ) { | |
count = count ? count : 0; | |
return String( Array( count ).join( ( char ? char : ' ' ) ) + input ).slice( - count ); | |
} | |
// function _hex_pad() | |
// | |
// returns a hex string from a number, padded with count zeros. | |
// _hex_pad( 12, 4 ) => "000C" | |
function _hex_pad( input, count ) { | |
return _pad( input.toString(16), count, '0' ).toUpperCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment