Comparing version 1.7.0 to 1.8.0
239
lib/util.js
@@ -67,3 +67,3 @@ (function(scope) { | ||
* Check is all arguments with names present | ||
* | ||
* | ||
* @param name | ||
@@ -103,6 +103,6 @@ * @param arg | ||
check.check = check; | ||
/** | ||
* Check is type of arg with name is equal to type | ||
* | ||
* | ||
* @param name | ||
@@ -126,3 +126,3 @@ * @param arg | ||
* Copy properties from from to to | ||
* | ||
* | ||
* @param from | ||
@@ -147,3 +147,3 @@ * @param to | ||
* copy objFrom properties to target | ||
* | ||
* | ||
* @target | ||
@@ -154,3 +154,3 @@ * @objFrom | ||
var obj, | ||
keys, | ||
keys, | ||
proto, | ||
@@ -164,3 +164,3 @@ isFunc = Util.type.function(objFrom), | ||
objFrom.forEach(function(item) { | ||
ret = Util.extend(target, item); | ||
ret = Util.extend(target, item); | ||
}); | ||
@@ -188,3 +188,3 @@ | ||
* extend proto | ||
* | ||
* | ||
* @obj | ||
@@ -205,3 +205,3 @@ */ | ||
* @param str | ||
*/ | ||
*/ | ||
this.parse = function(str) { | ||
@@ -230,104 +230,3 @@ var obj; | ||
} | ||
/** | ||
* function check is strings are equal | ||
* @param {String} str1 | ||
* @param {String, Array} str2 | ||
*/ | ||
this.strCmp = function(str1, str2) { | ||
var isEqual, | ||
type = Util.type(str2); | ||
switch(type) { | ||
case 'array': | ||
str2.some(function(str) { | ||
isEqual = Util.strCmp(str1, str); | ||
return isEqual; | ||
}); | ||
break; | ||
case 'string': | ||
isEqual = str1 === str2; | ||
break; | ||
} | ||
return isEqual; | ||
}; | ||
/** | ||
* function log pArg if it's not empty | ||
* @param pArg | ||
*/ | ||
this.log = function() { | ||
var args = [].slice.call(arguments), | ||
console = Scope.console, | ||
lDate = '[' + Util.getDate() + '] '; | ||
if (console && args.length && args[0]) { | ||
args.unshift(lDate); | ||
console.log.apply(console, args); | ||
args.shift(); | ||
} | ||
return args.join(' '); | ||
}; | ||
/** | ||
* function remove substring from string | ||
* @param str | ||
* @param substr | ||
*/ | ||
this.rmStr = function(str, substr, isOnce) { | ||
var replace, | ||
strArray = [], | ||
isString = Util.type.string(str), | ||
isArray = Util.type.array(substr), | ||
replaceStr = function(str, strItem) { | ||
var ret = str.replace(strItem, ''); | ||
return ret; | ||
}; | ||
replace = isOnce ? replaceStr : Util.replaceStr; | ||
if (isString && substr) { | ||
if (isArray) | ||
strArray = substr; | ||
else | ||
strArray.push(substr); | ||
strArray.forEach(function(strItem) { | ||
str = replace(str, strItem, ''); | ||
}); | ||
} | ||
return str; | ||
}; | ||
/** | ||
* function replase pFrom to pTo in pStr | ||
* @param str | ||
* @param from | ||
* @param to | ||
* @param notEscape | ||
*/ | ||
this.replaceStr = function(str, from, to, notEscape) { | ||
var regExp, | ||
isStr = Util.type.string(str); | ||
if (isStr && from) { | ||
if (!notEscape) | ||
from = Util.escapeRegExp(from); | ||
regExp = new RegExp(from, 'g'); | ||
str = str.replace(regExp, to); | ||
} | ||
return str; | ||
}; | ||
this.escapeRegExp = function(str) { | ||
@@ -351,6 +250,7 @@ var isStr = Util.type.string(str); | ||
wildcard = '^' + wildcard; /* search from start of line */ | ||
wildcard = Util.replaceStr(wildcard, '.', '\\.'); | ||
wildcard = Util.replaceStr(wildcard, '*', '.*'); | ||
wildcard = Util.replaceStr(wildcard, '?', '.?\\'); | ||
wildcard = '^' + wildcard /* search from start of line */ | ||
.replace('.', '\\.') | ||
.replace('*', '.*') | ||
.replace('?', '.?'); | ||
wildcard += '$'; /* search to end of line */ | ||
@@ -377,3 +277,3 @@ | ||
str = view[param]; | ||
regExp = RegExp('{{\\s*' + param + '\\s*}}', 'g'); | ||
regExp = RegExp('{{\\s' + param + '\\s}}', 'g'); | ||
result = result.replace(regExp, str); | ||
@@ -383,3 +283,3 @@ }); | ||
if (~result.indexOf('{{')) | ||
result = result.replace(/{{\s*.*\s*}}/, ''); | ||
result = result.replace(/{{.*}}/g, ''); | ||
@@ -394,7 +294,7 @@ return result; | ||
* get type of variable | ||
* | ||
* | ||
* @param variable | ||
*/ | ||
function type(variable) { | ||
var regExp = new RegExp('\\s([a-zA-Z]+)'), | ||
var regExp = /\s([a-zA-Z]+)/, | ||
str = {}.toString.call(variable), | ||
@@ -409,3 +309,3 @@ typeBig = str.match(regExp)[1], | ||
* functions check is variable is type of name | ||
* | ||
* | ||
* @param variable | ||
@@ -421,3 +321,3 @@ */ | ||
['arrayBuffer', 'object', 'file', 'array'] | ||
['null', 'arrayBuffer', 'file', 'array', 'object'] | ||
.forEach(function(name) { | ||
@@ -503,3 +403,3 @@ type[name] = typeOf.bind(null, name); | ||
* exec function if it exist in object | ||
* | ||
* | ||
* @param obj | ||
@@ -604,3 +504,3 @@ * @param name | ||
* try...catch block | ||
* | ||
* | ||
* @param callback | ||
@@ -624,2 +524,3 @@ */ | ||
* function gets file extension | ||
* | ||
* @param pFileName | ||
@@ -645,16 +546,14 @@ * @return Ext | ||
* get values from Object Array name properties | ||
* or | ||
* or | ||
* @pObj | ||
*/ | ||
this.getNamesFromObjArray = function(arr) { | ||
var ret = [], | ||
isArray = Util.type.array(arr); | ||
var ret = []; | ||
if (arr && !isArray) | ||
arr = arr.data; | ||
if (!Array.isArray(arr)) | ||
throw(Error('arr should be array!')); | ||
if (arr) | ||
arr.forEach(function(item) { | ||
ret.push(item.name || item); | ||
}); | ||
ret = arr.map(function(item) { | ||
return item.name; | ||
}); | ||
@@ -666,3 +565,3 @@ return ret; | ||
* find object by name in arrray | ||
* | ||
* | ||
* @param array | ||
@@ -672,28 +571,33 @@ * @param name | ||
this.findObjByNameInArr = function(array, name) { | ||
var ret, | ||
isArray = Util.type.array(array); | ||
var ret; | ||
if (isArray) { | ||
array.some(function(item) { | ||
var is = item.name === name, | ||
isArray = Util.type.array(item); | ||
if (is) | ||
ret = item; | ||
else if (isArray) | ||
item.some(function(item) { | ||
is = item.name === name; | ||
if (is) | ||
ret = item.data; | ||
}); | ||
return is; | ||
}); | ||
} | ||
if (!Array.isArray(array)) | ||
throw(Error('array should be array!')); | ||
if (typeof name !== 'string') | ||
throw(Error('name should be string!')); | ||
array.some(function(item) { | ||
var is = item.name === name, | ||
isArray = Util.type.array(item); | ||
if (is) | ||
ret = item; | ||
else if (isArray) | ||
item.some(function(item) { | ||
is = item.name === name; | ||
if (is) | ||
ret = item.data; | ||
return is; | ||
}); | ||
return is; | ||
}); | ||
return ret; | ||
}; | ||
/** | ||
/** | ||
* Gets current time in format hh:mm:ss | ||
@@ -740,33 +644,4 @@ */ | ||
}; | ||
/** | ||
* Gets current date in format yy.mm.dd hh:mm:ss | ||
*/ | ||
this.getDate = function() { | ||
var date = Util.getShortDate(), | ||
time = Util.getTime(), | ||
ret = date + ' ' + time; | ||
return ret; | ||
}; | ||
this.getShortDate = function() { | ||
var ret, | ||
date = new Date(), | ||
day = date.getDate(), | ||
month = date.getMonth() + 1, | ||
year = date.getFullYear(); | ||
if (month <= 9) | ||
month = '0' + month; | ||
if (day <= 9) | ||
day = '0' + day; | ||
ret = year + '.' + month + '.' + day; | ||
return ret; | ||
}; | ||
} | ||
})(this); |
{ | ||
"name": "util-io", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)", | ||
@@ -5,0 +5,0 @@ "description": "Util-io - utilites for vanila js", |
Sorry, the diff of this file is not supported yet
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
24409
494