From 558096748f454fbedff3fe480aa411ce70c4c2fb Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 14 Nov 2016 15:28:48 +0200 Subject: [PATCH] feature(modules) add currify --- bower.json | 3 +- lib/client/cloudcmd.js | 1 + lib/client/operation.js | 129 +++++++++++++++------------- modules/currify/.bower.json | 36 ++++++++ modules/currify/README.md | 36 ++++++++ modules/currify/bower.json | 26 ++++++ modules/currify/dist/currify.es6.js | 27 ++++++ modules/currify/dist/currify.js | 26 ++++++ modules/currify/dist/currify.min.js | 1 + modules/currify/lib/currify.js | 23 +++++ modules/currify/package.json | 43 ++++++++++ modules/currify/src/currify.js | 23 +++++ modules/jquery/.bower.json | 5 +- 13 files changed, 314 insertions(+), 65 deletions(-) create mode 100644 modules/currify/.bower.json create mode 100644 modules/currify/README.md create mode 100644 modules/currify/bower.json create mode 100644 modules/currify/dist/currify.es6.js create mode 100644 modules/currify/dist/currify.js create mode 100644 modules/currify/dist/currify.min.js create mode 100644 modules/currify/lib/currify.js create mode 100644 modules/currify/package.json create mode 100644 modules/currify/src/currify.js diff --git a/bower.json b/bower.json index 89252fc6..088705bd 100644 --- a/bower.json +++ b/bower.json @@ -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" } } diff --git a/lib/client/cloudcmd.js b/lib/client/cloudcmd.js index 6a756865..acc26905 100644 --- a/lib/client/cloudcmd.js +++ b/lib/client/cloudcmd.js @@ -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) { diff --git a/lib/client/operation.js b/lib/client/operation.js index a329e530..6d352f05 100644 --- a/lib/client/operation.js +++ b/lib/client/operation.js @@ -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) { diff --git a/modules/currify/.bower.json b/modules/currify/.bower.json new file mode 100644 index 00000000..79095938 --- /dev/null +++ b/modules/currify/.bower.json @@ -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 " + ], + "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 +} \ No newline at end of file diff --git a/modules/currify/README.md b/modules/currify/README.md new file mode 100644 index 00000000..d32ad9ab --- /dev/null +++ b/modules/currify/README.md @@ -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" diff --git a/modules/currify/bower.json b/modules/currify/bower.json new file mode 100644 index 00000000..d8df4e69 --- /dev/null +++ b/modules/currify/bower.json @@ -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 " + ], + "main": "lib/currify.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "curry", + "functional" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/modules/currify/dist/currify.es6.js b/modules/currify/dist/currify.es6.js new file mode 100644 index 00000000..d31684d4 --- /dev/null +++ b/modules/currify/dist/currify.es6.js @@ -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 [].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") +}); \ No newline at end of file diff --git a/modules/currify/dist/currify.js b/modules/currify/dist/currify.js new file mode 100644 index 00000000..e60b9d3b --- /dev/null +++ b/modules/currify/dist/currify.js @@ -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= 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") +}); \ No newline at end of file diff --git a/modules/currify/dist/currify.min.js b/modules/currify/dist/currify.min.js new file mode 100644 index 00000000..d89c5833 --- /dev/null +++ b/modules/currify/dist/currify.min.js @@ -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=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")}); diff --git a/modules/currify/lib/currify.js b/modules/currify/lib/currify.js new file mode 100644 index 00000000..3ad83df5 --- /dev/null +++ b/modules/currify/lib/currify.js @@ -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!'); +} \ No newline at end of file diff --git a/modules/currify/package.json b/modules/currify/package.json new file mode 100644 index 00000000..a5ec5c10 --- /dev/null +++ b/modules/currify/package.json @@ -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 (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" + } +} diff --git a/modules/currify/src/currify.js b/modules/currify/src/currify.js new file mode 100644 index 00000000..b5264aca --- /dev/null +++ b/modules/currify/src/currify.js @@ -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!'); +} diff --git a/modules/jquery/.bower.json b/modules/jquery/.bower.json index ea3f2aae..be54fe3a 100644 --- a/modules/jquery/.bower.json +++ b/modules/jquery/.bower.json @@ -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" } \ No newline at end of file