Skip to content

Commit

Permalink
feature(package) v0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Feb 17, 2014
1 parent 5717e7e commit 9370aad
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 89 deletions.
114 changes: 27 additions & 87 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@
}
},

/*
* bind function to arguments without context
*/

this.bind = function(callback) {
var result,
args = Util.slice(arguments, 1),
bind = Function.prototype.bind;

args.unshift(null);
result = bind.apply(callback, args);

return result;
};

/**
* ad new line (if it's not)
* @param {string} pText
Expand All @@ -80,25 +95,6 @@
return text;
};

/**
* callback for functions(pError, pData)
* thet moves on our parameters.
*
* @param pFunc
* @param pParams
*/
this.call = function(pFunc, pParams) {
function lFunc(pError, pData) {
Util.exec(pFunc, {
error : pError,
data : pData,
params : pParams
});
}

return lFunc;
};

/**
* Функция ищет в имени файла расширение
* и если находит возвращает true
Expand Down Expand Up @@ -729,17 +725,15 @@
* return save exec function
* @param callback
*/
this.retExec = function(callback) {
var args = Util.slice(arguments);
this.retExec = function() {
var result,
exec = Util.exec.bind(Util),
args = Util.slice(arguments);

return function() {
var argsLocal = Util.slice(arguments);
callback;

argsLocal = args.concat(argsLocal);

Util.exec.apply(null, argsLocal);
};
args.unshift(exec);
result = Util.bind.apply(null, args);

return result;
};

/**
Expand Down Expand Up @@ -769,52 +763,6 @@
};
};

/**
* set value to property of object, if object exist
* @param pArgs {object, property, value}
*/
this.setValue = function(pArgs) {
var lRet = false;

if ( Util.isObject(pArgs) ) {
var lObj = pArgs.object,
lProp = pArgs.property,
lVal = pArgs.lVal;

if (lObj) {
lObj[lProp] = lVal;
lRet = true;
}
}

return lRet;
};

/**
* set timout before callback would be called
* @param pArgs {func, callback, time}
*/
this.setTimeout = function(pArgs) {
var lDone,
lFunc = pArgs.func,
lTime = pArgs.time || 1000,
lCallBack = function(pArgument) {
if (!lDone) {
lDone = Util.exec(pArgs.callback, pArgument);
}
};

var lTimeoutFunc = function() {
setTimeout(function() {
Util.exec(lFunc, lCallBack);
if (!lDone)
lTimeoutFunc();
}, lTime);
};

lTimeoutFunc();
};

/**
* function makes new array based on first
*
Expand Down Expand Up @@ -901,19 +849,11 @@
* @param pArgN
*/
this.exec = function(callback) {
var ret, args = Util.slice(arguments);

args.shift();
var ret,
args = Util.slice(arguments, 1);

if (callback) {
if (Util.isFunction(callback))
ret = callback.apply(null, args);
else {
callback = callback.callback || callback.success;
args.unshift(callback);
ret = Util.exec.apply(null, args);
}
}
if (Util.isFunction(callback))
ret = callback.apply(null, args);

return ret;
};
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudcmd",
"version": "0.7.0",
"name": "util.io",
"version": "0.7.1",
"author": "coderaiser <[email protected]> (https://github.com/coderaiser)",
"description": "Util.io - utilites for vanila js",
"homepage": "http://github.com/coderaiser/util.io",
Expand Down

0 comments on commit 9370aad

Please sign in to comment.