Skip to content

Commit

Permalink
Add browser version
Browse files Browse the repository at this point in the history
  • Loading branch information
rsp committed Oct 27, 2015
1 parent f0cabec commit a191d90
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function tco(f) {

if (typeof f == 'function') {
var tf = function () {
var nf = f, na = arguments, next = true;
var nf = f, na = arguments;
while (1) {
var r = nf.apply(null, na);
if (typeof r[0] == 'function') {
Expand Down
6 changes: 6 additions & 0 deletions minify
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
read -d '' c << 'C'
/* tco.js by Rafał Pocztarski - https://github.com/rsp/node-tco */
C
echo "$c" > tco.min.js
node_modules/uglify-js/bin/uglifyjs tco.js -c -m >> tco.min.js
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
"bugs": {
"url": "https://github.com/rsp/node-tco/issues"
},
"homepage": "https://github.com/rsp/node-tco#readme"
"homepage": "https://github.com/rsp/node-tco#readme",
"devDependencies": {
"uglify-js": "^2.5.0"
}
}
42 changes: 42 additions & 0 deletions tco.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
tco.js
Copyright (c) 2015 Rafał Pocztarski
Released under MIT license
https://github.com/rsp/node-tco
*/

window.tco = (function (tco) {

"use strict";

function tco(f) {

if (typeof f == 'function') {
var tf = function () {
var nf = f, na = arguments;
while (1) {
var r = nf.apply(null, na);
if (typeof r[0] == 'function') {
if (typeof r[0].tco == 'function') {
nf = r[0].tco;
na = r[1];
} else {
return r[0].apply(null, r[1]);
}
} else if (r[0] == null) {
return r[1];
} else {
throw new Error('tco: bad value returned');
}
}
};
tf.tco = f;
return tf;
} else {
throw new Error('tco() expects a function');
}
}

return tco;

}(tco));
2 changes: 2 additions & 0 deletions tco.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a191d90

Please sign in to comment.