feature(bower) philip v1.2.0

This commit is contained in:
coderaiser 2015-07-18 18:29:21 -04:00
parent 4f8c3591f5
commit 98bb57a6d9
15 changed files with 550 additions and 17 deletions

View file

@ -30,6 +30,6 @@
"vk-openapi": "~0.0.1",
"domtokenlist-shim": "~1.1.0",
"promise-polyfill": "~2.1.0",
"philip": "~1.1.2"
"philip": "~1.2.0"
}
}

View file

@ -40,8 +40,8 @@
return result;
});
if (!window.fetch)
array.unshift('/modules/fetch/fetch.js');
if (!window.exec)
array.unshift('/modules/execon/lib/exec.js');
url = CloudCmd.join(array);

View file

@ -0,0 +1,34 @@
{
"name": "execon",
"homepage": "https://github.com/coderaiser/execon",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "Patterns of function calls",
"main": "lib/exec.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"exec"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"version": "1.2.2",
"_release": "1.2.2",
"_resolution": {
"type": "version",
"tag": "v1.2.2",
"commit": "07ebb474438800f66b4b2c5b7abca58a9aa57bf7"
},
"_source": "git://github.com/coderaiser/execon.git",
"_target": "~1.2.2",
"_originalSource": "execon"
}

40
modules/execon/ChangeLog Normal file
View file

@ -0,0 +1,40 @@
2015.06.05, v1.2.2
feature:
- (exec) with: callback.bind -> bind.apply
2015.06.05, v1.2.1
feature:
- (exec) exec.with: arguments[0] -> slice.call(arguments)
2015.06.03, v1.2.0
feature:
- (exec) add each, eachSeries
- (exec) series: rm getType call
2015.01.28, v1.1.1
feature:
- (exec) scope -> global
- (bower) add
- (package) node-execon -> execon
- (package) v1.1.0
- (execon) series: add callback
2015.01.15, v1.1.0
feature:
- (execon) series: add callback
2014.11.24, v1.0.1
fix:
- (package) check -> exec

20
modules/execon/LICENSE Normal file
View file

@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014-2015 coderaiser
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

152
modules/execon/README.md Normal file
View file

@ -0,0 +1,152 @@
# Execon [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL]
Patterns of function calls.
## Install
![NPM_INFO][NPM_INFO_IMG]
```
npm i execon --save
# or
bower i execon --save
```
## Api
```js
var exec = require('execon');
```
### exec
Check is parameter is function, if it's - executes it with given parameters
Was:
```js
function(callback, p1, p2, pN) {
if (typeof callback === 'function')
callback(p1, p2, pN);
}
```
Now
```js
function(callback, p1, p2, pN) {
exec(callback, p1, p2, pN);
}
```
or just
```js
exec.ret(callback, p1, p2, pN);
```
### exec.if
Conditional execution one of two functions
Preconditions:
```js
function one() {
console.log(1);
}
function two(callback) {
setTimeout(callback, 1000);
}
```
Before:
```js
if (2 > 3)
one();
else
two(one);
```
After:
```js
exec.if(2 > 3, one, two);
```
### exec.parallel
if a you need a couple async operation do same work, and then call callback, this function for you.
**Node.js example**.
```js
var fs = require('fs'),
Util = require('execon');
exec.parallel([
function(callback) {
fs.readFile('file1', callback);
},
function(callback) {
fs.readFile('file2', callback);
}
], function(error, data1, data2) {
if (error)
console.log(error)
else
console.log(data1, data2);
});
```
**Vanilla js example.**
```js
var ONE_SECOND = 1000,
TWO_SECONDS = 2000,
func = function(time, str, callback) {
setTimeout(function() {
console.log(str);
callback(null, str);
}, time);
},
func1 = func.bind(null, TWO_SECONDS, 'first'),
func2 = func.bind(null, ONE_SECOND, 'second');
exec.parallel([func1, func2], function(error, str1, str2) {
console.log(str1, str2);
});
```
### exec.series
executes functions one-by-one
```js
function one(callback){
setTimeout(function() {
console.log(1)
callback();
}, 1000);
}
function two(callback) {
console.log(2);
callback();
}
exec.series([one, two], function(error) {
console.log(error || 'done');
});
```
## License
MIT
[NPM_INFO_IMG]: https://nodei.co/npm/execon.png?downloads=true&&stars&&downloadRank "npm install rendy"
[NPMIMGURL]: https://img.shields.io/npm/v/execon.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/execon.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[NPMURL]: https://npmjs.org/package/execon "npm"
[BuildStatusURL]: https://travis-ci.org/coderaiser/execon "Build Status"
[DependencyStatusURL]: https://gemnasium.com/coderaiser/execon "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"

