Comparing version 1.4.0 to 1.5.0
@@ -53,3 +53,3 @@ --- | ||
```js | ||
Util.exec.ret(callback, p1, p2, pN); | ||
Util.exec.ret(callback, p1, p2, pN); | ||
``` | ||
@@ -86,3 +86,3 @@ | ||
```js | ||
exec.if(2 > 3, one, two); | ||
exec.if(2 > 3, one, two); | ||
``` | ||
@@ -89,0 +89,0 @@ |
272
lib/util.js
@@ -193,3 +193,3 @@ (function(scope) { | ||
Util.exec.tryLog(function() { | ||
Util.exec.try(function() { | ||
str = JSON.stringify(obj, null, 4); | ||
@@ -229,77 +229,3 @@ }); | ||
this.getStrBigFirst = function(str) { | ||
var isStr = Util.type.string(str), | ||
ret = str; | ||
if (isStr && str.length) | ||
ret = str[0].toUpperCase() + str.substring(1); | ||
return ret; | ||
}; | ||
/** | ||
* function returns is str1 contains str2 | ||
* @param str1 | ||
* @param str2 | ||
*/ | ||
this.isContainStr = function(str1, str2) { | ||
var i, n, str, is, index, | ||
isStr = Util.type.string(str1), | ||
type = Util.type(str2); | ||
if (isStr) | ||
switch (type) { | ||
case 'array': | ||
n = str2.length; | ||
for (i = 0; i < n; i++) { | ||
str = str2[i]; | ||
is = Util.isContainStr(str1, str); | ||
if (is) | ||
break; | ||
} | ||
break; | ||
case 'string': | ||
index = str1.indexOf(str2); | ||
is = index >= 0; | ||
break; | ||
} | ||
return is; | ||
}; | ||
/** | ||
* is pStr1 contains pStr2 at begin | ||
* @param pStr1 | ||
* @param pStr2 | ||
*/ | ||
this.isContainStrAtBegin = function(pStr1, pStr2) { | ||
var i, n, length, subStr, ret, | ||
isStr1 = Util.type.string(pStr1), | ||
isArr2 = Util.type.array(pStr2); | ||
if (isStr1) | ||
if (isArr2) { | ||
n = pStr2.length; | ||
for(i = 0; i < n; i++) { | ||
ret = Util.isContainStrAtBegin(pStr1, pStr2[i]); | ||
if (ret) | ||
break; | ||
} | ||
} else { | ||
length = pStr2.length, | ||
subStr = pStr1.substring(0, length); | ||
ret = subStr === pStr2; | ||
} | ||
return ret; | ||
}; | ||
/** | ||
* function log pArg if it's not empty | ||
@@ -325,36 +251,2 @@ * @param pArg | ||
/** | ||
* log array of elements | ||
* @param array | ||
*/ | ||
this.logArray = function(array) { | ||
var isArray = Util.type.array(array); | ||
if (isArray) | ||
array.forEach(function(item) { | ||
Util.log(item); | ||
}); | ||
return array; | ||
}; | ||
/** | ||
* function log pArg if it's not empty | ||
* @param pArg | ||
*/ | ||
this.logError = function(pArg) { | ||
var lConsole = Scope.console, | ||
lDate = '[' + Util.getDate() + '] '; | ||
if (lConsole && pArg) { | ||
var lMsg = pArg.message; | ||
if (lMsg) | ||
lDate += pArg.message + ' '; | ||
lConsole.error(lDate, pArg); | ||
} | ||
return pArg; | ||
}; | ||
/** | ||
* function remove substring from string | ||
@@ -426,17 +318,2 @@ * @param str | ||
/** | ||
* function convert name: rm: '(, ), -, " "' | ||
* | ||
* @name | ||
* convert | ||
*/ | ||
this.convertName = function(name) { | ||
var conv = name && name.toLowerCase(); | ||
conv = Util.rmStr(conv, ['(', ')']); | ||
conv = Util.replaceStr(conv, ' ', '-'); | ||
return conv; | ||
}; | ||
this.escapeRegExp = function(str) { | ||
@@ -494,3 +371,3 @@ var isStr = Util.type.string(str); | ||
this.ownRender = function(templ, view, symbols, notEscape) { | ||
var str, param, expr, | ||
var str, expr, | ||
ret = templ, | ||
@@ -503,8 +380,10 @@ firstChar, | ||
for (param in view) { | ||
str = view[param]; | ||
str = Util.exec(str) || str; | ||
expr = firstChar + param + secondChar; | ||
ret = Util.replaceStr(ret, expr, str, notEscape); | ||
} | ||
Object | ||
.keys(view) | ||
.forEach(function(param) { | ||
str = view[param]; | ||
str = Util.exec(str) || str; | ||
expr = firstChar + param + secondChar; | ||
ret = Util.replaceStr(ret, expr, str, notEscape); | ||
}); | ||
@@ -535,90 +414,24 @@ expr = firstChar + '.*' + secondChar; | ||
/** | ||
* functions check is variable is array | ||
* functions check is variable is type of name | ||
* | ||
* @param variable | ||
*/ | ||
type.array = function(variable) { | ||
var result; | ||
if (Array.isArray) | ||
result = Array.isArray(variable) ; | ||
else | ||
result = type(variable) === 'array'; | ||
return result; | ||
}; | ||
function typeOf(name, variable) { | ||
return type(variable) === name; | ||
} | ||
/** | ||
* functions check is variable is arrayBuffer | ||
* @param variable | ||
*/ | ||
type.arrayBuffer = function(variable) { | ||
return type(variable) === 'arraybuffer'; | ||
}; | ||
function typeOfSimple(name, variable) { | ||
return typeof variable === name; | ||
} | ||
/** | ||
* functions check is variable is boolean | ||
* @param variable | ||
*/ | ||
type.boolean = function(variable) { | ||
return typeof variable === 'boolean'; | ||
}; | ||
['arrayBuffer', 'object', 'file', 'array'] | ||
.forEach(function(name) { | ||
type[name] = typeOf.bind(null, name); | ||
}); | ||
/** | ||
* functions check is variable is function | ||
* @param variable | ||
*/ | ||
type.function = function(variable) { | ||
return typeof variable === 'function'; | ||
}; | ||
['string', 'undefined', 'boolean', 'number', 'function'] | ||
.forEach(function(name) { | ||
type[name] = typeOfSimple.bind(null, name); | ||
}); | ||
/** | ||
* functions check is variable is number | ||
* @param variable | ||
*/ | ||
type.number = function(variable) { | ||
return typeof variable === 'number'; | ||
}; | ||
/** | ||
* functions check is variable is object | ||
* @param variable | ||
*/ | ||
type.object = function(variable) { | ||
var type = Util.type(variable), | ||
is = type === 'object'; | ||
return is; | ||
}; | ||
/** | ||
* functions check is variable is string | ||
* @param variable | ||
*/ | ||
type.string = function(variable) { | ||
return typeof variable === 'string'; | ||
}; | ||
/** | ||
* functions check is variable is string | ||
* @param variable | ||
*/ | ||
type.undefined = function(variable) { | ||
return typeof variable === 'undefined'; | ||
}; | ||
/** | ||
* functions check is variable is File | ||
* @param variable | ||
*/ | ||
type.file = function(variable) { | ||
var FILE = '[object File]', | ||
name, is; | ||
name = Util.exec.ifExist(variable, 'toString'); | ||
is = name === FILE; | ||
return is; | ||
}; | ||
return type; | ||
@@ -628,11 +441,2 @@ } | ||
/** | ||
* function return false | ||
*/ | ||
this.retFalse = function() { | ||
var ret = false; | ||
return ret; | ||
}; | ||
/** | ||
* function makes new array based on first | ||
@@ -742,6 +546,4 @@ * | ||
if (func) { | ||
func = func.bind(obj); | ||
ret = exec(func, arg); | ||
} | ||
if (func) | ||
func = func.apply(obj, arg); | ||
@@ -850,16 +652,2 @@ return ret; | ||
/** | ||
* function execute param function in | ||
* try...catch block and log result | ||
* | ||
* @param tryFunc | ||
*/ | ||
exec.tryLog = function(tryFunc) { | ||
var ret; | ||
ret = this.try(tryFunc); | ||
return Util.logError(ret); | ||
}; | ||
return exec; | ||
@@ -966,3 +754,3 @@ } | ||
Util.exec.ifExist(console, 'time', name); | ||
Util.exec.ifExist(console, 'time', [name]); | ||
@@ -979,3 +767,3 @@ return this; | ||
Util.exec.ifExist(console, 'timeEnd', name); | ||
Util.exec.ifExist(console, 'timeEnd', [name]); | ||
@@ -982,0 +770,0 @@ return this; |
{ | ||
"name": "util-io", | ||
"version": "1.4.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
"description": "Util.io - utilites for vanila js", | ||
"homepage": "http://github.com/coderaiser/util.io", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/coderaiser/util.io.git" | ||
}, | ||
"dependencies": { | ||
}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=0.4.x" | ||
}, | ||
"main": "./lib/util.js" | ||
"name": "util-io", | ||
"version": "1.5.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
"description": "Util-io - utilites for vanila js", | ||
"homepage": "http://github.com/coderaiser/util-io", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/coderaiser/util-io.git" | ||
}, | ||
"dependencies": {}, | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=0.4.x" | ||
}, | ||
"main": "lib/util.js" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28740
627