diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..af73450 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1 @@ +repo_token: GQiHTVmmp97RofjFzkjPWhnfYnkny2Gnh \ No newline at end of file diff --git a/.gitignore b/.gitignore index c85866a..7cafbdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -coverage/coverage.html +coverage node_modules \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b7151eb --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: +- '0.10' +script: +- 'npm run coveralls' +notifications: + email: + on_success: never + on_failure: always \ No newline at end of file diff --git a/GedcomXDate.js b/GedcomXDate.js index 88470ec..ff404b7 100644 --- a/GedcomXDate.js +++ b/GedcomXDate.js @@ -1,4 +1,4 @@ -(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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { - var fn = queue.shift(); - fn(); - } - } - }, true); - - return function nextTick(fn) { - queue.push(fn); - window.postMessage('process-tick', '*'); - }; + draining = true; + var currentQueue; + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + var i = -1; + while (++i < len) { + currentQueue[i](); + } + len = queue.length; } - - return function nextTick(fn) { - setTimeout(fn, 0); - }; -})(); + draining = false; +} +process.nextTick = function (fun) { + queue.push(fun); + if (!draining) { + setTimeout(drainQueue, 0); + } +}; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; function noop() {} @@ -1547,13 +1541,14 @@ process.emit = noop; process.binding = function (name) { throw new Error('process.binding is not supported'); -} +}; // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; +process.umask = function() { return 0; }; },{}],11:[function(require,module,exports){ module.exports = function isBuffer(arg) { @@ -2151,5 +2146,6 @@ function hasOwnProperty(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } -}).call(this,require("FWaASH"),typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) -},{"./support/isBuffer":11,"FWaASH":10,"inherits":9}]},{},[3]) \ No newline at end of file +}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./support/isBuffer":11,"_process":10,"inherits":9}]},{},[3])(3) +}); \ No newline at end of file diff --git a/README.md b/README.md index 666e58f..0f6e9fa 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,15 @@ +[![Build Status](https://travis-ci.org/genealogysystems/gedcomx-date-js.svg?branch=build)](https://travis-ci.org/genealogysystems/gedcomx-date-js) +[![Coverage Status](https://coveralls.io/repos/genealogysystems/gedcomx-date-js/badge.svg)](https://coveralls.io/r/genealogysystems/gedcomx-date-js) +[![Dependency Status](https://david-dm.org/genealogysystems/gedcomx-date-js.svg)](https://david-dm.org/genealogysystems/gedcomx-date-js) +[![devDependency Status](https://david-dm.org/genealogysystems/gedcomx-date-js/dev-status.svg)](https://david-dm.org/genealogysystems/gedcomx-date-js#info=devDependencies) + # GedcomX-Date + A GEDCOM-X Date Library for Javascript, fully compliant with the [spec](https://github.com/FamilySearch/gedcomx/blob/master/specifications/date-format-specification.md). # Usage -````javascript + +```js var GedcomXDate = require('gedcomx-date'); var single = new GedcomXDate('+1900-01-01'); @@ -38,41 +45,43 @@ var halfDuration = GedcomXDate.multiplyDuration(newDuration, .5); console.log(newDuration.toFormalString()); // P57Y1M -```` +``` ## Node.js + You can install GedcomX-Date by cloning this repository or by using npm. -````bash +```bash npm install gedcomx-date -```` +``` ## Browser + Download [GedcomXDate.js](GedcomXDate.js) and enjoy. (Packaged with love by [browserify](http://browserify.org/)) # Tests There is a very comprehensive test suite. -````bash -# To run the tests cd to the repo directory and run -mocha - -# To generate the code coverage run -./coverage/generate.sh -```` -Install [mocha](http://visionmedia.github.io/mocha/) and [jscoverage](https://github.com/visionmedia/node-jscoverage) globally before runnings tests and generating coverage. +```bash +# Run tests +npm test +# Generate code coverage +npm run coverage +``` # Reference + When you create a new GedcomXDate you pass in a formal date string into the contructor. It will parse and validate the string, and return an object representation of it. If there is a parsing error GedcomXDate with throw an error. ## Single -````javascript + +```js var date = new GedcomXDate('A+2000-01-01'); // date will be a Single Date -```` +``` ### getType() Returns the `string` 'single'. @@ -110,13 +119,13 @@ Returns the formal GedcomX representation as a `string`. ## Range A range has three components, start, end, and duration -````javascript +```js var date = GedcomXDate('A+1000-01-01/+2000-12-31'); // date.start will be a simple date // date.end will be a simple date // date.duration will be a duration -```` +``` ### getType() Returns the `string` 'range'. @@ -139,9 +148,9 @@ Returns the formal GedcomX representation as a `string`. ## Recurring A Recurring date is the same as a Range with a few more methods. -````javascript +```js var date = GedcomXDate('R2/+1000-01-01/+2000-12-31'); -```` +``` ### getType() Returns the `string` 'recurring'. @@ -164,11 +173,11 @@ Returns the formal GedcomX representation as a `string`. ## Duration Represents a duration of time. -````javascript +```js var date = GedcomXDate('A+1000-01-01/P100Y'); var duration = date.getDuration(); -```` +``` ### getType() Returns the `string` 'duration'. diff --git a/coverage/generate.sh b/coverage/generate.sh deleted file mode 100755 index 55315d4..0000000 --- a/coverage/generate.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Make sure to install jscoverage -# https://github.com/visionmedia/node-jscoverage - -jscoverage lib lib-cov -TEST_COV=1 mocha -R html-cov > coverage/coverage.html -rm -rf lib-cov - -echo "open ./coverage/coverage.html in your browser to view the coverage report" \ No newline at end of file diff --git a/package.json b/package.json index 08f92e1..5def129 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,16 @@ "main": "lib/gedcomx-date.js", "scripts": { "test": "mocha", - "build": "./node_modules/browserify/bin/cmd.js lib/gedcomx-date.js -s GedcomXDate -o GedcomXDate.js" + "build": "browserify lib/gedcomx-date.js -s GedcomXDate -o GedcomXDate.js", + "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha", + "coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" }, "dependencies": {}, "devDependencies": { - "chai": "~1.9.1", - "browserify": "~3.46.0" + "browserify": "9.0.8", + "chai": "2.2.0", + "coveralls": "2.11.2", + "istanbul": "0.3.13", + "mocha": "2.2.4" } } diff --git a/test/approximate.js b/test/approximate.js index 5647d0f..1b6952c 100644 --- a/test/approximate.js +++ b/test/approximate.js @@ -1,7 +1,6 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Approximate = require(path.join(libPath, 'approximate.js')); + Approximate = require(path.join('../lib', 'approximate.js')); describe('Approximate', function(){ diff --git a/test/duration.js b/test/duration.js index 8a7cf15..00d87dd 100644 --- a/test/duration.js +++ b/test/duration.js @@ -1,7 +1,6 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Duration = require(path.join(libPath, 'duration.js')); + Duration = require(path.join('../lib', 'duration.js')); describe('Duration', function(){ diff --git a/test/gedcomx-date.js b/test/gedcomx-date.js index 57722e3..8abcefe 100644 --- a/test/gedcomx-date.js +++ b/test/gedcomx-date.js @@ -1,13 +1,12 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), fs = require('fs'), expect = require('chai').expect, - Simple = require(path.join(libPath, 'simple.js')), - Approximate = require(path.join(libPath, 'approximate.js')), - Recurring = require(path.join(libPath, 'recurring.js')), - Duration = require(path.join(libPath, 'duration.js')), - Range = require(path.join(libPath, 'range.js')), - GedcomXDate = require(path.join(libPath, 'gedcomx-date.js')); + Simple = require(path.join('../lib', 'simple.js')), + Approximate = require(path.join('../lib', 'approximate.js')), + Recurring = require(path.join('../lib', 'recurring.js')), + Duration = require(path.join('../lib', 'duration.js')), + Range = require(path.join('../lib', 'range.js')), + GedcomXDate = require(path.join('../lib', 'gedcomx-date.js')); describe('GedcomXDate', function(){ diff --git a/test/mocha.opts b/test/mocha.opts deleted file mode 100644 index fb5f824..0000000 --- a/test/mocha.opts +++ /dev/null @@ -1 +0,0 @@ ---reporter spec \ No newline at end of file diff --git a/test/range.js b/test/range.js index 99e0805..8d380ba 100644 --- a/test/range.js +++ b/test/range.js @@ -1,10 +1,8 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Simple = require(path.join(libPath, 'simple.js')), - Approximate = require(path.join(libPath, 'approximate.js')), - Duration = require(path.join(libPath, 'duration.js')), - Range = require(path.join(libPath, 'range.js')); + Simple = require(path.join('../lib', 'simple.js')), + Duration = require(path.join('../lib', 'duration.js')), + Range = require(path.join('../lib', 'range.js')); describe('Range', function(){ diff --git a/test/recurring.js b/test/recurring.js index 4eddcbf..a1d5d81 100644 --- a/test/recurring.js +++ b/test/recurring.js @@ -1,9 +1,6 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Simple = require(path.join(libPath, 'simple.js')), - Approximate = require(path.join(libPath, 'approximate.js')), - Recurring = require(path.join(libPath, 'recurring.js')); + Recurring = require(path.join('../lib', 'recurring.js')); describe('Recurring', function(){ describe("#(start, end)", function(){ diff --git a/test/simple.js b/test/simple.js index cb58323..59480c8 100644 --- a/test/simple.js +++ b/test/simple.js @@ -1,7 +1,6 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Simple = require(path.join(libPath, 'simple.js')); + Simple = require(path.join('../lib', 'simple.js')); describe('Simple', function(){ diff --git a/test/util-global.js b/test/util-global.js index 86b3716..e38124e 100644 --- a/test/util-global.js +++ b/test/util-global.js @@ -1,7 +1,6 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), +var path = require('path'), expect = require('chai').expect, - Util = require(path.join(libPath, 'util-global.js')); + Util = require(path.join('../lib', 'util-global.js')); describe('Util-Global', function(){ diff --git a/test/util.js b/test/util.js index 0b8b0ea..80a8d39 100644 --- a/test/util.js +++ b/test/util.js @@ -1,13 +1,9 @@ -var libPath = process.env.TEST_COV ? '../lib-cov' : '../lib', - path = require('path'), - fs = require('fs'), +var path = require('path'), expect = require('chai').expect, - Simple = require(path.join(libPath, 'simple.js')), - Approximate = require(path.join(libPath, 'approximate.js')), - Recurring = require(path.join(libPath, 'recurring.js')), - Duration = require(path.join(libPath, 'duration.js')), - Range = require(path.join(libPath, 'range.js')), - GedcomXDate = require(path.join(libPath, 'gedcomx-date.js')); + Simple = require(path.join('../lib', 'simple.js')), + Approximate = require(path.join('../lib', 'approximate.js')), + Duration = require(path.join('../lib', 'duration.js')), + GedcomXDate = require(path.join('../lib', 'gedcomx-date.js')); describe('Util', function(){