25
modules/execon/bower.json Normal file
View file

@ -0,0 +1,25 @@
{
"name": "execon",
"homepage": "https://github.com/coderaiser/execon",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "Patterns of function calls",
"main": "lib/exec.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"exec"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"version": "1.2.2"
}

233
modules/execon/lib/exec.js Normal file
View file

@ -0,0 +1,233 @@
(function(global) {
'use strict';
if (typeof module === 'object' && module.exports)
module.exports = new ExecProto();
else
global.exec = new ExecProto();
function ExecProto() {
var slice = Array.prototype.slice,
/**
* function do save exec of function
* @param callback
* @param arg1
* ...
* @param argN
*/
exec = function(callback) {
var ret,
isFunc = typeof callback === 'function',
args = slice.call(arguments, 1);
if (isFunc)
ret = callback.apply(null, args);
return ret;
};
/*
* return function that calls callback with arguments
*/
exec.with = function(callback) {
var args = [].slice.call(arguments),
bind = Function.prototype.bind;
args[0] = null;
return bind.apply(callback, args);
};
/**
* return save exec function
* @param callback
*/
exec.ret = function() {
var result,
args = slice.call(arguments);
args.unshift(exec);
result = exec.with.apply(null, args);
return result;
};
/**
* function do conditional save exec of function
* @param condition
* @param callback
* @param func
*/
exec.if = function(condition, callback, func) {
var ret;
if (condition)
exec(callback);
else
exec(func, callback);
return ret;
};
/**
* exec function if it exist in object
*
* @param obj
* @param name
* @param arg
*/
exec.ifExist = function(obj, name, arg) {
var ret,
func = obj && obj[name];
if (func)
func = func.apply(obj, arg);
return ret;
};
exec.parallel = function(funcs, callback) {
var ERROR = 'could not be empty!',
keys = [],
callbackWas = false,
arr = [],
obj = {},
count = 0,
countFuncs = 0,
type = getType(funcs);
if (!funcs)
throw(Error('funcs' + ERROR));
if (!callback)
throw(Error('callback' + ERROR));
switch(type) {
case 'array':
countFuncs = funcs.length;
funcs.forEach(function(func, num) {
exec(func, function() {
checkFunc(num, arguments, arr);
});
});
break;
case 'object':
keys = Object.keys(funcs);
countFuncs = keys.length;
keys.forEach(function(name) {
var func = funcs[name];
exec(func, function() {
checkFunc(name, arguments, obj);
});
});
break;
}
function checkFunc(num, data, all) {
var args = slice.call(data, 1),
isLast = false,
error = data[0],
length = args.length;
++count;
isLast = count === countFuncs;
if (!error)
if (length >= 2)
all[num] = args;
else
all[num] = args[0];
if (!callbackWas && (error || isLast)) {
callbackWas = true;
if (type === 'array')
callback.apply(null, [error].concat(all));
else
callback(error, all);
}
}
};
/**
* load functions thrue callbacks one-by-one
* @param funcs {Array} - array of functions
*/
exec.series = function(funcs, callback) {
var fn,
i = funcs.length,
check = function(error) {
var done;
--i;
if (!i || error) {
done = true;
exec(callback, error);
}
return done;
};
if (!Array.isArray(funcs))
throw(Error('funcs should be array!'));
fn = funcs.shift();
exec(fn, function(error) {
if (!check(error))
exec.series(funcs, callback);
});
};
exec.each = function(array, iterator, callback) {
var listeners = array.map(function(item) {
return iterator.bind(null, item);
});
exec.parallel(listeners, callback);
};
exec.eachSeries = function(array, iterator, callback) {
var listeners = array.map(function(item) {
return iterator.bind(null, item);
});
exec.series(listeners, callback);
};
/**
* function execute param function in
* try...catch block
*
* @param callback
*/
exec.try = function(callback) {
var ret;
try {
ret = callback();
} catch(error) {
ret = error;
}
return ret;
};
function getType(variable) {
var regExp = new RegExp('\\s([a-zA-Z]+)'),
str = {}.toString.call(variable),
typeBig = str.match(regExp)[1],
result = typeBig.toLowerCase();
return result;
}
return exec;
}
})(this);

