Author: ygrego Date: 2015-06-10 08:50:42 +0000 (Wed, 10 Jun 2015) New Revision: 1681 Url: http://forge.nuiton.org/projects/sandbox/repository/revisions/1681 Log: Utils.js has been deleted and its content has been moved to class OipfUtils.js Added: oipf/lib/js/utils/OipfUtils.js Removed: oipf/lib/js/utils/Utils.js Copied: oipf/lib/js/utils/OipfUtils.js (from rev 1680, oipf/lib/js/utils/Utils.js) =================================================================== --- oipf/lib/js/utils/OipfUtils.js (rev 0) +++ oipf/lib/js/utils/OipfUtils.js 2015-06-10 08:50:42 UTC (rev 1681) @@ -0,0 +1,95 @@ +class OipfUtils { + + static initProperties(defaultProperties) { + var keys = Object.keys(defaultProperties); + for (var i = 0, l = keys.length; i < l; i++) { + this[keys[i]] = defaultProperties[keys[i]]; + } + } + + static timeout(time) { + return new Timeout(time); + } + + static equals(field1, field2) { + return field1 == field2; + } + + static notEquals(field1, field2) { + return field1 != field2; + } + + static superior(field1, field2) { + return field1 > field2; + } + + static superiorOrEquals(field1, field2) { + return field1 >= field2; + } + + static inferior(field1, field2) { + return field1 < field2; + } + + static inferiorOrEquals(field1, field2) { + return field1 <= field2; + } + + static contains(field1, field2) { + return field1 == field2; + } + + static generateFourDigit() { + + return Math.floor(Math.random() * 9000) + 1000; + } + + static getRandomNumberBetweenMinMax(min, max) { + return Math.floor(Math.random() * (max - min)) + min; + } + + static isPresent(list, element) { + + for (var i = 0, l = list.length; i < l; i++) { + if (OipfUtils.equals(list[i].name, element)) { + return true; + } + } + } + + /* + * Some code based on RFC 4122, section 4.4 + * (Algorithms for Creating a UUID from Truly Random or Pseudo-Random Number). + */ + static createUUID() { + // http://www.ietf.org/rfc/rfc4122.txt + var s = []; + var hexDigits = "0123456789abcdef"; + for (var i = 0; i < 36; i++) { + s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); + } + s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 + s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 + s[8] = s[13] = s[18] = s[23] = "-"; + + var uuid = s.join(""); + return uuid; + } + + /* + * Description: + * Should be use in each test method in anticipation of tests executed on a tv platform. + */ + static isMethodImplemented(object, methodName) { + return object[methodName]; + } + + static upperCaseFirstChar(string) { + return string.charAt(0).toUpperCase() + string.slice(1); + } + + static logTest() { + console.log.apply(console, arguments); + } + +} Deleted: oipf/lib/js/utils/Utils.js =================================================================== --- oipf/lib/js/utils/Utils.js 2015-06-10 08:13:47 UTC (rev 1680) +++ oipf/lib/js/utils/Utils.js 2015-06-10 08:50:42 UTC (rev 1681) @@ -1,121 +0,0 @@ -/* - * Some code based on RFC 4122, section 4.4 - * (Algorithms for Creating a UUID from Truly Random or Pseudo-Random Number). - */ -var oipf = { - utils: {} -}; - - -oipf.utils.initProperties = function(defaultProperties) { - var keys = Object.keys(defaultProperties); - for (var i = 0, l = keys.length; i < l; i++) { - this[keys[i]] = defaultProperties[keys[i]]; - } -}; - -oipf.utils.timeout = function(time) { - return new Timeout(time); -}; - -oipf.utils.equals = function(field1, field2) { - return field1 == field2; -}; - -oipf.utils.notEquals = function(field1, field2) { - return field1 != field2; -}; - -oipf.utils.superior = function(field1, field2) { - return field1 > field2; -}; - -oipf.utils.superiorOrEquals = function(field1, field2) { - return field1 >= field2; -}; - -oipf.utils.inferior = function(field1, field2) { - return field1 < field2; -}; - -oipf.utils.inferiorOrEquals = function(field1, field2) { - return field1 <= field2; -}; - -oipf.utils.contains = function(field1, field2) { - return field1 == field2; -}; - -oipf.utils.generateFourDigit = function() { - - return Math.floor(Math.random() * 9000) + 1000; -}; - -oipf.utils.getRandomNumberBetweenMinMax = function(min, max) { - return Math.floor(Math.random() * (max - min)) + min; -}; - -oipf.utils.isPresent = function(list, element) { - - for (var i = 0, l = list.length; i < l; i++) { - if (oipf.utils.equals(list[i].name, element)) { - return true; - } - } -}; - -function createUUID() { - // http://www.ietf.org/rfc/rfc4122.txt - var s = []; - var hexDigits = "0123456789abcdef"; - for (var i = 0; i < 36; i++) { - s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); - } - s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010 - s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01 - s[8] = s[13] = s[18] = s[23] = "-"; - - var uuid = s.join(""); - return uuid; -} - -/* - * Description: - * Should be use in each test method in anticipation of tests executed on a tv platform. - */ -function isMethodImplemented(object, methodName) { - return object[methodName]; -} - -/* - * Description: - * Encapsulation of function "setTimeout" in order to it be accessible for all object and also reusable. - */ -function timeout(time) { - return new Promise(function(resolve, reject) { - setTimeout(resolve, time); - }); -} - -function upperCaseFirstChar(string) { - return string.charAt(0).toUpperCase() + string.slice(1); -} - -function logTest() { - console.log.apply(console, arguments); -} - -function createCustomEvent(type, param) { - return new CustomEvent(type, {detail :param}); -} - -function updateProperty(id, property, value){ - var getElById = document.getElementById.bind(document); - - if (property == "backgroundColor") { - getElById(id)["style"][property] = value; - } else { - getElById(id)[property] = value; - } - -}
participants (1)
-
ygregoï¼ users.nuiton.org