From 9c15185a487bab4be2029956047e9d723236a6f1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 18 Aug 2015 14:34:55 -0400 Subject: [PATCH] Changed API to allow for multiple instances --- README.md | 11 ++++++----- index.js | 7 ++++--- package.json | 2 +- test/index.js | 27 +++++++++------------------ 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index edffc17..9b38376 100644 --- a/README.md +++ b/README.md @@ -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/) @@ -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'); ```` diff --git a/index.js b/index.js index c0dad56..4c5fefd 100644 --- a/index.js +++ b/index.js @@ -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(); } @@ -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; \ No newline at end of file diff --git a/package.json b/package.json index f9c2086..7be40f6 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/index.js b/test/index.js index c6e9571..10d028e 100644 --- a/test/index.js +++ b/test/index.js @@ -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); }); }); }); \ No newline at end of file