View file

@ -0,0 +1,17 @@
{
"name": "execon",
"version": "1.2.2",
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
"description": "Patterns of function calls",
"homepage": "http://github.com/coderaiser/execon",
"repository": {
"type": "git",
"url": "git://github.com/coderaiser/execon.git"
},
"dependencies": {},
"license": "MIT",
"engines": {
"node": ">=0.8"
},
"main": "lib/exec.js"
}

View file

@ -1,6 +1,6 @@
{
"name": "philip",
"version": "1.1.2",
"version": "1.2.0",
"homepage": "https://github.com/coderaiser/domfs-philip",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
@ -23,16 +23,17 @@
],
"dependencies": {
"emitify": "~1.2.0",
"findit": "~1.1.0"
"findit": "~1.1.0",
"execon": "~1.2.2"
},
"_release": "1.1.2",
"_release": "1.2.0",
"_resolution": {
"type": "version",
"tag": "v1.1.2",
"commit": "9784fc8c0b935b596d6135743334fa5f86d787e7"
"tag": "v1.2.0",
"commit": "f23a266be8221788974a851c6eed96060dc61f2f"
},
"_source": "git://github.com/coderaiser/domfs-philip.git",
"_target": "~1.1.2",
"_target": "~1.2.0",
"_originalSource": "philip",
"_direct": true
}

View file

@ -1,3 +1,9 @@
2015.07.18, v1.2.0
fix:
- (philip) not all files was processed
2015.07.17, v1.1.2
feature:

View file

@ -10,7 +10,7 @@ bower i philip --save
## How to use?
Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It") and [emitify](https://github.com/coderaiser/emitify "Emitify").
Add `philip.js` [findit](https://github.com/coderaiser/domfs-findit "Find It"), [execon](https://github.com/coderaiser/execon "Patterns of function calls")(or [async](https://github.com/caolan/async "Async utilities for node and the browser" with `window.exec = window.async`) and [emitify](https://github.com/coderaiser/emitify "Emitify").
Or any other node-compitable [EventEmitter](https://iojs.org/api/events.html "Events") (set `window.Emitify = your_emitter` before using `findit`).

View file

@ -1,6 +1,6 @@
{
"name": "philip",
"version": "1.1.2",
"version": "1.2.0",
"homepage": "https://github.com/coderaiser/domfs-philip",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
@ -23,6 +23,7 @@
],
"dependencies": {
"emitify": "~1.2.0",
"findit": "~1.1.0"
"findit": "~1.1.0",
"execon": "~1.2.2"
}
}

View file

@ -1,5 +1,6 @@
/* global Emitify */
/* global findit */
/* global exec */
(function(global) {
'use strict';
@ -132,10 +133,11 @@
};
Philip.prototype._find = function(entries, fn) {
[].forEach.call(entries, function(entry) {
var files = [],
dirs = [],
finder = findit(entry);
var files = [],
dirs = [];
exec.each(entries, function(entry) {
var finder = findit(entry);
finder.on('directory', function(name) {
dirs.push(name);
@ -148,6 +150,8 @@
finder.on('end', function() {
fn(files, dirs);
});
}, function() {
fn(files, dirs);
});
};
})(this);

View file

@ -1,7 +1,7 @@
{
"name": "philip",
"private": true,
"version": "1.1.2",
"version": "1.2.0",
"description": "Process files and directories in DOM File System",
"main": "lib/philip.js",
"dependencies": {},