mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(modules) add currify
This commit is contained in:
parent
51fbd7c620
commit
558096748f
13 changed files with 314 additions and 65 deletions
|
|
@ -41,6 +41,7 @@
|
|||
"jonny": "1.0.1",
|
||||
"promise-polyfill": "6.0.2",
|
||||
"smalltalk": "2.1.3",
|
||||
"jquery": "3.1.1"
|
||||
"jquery": "3.1.1",
|
||||
"currify": "1.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ var CloudCmd;
|
|||
libDir('format', 'format-io'),
|
||||
libDir('rendy'),
|
||||
libDir('emitify', '', 'dist'),
|
||||
libDir('currify', '', 'dist'),
|
||||
libDir('exec', 'execon'),
|
||||
libDir('jonny')
|
||||
].filter(function(name) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
/* global Util */
|
||||
/* global DOM */
|
||||
/* global rendy */
|
||||
/* global currify */
|
||||
/* global spero */
|
||||
/* global remedy */
|
||||
/* global ishtar */
|
||||
|
|
@ -77,72 +78,78 @@
|
|||
});
|
||||
}
|
||||
|
||||
function create(prefix, callback) {
|
||||
exec.series([
|
||||
function(fn) {
|
||||
spero(prefix + '/spero', prefix, function(copier) {
|
||||
fn();
|
||||
|
||||
copier.on('connect', function() {
|
||||
authCheck(copier, function() {
|
||||
copyFn = function(data, callback) {
|
||||
setListeners(copier, callback);
|
||||
copier.copy(data.from, data.to, data.names);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
copier.on('disconnect', function() {
|
||||
copyFn = DOM.RESTful.cp;
|
||||
});
|
||||
});
|
||||
},
|
||||
function _initSpero(prefix, fn) {
|
||||
spero(prefix + '/spero', prefix, function(copier) {
|
||||
fn();
|
||||
|
||||
function(fn) {
|
||||
remedy(prefix + '/remedy', prefix, function(remover) {
|
||||
fn();
|
||||
remover.on('connect', function() {
|
||||
authCheck(remover, function() {
|
||||
deleteFn = function(from, files, callback) {
|
||||
setListeners(remover, callback);
|
||||
from = from.replace(/\?.*/, '');
|
||||
remover.remove(from, files);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
remover.on('disconnect', function() {
|
||||
deleteFn = DOM.RESTful.remove;
|
||||
});
|
||||
copier.on('connect', function() {
|
||||
authCheck(copier, function() {
|
||||
copyFn = function(data, callback) {
|
||||
setListeners(copier, callback);
|
||||
copier.copy(data.from, data.to, data.names);
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
function(fn) {
|
||||
ishtar(prefix + '/ishtar', prefix, function(packer) {
|
||||
fn();
|
||||
packer.on('connect', function() {
|
||||
authCheck(packer, function() {
|
||||
packFn = function(data, callback) {
|
||||
setListeners(packer, {noContinue: true}, callback);
|
||||
packer.pack(data.from, data.to, data.names);
|
||||
};
|
||||
|
||||
extractFn = function(data, callback) {
|
||||
setListeners(packer, {noContinue: true}, callback);
|
||||
packer.extract(data.from, data.to);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
packer.on('disconnect', function() {
|
||||
packFn = RESTful.pack;
|
||||
extractFn = RESTful.extract;
|
||||
});
|
||||
copier.on('disconnect', function() {
|
||||
copyFn = DOM.RESTful.cp;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function _initRemedy(prefix, fn) {
|
||||
remedy(prefix + '/remedy', prefix, function(remover) {
|
||||
fn();
|
||||
remover.on('connect', function() {
|
||||
authCheck(remover, function() {
|
||||
deleteFn = function(from, files, callback) {
|
||||
setListeners(remover, callback);
|
||||
from = from.replace(/\?.*/, '');
|
||||
remover.remove(from, files);
|
||||
};
|
||||
});
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
remover.on('disconnect', function() {
|
||||
deleteFn = DOM.RESTful.remove;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function _initIshtar(prefix, fn) {
|
||||
ishtar(prefix + '/ishtar', prefix, function(packer) {
|
||||
fn();
|
||||
packer.on('connect', function() {
|
||||
authCheck(packer, function() {
|
||||
packFn = function(data, callback) {
|
||||
setListeners(packer, {noContinue: true}, callback);
|
||||
packer.pack(data.from, data.to, data.names);
|
||||
};
|
||||
|
||||
extractFn = function(data, callback) {
|
||||
setListeners(packer, {noContinue: true}, callback);
|
||||
packer.extract(data.from, data.to);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
packer.on('disconnect', function() {
|
||||
packFn = RESTful.pack;
|
||||
extractFn = RESTful.extract;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function create(prefix) {
|
||||
var initSpero = currify(_initSpero);
|
||||
var initRemedy = currify(_initRemedy);
|
||||
var initIshtar = currify(_initIshtar);
|
||||
|
||||
Util.exec(callback);
|
||||
exec.parallel([
|
||||
initSpero(prefix),
|
||||
initRemedy(prefix),
|
||||
initIshtar(prefix),
|
||||
], exec.ret);
|
||||
}
|
||||
|
||||
function setListeners(emitter, options, callback) {
|
||||
|
|
|
|||
36
modules/currify/.bower.json
Normal file
36
modules/currify/.bower.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "currify",
|
||||
"version": "1.0.0",
|
||||
"description": "translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments",
|
||||
"homepage": "https://github.com/coderaiser/currify",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"main": "lib/currify.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"curry",
|
||||
"functional"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
],
|
||||
"_release": "1.0.0",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v1.0.0",
|
||||
"commit": "aeb6b45ce3b87d9982680945e829fab92c80b767"
|
||||
},
|
||||
"_source": "https://github.com/coderaiser/currify.git",
|
||||
"_target": "^1.0.0",
|
||||
"_originalSource": "currify",
|
||||
"_direct": true
|
||||
}
|
||||
36
modules/currify/README.md
Normal file
36
modules/currify/README.md
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# Currify [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL]
|
||||
|
||||
Translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
npm i currify --save
|
||||
```
|
||||
|
||||
## How to use?
|
||||
|
||||
```js
|
||||
let currify = require('currify');
|
||||
|
||||
let mean = (a, b, c) => (a + b) / c;
|
||||
let mean1 = currify(mean, 1);
|
||||
let mean2 = mean1(2);
|
||||
let result = mean2(2);
|
||||
|
||||
// returns
|
||||
1.5
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
[NPMIMGURL]: https://img.shields.io/npm/v/currify.svg?style=flat
|
||||
[BuildStatusIMGURL]: https://img.shields.io/travis/coderaiser/currify/master.svg?style=flat
|
||||
[DependencyStatusIMGURL]: https://img.shields.io/gemnasium/coderaiser/currify.svg?style=flat
|
||||
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
|
||||
[NPMURL]: https://npmjs.org/package/currify "npm"
|
||||
[BuildStatusURL]: https://travis-ci.org/coderaiser/currify "Build Status"
|
||||
[DependencyStatusURL]: https://gemnasium.com/coderaiser/currify "Dependency Status"
|
||||
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
|
||||
26
modules/currify/bower.json
Normal file
26
modules/currify/bower.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"name": "currify",
|
||||
"version": "1.0.0",
|
||||
"description": "translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments",
|
||||
"homepage": "https://github.com/coderaiser/currify",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
],
|
||||
"main": "lib/currify.js",
|
||||
"moduleType": [
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"curry",
|
||||
"functional"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
27
modules/currify/dist/currify.es6.js
vendored
Normal file
27
modules/currify/dist/currify.es6.js
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.currify = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"currify":[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
module.exports = currify;
|
||||
|
||||
let tail = list => [].slice.call(list, 1);
|
||||
|
||||
function currify(fn) {
|
||||
check(fn);
|
||||
|
||||
let args = tail(arguments);
|
||||
|
||||
if (args.length >= fn.length)
|
||||
return fn(...args);
|
||||
else
|
||||
return function() {
|
||||
return currify(...[fn, ...args, ...arguments]);
|
||||
};
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
if (typeof fn !== 'function')
|
||||
throw Error('fn should be function!');
|
||||
}
|
||||
|
||||
},{}]},{},["currify"])("currify")
|
||||
});
|
||||
26
modules/currify/dist/currify.js
vendored
Normal file
26
modules/currify/dist/currify.js
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.currify = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"currify":[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
||||
|
||||
module.exports = currify;
|
||||
|
||||
var tail = function tail(list) {
|
||||
return [].slice.call(list, 1);
|
||||
};
|
||||
|
||||
function currify(fn) {
|
||||
check(fn);
|
||||
|
||||
var args = tail(arguments);
|
||||
|
||||
if (args.length >= fn.length) return fn.apply(undefined, _toConsumableArray(args));else return function () {
|
||||
return currify.apply(undefined, [fn].concat(_toConsumableArray(args), Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
if (typeof fn !== 'function') throw Error('fn should be function!');
|
||||
}
|
||||
},{}]},{},["currify"])("currify")
|
||||
});
|
||||
1
modules/currify/dist/currify.min.js
vendored
Normal file
1
modules/currify/dist/currify.min.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
!function(r){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=r();else if("function"==typeof define&&define.amd)define([],r);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.currify=r()}}(function(){return function r(e,n,t){function o(i,u){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!u&&c)return c(i,!0);if(f)return f(i,!0);var l=new Error("Cannot find module '"+i+"'");throw l.code="MODULE_NOT_FOUND",l}var a=n[i]={exports:{}};e[i][0].call(a.exports,function(r){var n=e[i][1][r];return o(n?n:r)},a,a.exports,r,e,n,t)}return n[i].exports}for(var f="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({currify:[function(r,e){"use strict";function n(r){if(Array.isArray(r)){for(var e=0,n=Array(r.length);e<r.length;e++)n[e]=r[e];return n}return Array.from(r)}function t(r){o(r);var e=f(arguments);return e.length>=r.length?r.apply(void 0,n(e)):function(){return t.apply(void 0,[r].concat(n(e),Array.prototype.slice.call(arguments)))}}function o(r){if("function"!=typeof r)throw Error("fn should be function!")}e.exports=t;var f=function(r){return[].slice.call(r,1)}},{}]},{},["currify"])("currify")});
|
||||
23
modules/currify/lib/currify.js
Normal file
23
modules/currify/lib/currify.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
||||
|
||||
module.exports = currify;
|
||||
|
||||
var tail = function tail(list) {
|
||||
return [].slice.call(list, 1);
|
||||
};
|
||||
|
||||
function currify(fn) {
|
||||
check(fn);
|
||||
|
||||
var args = tail(arguments);
|
||||
|
||||
if (args.length >= fn.length) return fn.apply(undefined, _toConsumableArray(args));else return function () {
|
||||
return currify.apply(undefined, [fn].concat(_toConsumableArray(args), Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
if (typeof fn !== 'function') throw Error('fn should be function!');
|
||||
}
|
||||
43
modules/currify/package.json
Normal file
43
modules/currify/package.json
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "currify",
|
||||
"version": "1.0.0",
|
||||
"description": "translate the evaluation of a function that takes multiple arguments into evaluating a sequence of functions, each with a single or more arguments",
|
||||
"main": "lib/currify.js",
|
||||
"scripts": {
|
||||
"test": "tape test/*.js",
|
||||
"build": "npm-run-all clean 6to5 bundle bundle:es6 minify",
|
||||
"minify": "minify dist/currify.js > dist/currify.min.js",
|
||||
"6to5": "babel -d lib src",
|
||||
"wisdom": "npm run build",
|
||||
"jscs-fix": "jscs --esnext test src --fix",
|
||||
"clean": "rimraf lib/* dist/*",
|
||||
"bundle:base": "browserify -s currify --ng false",
|
||||
"bundle": "npm run bundle:base -- -r ./lib/currify.js:currify ./lib/currify.js -o dist/currify.js",
|
||||
"bundle:es6:base": "npm run bundle:base -- -r ./src/currify.js:currify ./src/currify.js",
|
||||
"bundle:es6": "npm run bundle:es6:base -- -o dist/currify.es6.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/coderaiser/currify.git"
|
||||
},
|
||||
"keywords": [
|
||||
"currify",
|
||||
"partial",
|
||||
"functional"
|
||||
],
|
||||
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/coderaiser/currify/issues"
|
||||
},
|
||||
"homepage": "https://github.com/coderaiser/currify",
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.1.1",
|
||||
"babel-preset-es2015": "^6.0.15",
|
||||
"browserify": "^12.0.1",
|
||||
"jscs": "^2.4.0",
|
||||
"npm-run-all": "^1.2.12",
|
||||
"rimraf": "^2.4.3",
|
||||
"tape": "^4.2.0"
|
||||
}
|
||||
}
|
||||
23
modules/currify/src/currify.js
Normal file
23
modules/currify/src/currify.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = currify;
|
||||
|
||||
let tail = list => [].slice.call(list, 1);
|
||||
|
||||
function currify(fn) {
|
||||
check(fn);
|
||||
|
||||
let args = tail(arguments);
|
||||
|
||||
if (args.length >= fn.length)
|
||||
return fn(...args);
|
||||
else
|
||||
return function() {
|
||||
return currify(...[fn, ...args, ...arguments]);
|
||||
};
|
||||
}
|
||||
|
||||
function check(fn) {
|
||||
if (typeof fn !== 'function')
|
||||
throw Error('fn should be function!');
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
"commit": "1b30f3ad466ebf2714d47eda34dbd7fdf6849fe3"
|
||||
},
|
||||
"_source": "https://github.com/jquery/jquery-dist.git",
|
||||
"_target": "^3.1.1",
|
||||
"_originalSource": "jquery",
|
||||
"_direct": true
|
||||
"_target": "3.1.1",
|
||||
"_originalSource": "jquery"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue