diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..a0074fd --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -0,0 +1,30 @@ +name: build + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x, 10.x, 12.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install, build, and test + run: | + npm install + npm ci + npm run build --if-present + npm test + npm run coverage + npm run coveralls + env: + CI: true + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index af258a7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - '0.10' -after_script: - - npm run coveralls diff --git a/README.md b/README.md index fbd3eb2..360be94 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Teep -[![Build Status](https://travis-ci.org/earldouglas/teep.svg?branch=master)](https://travis-ci.org/earldouglas/teep) -[![Coverage Status](https://coveralls.io/repos/earldouglas/teep/badge.svg?branch=master&service=github)](https://coveralls.io/github/earldouglas/teep?branch=master) +![Build Status](https://github.com/earldouglas/teep/workflows/build/badge.svg) +[![Coverage Status](https://coveralls.io/repos/earldouglas/teep/badge.svg)](https://coveralls.io/github/earldouglas/teep) Teep is a JavaScript library for functional programming. It works both as a [Node.js module](https://www.npmjs.org/package/teep), and directly diff --git a/package.json b/package.json index 33c36cb..9d11c8c 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,23 @@ }, "scripts": { "build": "tsc src/teep.ts --outDir .", - "test": "npm run-script build && istanbul cover _mocha -- -R spec", - "coveralls": "npm run-script test && cat ./coverage/lcov.info | coveralls" + "test": "jshint . --exclude node_modules && mocha", + "coverage": "istanbul cover _mocha -- -R spec", + "coveralls": "cat ./coverage/lcov.info | coveralls" + }, + "jshintConfig": { + "node": true, + "globals": { + "Promise": false, + "describe": false, + "it": false + } }, "devDependencies": { "bluebird": "2.2.2", "coveralls": "2.11.2", "istanbul": "0.3.5", + "jshint": "2.9.4", "mocha": "2.2.5", "mocha-lcov-reporter": "0.0.1", "typescript": "2.9" diff --git a/src/teep.ts b/src/teep.ts index 5b62ca9..2fb5200 100644 --- a/src/teep.ts +++ b/src/teep.ts @@ -51,7 +51,9 @@ module edc { keys: (o: Object): Array => { var ks = []; for (var k in o) { - !o.hasOwnProperty(k) || ks.push(k); + if (o.hasOwnProperty(k)) { + ks.push(k); + } } return ks; }, @@ -336,17 +338,17 @@ module edc { } apply(a: A): B { return this.f(a); - }; + } map(g: (B) => C): Reader { return new Reader((a) => { return g(this.f(a)); }); - }; + } flatMap(g: (B) => Reader): Reader { return new Reader((a) => { return g(this.f(a)).apply(a); }); - }; + } } var reader = (f: (A) => B) => { return new Reader(f); } @@ -362,21 +364,21 @@ module edc { } apply(k: (A) => any): void { this.f(k); - }; + } map(g: (A) => B): Future { return new Future((k: (B) => any) => { return this.f((a: A) => { k(g(a)); }); }); - }; + } flatMap(g: (A) => Future): Future { return new Future((k: (B) => any) => { return this.f((a: A) => { g(a).apply(k); }); }); - }; + } sequence(f2: Future): Future<(A) => B> { var a: A; var b: B; @@ -395,7 +397,7 @@ module edc { kk(); }); }); - }; + } } var future = (f: (A) => any) => { return new Future(f); } @@ -407,17 +409,17 @@ module edc { } apply(a: A): Monad { return this.f(a); - }; + } map(g: (B) => C): ReaderT { return new ReaderT((a) => { return this.f(a).map(g); }); - }; + } flatMap(g: (B) => ReaderT): ReaderT { return new ReaderT((a) => { return this.f(a).map(g).flatMap((r) => { return r.apply(a); }); }); - }; + } } var readerT = (f: (A) => Monad) => { return new ReaderT(f); } @@ -440,20 +442,20 @@ module edc { } apply(s: S): StateTuple { return this.f(s); - }; + } map(g: (A) => B): State { return state((s: S) => { var sa: StateTuple = this.f(s); return new StateTuple(sa.state, g(sa.value)); }); - }; + } flatMap(g: (A) => State): State { return state((s: S) => { var sa: StateTuple = this.f(s); var sb: State = g(sa.value); return sb.apply(sa.state); }); - }; + } } export var teep = { @@ -478,6 +480,8 @@ module edc { }); }; - !exports || setExports(); + if (exports) { + setExports(); + } } diff --git a/teep.js b/teep.js index 0bddd5d..0ed717c 100644 --- a/teep.js +++ b/teep.js @@ -48,7 +48,9 @@ var edc; keys: function (o) { var ks = []; for (var k in o) { - !o.hasOwnProperty(k) || ks.push(k); + if (o.hasOwnProperty(k)) { + ks.push(k); + } } return ks; } @@ -287,21 +289,18 @@ var edc; Reader.prototype.apply = function (a) { return this.f(a); }; - ; Reader.prototype.map = function (g) { var _this = this; return new Reader(function (a) { return g(_this.f(a)); }); }; - ; Reader.prototype.flatMap = function (g) { var _this = this; return new Reader(function (a) { return g(_this.f(a)).apply(a); }); }; - ; return Reader; }()); var reader = function (f) { return new Reader(f); }; @@ -315,7 +314,6 @@ var edc; Future.prototype.apply = function (k) { this.f(k); }; - ; Future.prototype.map = function (g) { var _this = this; return new Future(function (k) { @@ -324,7 +322,6 @@ var edc; }); }); }; - ; Future.prototype.flatMap = function (g) { var _this = this; return new Future(function (k) { @@ -333,7 +330,6 @@ var edc; }); }); }; - ; Future.prototype.sequence = function (f2) { var _this = this; var a; @@ -354,7 +350,6 @@ var edc; }); }); }; - ; return Future; }()); var future = function (f) { return new Future(f); }; @@ -365,21 +360,18 @@ var edc; ReaderT.prototype.apply = function (a) { return this.f(a); }; - ; ReaderT.prototype.map = function (g) { var _this = this; return new ReaderT(function (a) { return _this.f(a).map(g); }); }; - ; ReaderT.prototype.flatMap = function (g) { var _this = this; return new ReaderT(function (a) { return _this.f(a).map(g).flatMap(function (r) { return r.apply(a); }); }); }; - ; return ReaderT; }()); var readerT = function (f) { return new ReaderT(f); }; @@ -398,7 +390,6 @@ var edc; State.prototype.apply = function (s) { return this.f(s); }; - ; State.prototype.map = function (g) { var _this = this; return state(function (s) { @@ -406,7 +397,6 @@ var edc; return new StateTuple(sa.state, g(sa.value)); }); }; - ; State.prototype.flatMap = function (g) { var _this = this; return state(function (s) { @@ -415,7 +405,6 @@ var edc; return sb.apply(sa.state); }); }; - ; return State; }()); edc.teep = { @@ -438,5 +427,7 @@ var edc; exports[k] = edc.teep[k]; }); }; - !exports || setExports(); + if (exports) { + setExports(); + } })(edc || (edc = {})); diff --git a/test/examples.js b/test/examples.js index 730ccf1..1ddcce6 100644 --- a/test/examples.js +++ b/test/examples.js @@ -2,7 +2,7 @@ if (!global.Promise) { global.Promise = require('bluebird'); } -var assert = require("assert") +var assert = require("assert"); var teep = require('../teep.js'); describe('examples', function () { @@ -496,7 +496,7 @@ describe('examples', function () { return k(db.answer + x); }); }); - }; + } function verify(x, done) { return function (y) { @@ -504,7 +504,7 @@ describe('examples', function () { done(); } }; - }; + } it('apply', function (done) { teep.readerT(getAnswer).apply(db).apply(verify(42, done));