typings, hex number conversion
This commit is contained in:
		
							
								
								
									
										38
									
								
								index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								index.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * encode a string to base64
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {string} str string to encode
 | 
				
			||||||
 | 
					 * @param {string} encoding encoding the string is in
 | 
				
			||||||
 | 
					 * @returns {string} base64
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function to_b64(str: string, encoding?: string): string;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * encode a string to hex
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {string} str string to encode
 | 
				
			||||||
 | 
					 * @param {string} encoding encoding the string is in
 | 
				
			||||||
 | 
					 * @returns {string} hex
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function to_hex(str: string, encoding?: string): string;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * encode a string to utf-8
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {string} str string to encode
 | 
				
			||||||
 | 
					 * @param {string} encoding encoding the string is in
 | 
				
			||||||
 | 
					 * @returns {string} utf-8
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function to_utf8(str: string, encoding: string): string;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * encode a number to hex
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {number} n number to encode
 | 
				
			||||||
 | 
					 * @returns {string} hex
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function num_to_hex(n: number): string;
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * decode a number from hex
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {string} h hex to decode
 | 
				
			||||||
 | 
					 * @returns {number} number
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export function hex_to_num(h: string): number;
 | 
				
			||||||
							
								
								
									
										24
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								index.js
									
									
									
									
									
								
							@@ -44,9 +44,31 @@ function to_hex (str, encoding = '') {
 | 
				
			|||||||
  return buf.toString ('hex');
 | 
					  return buf.toString ('hex');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * encode a number to hex
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {number} n number to encode
 | 
				
			||||||
 | 
					 * @returns {string} hex
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function num_to_hex (n) {
 | 
				
			||||||
 | 
					  return n.toString(16);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * decode a number from hex
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @param {string} h hex to decode
 | 
				
			||||||
 | 
					 * @returns {number} number
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function hex_to_num (h) {
 | 
				
			||||||
 | 
					  return parseInt(h, 16);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = {
 | 
					module.exports = {
 | 
				
			||||||
  to_b64,
 | 
					  to_b64,
 | 
				
			||||||
  to_hex,
 | 
					  to_hex,
 | 
				
			||||||
  to_utf8
 | 
					  to_utf8,
 | 
				
			||||||
 | 
					  num_to_hex,
 | 
				
			||||||
 | 
					  hex_to_num
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user