Skip to content

Commit

Permalink
Changed API to allow for multiple instances
Browse files Browse the repository at this point in the history
  • Loading branch information
bchr02 committed Aug 18, 2015
1 parent 0cc718d commit 9c15185
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 27 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# epochjs version 1.0.3
# epochjs version 2.0.0
Track the elapsed time since a certain point, like the start of a node script.

[![NPM](https://nodei.co/npm/epochjs.png?downloads=true&stars=true)](https://nodei.co/npm/epochjs/)
Expand All @@ -9,20 +9,21 @@ Run `npm install epochjs` to install from the NPM registry.

## Examples:
````javascript
var epoch = require('epochjs');
var Epochjs = require('epochjs'),
epochjs = new Epochjs();

// Call start() to set (or reset) the start time.
// start() is called at the start of the script by default.
epoch.start();
epochjs.start();

// ...add your javascript code here

// when ready to see the amount of time that has ellapsed call secElapsed()
console.log(epoch.secElapsed() + ' time has ellapsed');
console.log(epochjs.secElapsed() + ' time has ellapsed');

// or even simpler call log()
// the following will output to the console "5.11 database updated" where
// 5.11 is the amount of time that has ellapsed since start().
epoch.log('database updated');
epochjs.log('database updated');

````
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

function Epochjs() {
this.seconds; // the number of seconds between midnight of January 1, 1970 and this.start().
this.start();
}

Expand All @@ -21,8 +20,10 @@ Epochjs.prototype = {
return r;
},
log: function(msg) {
console.log(secElapsed() + ' ' + msg);
msg = this.secElapsed() + ' ' + msg;
console.log(msg);
return msg;
}
}
};

module.exports = Epochjs;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "epochjs",
"version": "1.0.3",
"version": "2.0.0",
"description": "Track the elapsed time since a certain point, like the start of a node script.",
"main": "index.js",
"scripts": {
Expand Down
27 changes: 9 additions & 18 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@ describe("Epochjs", function() {
epochjs.secElapsed().should.be.within(0,10);
});
});
describe(".log()", function() {
it("should log a message to the console", function() {
var oldconsole = console,
console = {
log: function(s) {
if (s == message) {
return true;
}
}},
message = 'test',
result = false,
epochjs = new Epochjs(),
check;
epochjs.start();
check = epochjs.log(message);
console = oldconsole;
should.exist(check);
check.should.be.true();
describe(".log('test')", function() {
it("should return a message", function() {
var epochjs = new Epochjs(),
msg = 'test',
result = epochjs.log(msg),
pass = (result.indexOf(msg) > -1) ? true : false;

should.exist(pass);
pass.should.equal(true);
});
});
});

0 comments on commit 9c15185

Please sign in to comment.