utils.js docs

This commit is contained in:
Marek Kotewicz 2015-03-08 10:36:16 +01:00
parent 344428b3b5
commit e2352b48d3
3 changed files with 102 additions and 24 deletions

61
dist/ethereum.js vendored
View File

@ -1865,10 +1865,13 @@ var unitMap = {
};
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
/// @returns index of element
/** Finds first index of array element matching pattern
*
* @method findIndex
* @param {Array}
* @param {Function} pattern
* @returns {Number} index of element
*/
var findIndex = function (array, callback) {
var end = false;
var i = 0;
@ -1878,7 +1881,13 @@ var findIndex = function (array, callback) {
return end ? i - 1 : -1;
};
/// @returns ascii string representation of hex value prefixed with 0x
/**
* Should be called to get sting from it's hex representation
*
* @method toAscii
* @param {String} string in hex
* @returns {String} ascii string representation of hex value
*/
var toAscii = function(hex) {
// Find termination
var str = "";
@ -1898,6 +1907,13 @@ var toAscii = function(hex) {
return str;
};
/**
* Shold be called to get hex representation (prefixed by 0x) of ascii string
*
* @method fromAscii
* @param {String} string
* @returns {String} hex representation of input string
*/
var toHexNative = function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
@ -1908,7 +1924,14 @@ var toHexNative = function(str) {
return hex;
};
/// @returns hex representation (prefixed by 0x) of ascii string
/**
* Shold be called to get hex representation (prefixed by 0x) of ascii string
*
* @method fromAscii
* @param {String} string
* @param {Number} optional padding
* @returns {String} hex representation of input string
*/
var fromAscii = function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = toHexNative(str);
@ -1917,7 +1940,13 @@ var fromAscii = function(str, pad) {
return "0x" + hex;
};
/// @returns display name for function/event eg. multiply(uint256) -> multiply
/**
* Should be called to get display name of contract function
*
* @method extractDisplayName
* @param {String} name of function/event
* @returns {String} display name for function/event eg. multiply(uint256) -> multiply
*/
var extractDisplayName = function (name) {
var length = name.indexOf('(');
return length !== -1 ? name.substr(0, length) : name;
@ -1930,16 +1959,26 @@ var extractTypeName = function (name) {
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/// Filters all events form input abi
/// @returns abi array with filtered objects of type 'event'
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';

File diff suppressed because one or more lines are too long

View File

@ -44,10 +44,13 @@ var unitMap = {
};
/// Finds first index of array element matching pattern
/// @param array
/// @param callback pattern
/// @returns index of element
/** Finds first index of array element matching pattern
*
* @method findIndex
* @param {Array}
* @param {Function} pattern
* @returns {Number} index of element
*/
var findIndex = function (array, callback) {
var end = false;
var i = 0;
@ -57,7 +60,13 @@ var findIndex = function (array, callback) {
return end ? i - 1 : -1;
};
/// @returns ascii string representation of hex value prefixed with 0x
/**
* Should be called to get sting from it's hex representation
*
* @method toAscii
* @param {String} string in hex
* @returns {String} ascii string representation of hex value
*/
var toAscii = function(hex) {
// Find termination
var str = "";
@ -77,6 +86,13 @@ var toAscii = function(hex) {
return str;
};
/**
* Shold be called to get hex representation (prefixed by 0x) of ascii string
*
* @method fromAscii
* @param {String} string
* @returns {String} hex representation of input string
*/
var toHexNative = function(str) {
var hex = "";
for(var i = 0; i < str.length; i++) {
@ -87,7 +103,14 @@ var toHexNative = function(str) {
return hex;
};
/// @returns hex representation (prefixed by 0x) of ascii string
/**
* Shold be called to get hex representation (prefixed by 0x) of ascii string
*
* @method fromAscii
* @param {String} string
* @param {Number} optional padding
* @returns {String} hex representation of input string
*/
var fromAscii = function(str, pad) {
pad = pad === undefined ? 0 : pad;
var hex = toHexNative(str);
@ -96,7 +119,13 @@ var fromAscii = function(str, pad) {
return "0x" + hex;
};
/// @returns display name for function/event eg. multiply(uint256) -> multiply
/**
* Should be called to get display name of contract function
*
* @method extractDisplayName
* @param {String} name of function/event
* @returns {String} display name for function/event eg. multiply(uint256) -> multiply
*/
var extractDisplayName = function (name) {
var length = name.indexOf('(');
return length !== -1 ? name.substr(0, length) : name;
@ -109,16 +138,26 @@ var extractTypeName = function (name) {
return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
};
/// Filters all function from input abi
/// @returns abi array with filtered objects of type 'function'
/**
* Filters all functions from input abi
*
* @method filterFunctions
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'function'
*/
var filterFunctions = function (json) {
return json.filter(function (current) {
return current.type === 'function';
});
};
/// Filters all events form input abi
/// @returns abi array with filtered objects of type 'event'
/**
* Filters all events from input abi
*
* @method filterEvents
* @param {Array} abi
* @returns {Array} abi array with filtered objects of type 'event'
*/
var filterEvents = function (json) {
return json.filter(function (current) {
return current.type === 'event';