1 /** 2 * @file Helper methods 3 * 4 * @author Dominik Kocuj 5 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2 or later 6 * @copyright Copyright (c) 2016-2018 kocuj.pl 7 */ 8 9 (function() {})(); // empty function for correct minify with comments 10 //'use strict'; // for jshint uncomment this and comment line above 11 12 /* jshint strict: true */ 13 /* jshint -W034 */ 14 15 /** 16 * Helper prototype constructor 17 * 18 * @constructs 19 * @namespace kocujILV12aCHelper 20 * @public 21 * @return {void} 22 */ 23 function kocujILV12aCHelper() { 24 } 25 26 /** 27 * Helper prototype 28 * 29 * @namespace kocujILV12aCHelper 30 * @public 31 */ 32 kocujILV12aCHelper.prototype = { 33 /** 34 * Initialize numeric integer value 35 * 36 * @public 37 * @param {(number|string)} value Value to initialize 38 * @return {(number|string)} Initialized value or empty string if there was an error 39 */ 40 initNumeric : function(value) { 41 'use strict'; 42 // initialize numeric value 43 if (value !== undefined) { 44 value = parseInt(value, 10); 45 if (isNaN(value)) { 46 return ''; 47 } 48 } else { 49 return ''; 50 } 51 // exit 52 return value; 53 }, 54 55 /** 56 * Initialize numeric float value 57 * 58 * @public 59 * @param {(number|string)} value Value to initialize 60 * @return {(number|string)} Initialized value or empty string if there was an error 61 */ 62 initNumericFloat : function(value) { 63 'use strict'; 64 // initialize numeric value 65 if (value !== undefined) { 66 value = parseFloat(value, 10); 67 if (isNaN(value)) { 68 return ''; 69 } 70 } else { 71 return ''; 72 } 73 // exit 74 return value; 75 }, 76 77 /** 78 * Initialize string value 79 * 80 * @public 81 * @param {string} value Value to initialize 82 * @return {string} Initialized value or empty string if there was an error 83 */ 84 initString : function(value) { 85 'use strict'; 86 // initialize string value 87 if (typeof value !== 'string') { 88 if (typeof value === 'number') { 89 return value.toString(); 90 } else { 91 return ''; 92 } 93 } 94 // exit 95 return value; 96 }, 97 98 /** 99 * Initialize boolean value 100 * 101 * @public 102 * @param {(boolean|number|string)} value Value to initialize; 1 means true and 0 means false 103 * @return {boolean} Initialized value or empty string if there was an error 104 */ 105 initBoolean : function(value) { 106 'use strict'; 107 // initialize boolean value 108 if (typeof value !== 'boolean') { 109 if (typeof value === 'number') { 110 if ((value !== 0) && (value !== 1)) { 111 return ''; 112 } 113 value = (value === 1); 114 } else { 115 return ''; 116 } 117 } 118 // exit 119 return value; 120 }, 121 122 /** 123 * Initialize function value 124 * 125 * @public 126 * @param {function} value Value to initialize 127 * @return {(boolean|function)} Initialized value or false if there was an error 128 */ 129 initFunction : function(value) { 130 'use strict'; 131 // initialize function value 132 if ((typeof value !== 'function') && (typeof value !== 'object')) { 133 return false; 134 } 135 // exit 136 return value; 137 }, 138 139 /** 140 * Initialize object value 141 * 142 * @public 143 * @param {Object} value Value to initialize 144 * @return {Object} Initialized value or empty string if there was an error 145 */ 146 initObject : function(value) { 147 'use strict'; 148 // initialize function value 149 if (typeof value !== 'object') { 150 return ''; 151 } 152 // exit 153 return value; 154 }, 155 156 /** 157 * Initialize any value 158 * 159 * @public 160 * @param {anything} value Value to initialize 161 * @return {anything} Initialized value or empty string if there was an error 162 */ 163 initAny : function(value) { 164 'use strict'; 165 // initialize any value 166 if (value === undefined) { 167 return ''; 168 } 169 // exit 170 return value; 171 } 172 }; 173 174 // initialize 175 var kocujILV12aHelper = new kocujILV12aCHelper(); 176