{"_id":"timer-machine","_rev":"13-86f179dfed1f0dd3be02ce609e07c268","name":"timer-machine","description":"A lightweight, pause-able timer class","dist-tags":{"latest":"1.1.0"},"versions":{"0.0.1":{"name":"timer-machine","version":"0.0.1","description":"A lightweight, pause-able timer class","main":"lib/timer.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"keywords":["timer","time","pause","stopwatch"],"author":{"name":"Brent Burgoyne"},"license":"MIT","bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"homepage":"https://github.com/brentburgoyne/timer-machine","devDependencies":{"mocha":"^1.20.1","should":"^4.0.4"},"_id":"timer-machine@0.0.1","_shasum":"49ac81f1d8fc1565c37717b23eae3d7d7bea704b","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"brentburgoyne","email":"brent47@gmail.com"},"maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"dist":{"shasum":"49ac81f1d8fc1565c37717b23eae3d7d7bea704b","tarball":"https://registry.npmjs.org/timer-machine/-/timer-machine-0.0.1.tgz","integrity":"sha512-rJZ/MtJIfsozR19/K36RY+t3ZujXaIECUg2NylylDjvBOHo21qPVoVaQtU6RC/BixPRZ1kUgVQWtKPTRVim96w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFZfPKGrcc465UzBFNr/thWi3kMUaPM9nPBbhVVM8J84AiEAt42Xkuk71AHaXc3NAPpkDn2M+kh+N62lNDS/X+aqTA4="}]}},"0.1.0":{"name":"timer-machine","version":"0.1.0","description":"A lightweight, pause-able timer class","main":"lib/timer.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"keywords":["timer","time","pause","stopwatch"],"author":{"name":"Brent Burgoyne"},"license":"MIT","bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"homepage":"https://github.com/brentburgoyne/timer-machine","devDependencies":{"mocha":"^1.20.1","should":"^4.0.4","sinon":"^1.10.3"},"_id":"timer-machine@0.1.0","_shasum":"15080e1c37bfa5980646db667778478cc53e3781","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"brentburgoyne","email":"brent47@gmail.com"},"maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"dist":{"shasum":"15080e1c37bfa5980646db667778478cc53e3781","tarball":"https://registry.npmjs.org/timer-machine/-/timer-machine-0.1.0.tgz","integrity":"sha512-Z6Bfe415SjklXx2lOtG9pMuI/16rl0Q2rUCoFdUjYwcX6e6I2oQaegto4a18zedzf+huqqCc45jXlb0lQG3ZPA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAvUGnpoPI71/SvzurQ3F6NSFDMQsZJBeNHdlcZ+g+A/AiEA+Q+JEIjAPcDHbyQopBmqxViVGn8xWSHdFpVXMZkZJCU="}]}},"1.0.0":{"name":"timer-machine","version":"1.0.0","description":"A lightweight, pause-able timer class","main":"lib/timer.js","scripts":{"test":"jshint lib test && mocha"},"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"keywords":["timer","time","pause","stopwatch"],"author":{"name":"Brent Burgoyne"},"license":"MIT","bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"homepage":"https://github.com/brentburgoyne/timer-machine","devDependencies":{"jshint":"^2.5.2","mocha":"^1.20.1","should":"^4.0.4","sinon":"^1.10.3"},"_id":"timer-machine@1.0.0","_shasum":"162efbc6ff2c77f87d6b75e3e6cced0b8e662e65","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"brentburgoyne","email":"brent47@gmail.com"},"maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"dist":{"shasum":"162efbc6ff2c77f87d6b75e3e6cced0b8e662e65","tarball":"https://registry.npmjs.org/timer-machine/-/timer-machine-1.0.0.tgz","integrity":"sha512-hSuA2PwcH0GFC8I7dRXhf8q7wdELJMaTPO4DRwVhUvQXJYi5wIyGREz48zpyosXU+1Md8FE4YVMieoVYN0gI8A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBlPc0FrIHtjlwyvKPnf4YwXWFc4GbXav3Bm2hqtQuEOAiEAqtIqesUdiOxo6ziFFGePyPviRzJ1y4KNZCPXbGknQwg="}]}},"1.0.1":{"name":"timer-machine","version":"1.0.1","description":"A lightweight, pause-able timer class","main":"lib/timer.js","scripts":{"test":"jshint lib test && mocha"},"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"keywords":["timer","time","pause","stopwatch"],"author":{"name":"Brent Burgoyne"},"license":"MIT","bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"homepage":"https://github.com/brentburgoyne/timer-machine","devDependencies":{"jshint":"^2.5.2","mocha":"^1.20.1","should":"^4.0.4","sinon":"^1.10.3"},"_id":"timer-machine@1.0.1","_shasum":"f7a3ca04c7f8b94275b3ed7388181038ceb55c68","_from":".","_npmVersion":"1.4.9","_npmUser":{"name":"brentburgoyne","email":"brent47@gmail.com"},"maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"dist":{"shasum":"f7a3ca04c7f8b94275b3ed7388181038ceb55c68","tarball":"https://registry.npmjs.org/timer-machine/-/timer-machine-1.0.1.tgz","integrity":"sha512-oOprv0qL9qDK3LStPC2tMt0mJOKQl9JzbLeDgVS4mlxuu5xYh+A9HnaH3t6Uqp1LOAQUDi9WkAs7vVAgcZUFVA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDgXaqtWxlaPA1LzQktqkIEt9lyOk/0+mBEHxwNRbEfoAIgbn7WJFDtL8ci0XOUWl7wl5zTX0lfaaSrGbgzFNcMGwE="}]}},"1.1.0":{"name":"timer-machine","version":"1.1.0","description":"A lightweight, pause-able timer class","main":"lib/timer.js","scripts":{"test":"jshint lib && mocha","debug-test":"mocha debug"},"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"keywords":["timer","time","pause","stopwatch"],"author":{"name":"Brent Burgoyne"},"license":"MIT","bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"homepage":"https://github.com/brentburgoyne/timer-machine","devDependencies":{"jshint":"^2.5.2","mocha":"^1.20.1","should":"^4.0.4","sinon":"^1.10.3"},"gitHead":"636a143d3f09086783614124e6840199884a0cf4","_id":"timer-machine@1.1.0","_shasum":"c66d3c226ec53ae48f54bdc03c402fe9840647fe","_from":".","_npmVersion":"3.5.2","_nodeVersion":"4.2.6","_npmUser":{"name":"brentburgoyne","email":"brent47@gmail.com"},"dist":{"shasum":"c66d3c226ec53ae48f54bdc03c402fe9840647fe","tarball":"https://registry.npmjs.org/timer-machine/-/timer-machine-1.1.0.tgz","integrity":"sha512-XzR83MkxomL9J+p+Jnwc7sVlIXho9fPoRcoF/hHluifX2mAIIJGU3uQ15KCzbDtP1/kshVbRGqDYlW0niThhQQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAgXutrSdyxW0gnkOqe4mUbbUQe4olTPcOALNWuS/0+JAiBLQhR3ALXqJljngIpg3phDp+baPreUxvCHD5mg0dZmkQ=="}]},"maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/timer-machine-1.1.0.tgz_1469363733413_0.9618524946272373"}}},"readme":"# Timer Machine\n\n[![npm](http://img.shields.io/npm/v/timer-machine.svg?style=flat)](https://www.npmjs.org/package/timer-machine)\n[![Travis](http://img.shields.io/travis/brentburgoyne/timer-machine.svg?style=flat)](https://travis-ci.org/brentburgoyne/timer-machine)\n[![Code Climate](http://img.shields.io/codeclimate/github/brentburgoyne/timer-machine.svg?style=flat)](https://codeclimate.com/github/brentburgoyne/timer-machine)\n[![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/brentburgoyne/timer-machine.svg?style=flat)](https://codeclimate.com/github/brentburgoyne/timer-machine)\n[![Gemnasium](http://img.shields.io/gemnasium/brentburgoyne/timer-machine.svg?style=flat)](https://gemnasium.com/brentburgoyne/timer-machine)\n\nA simple, flexible timer for JavaScript.\n\n## Installation\n\n```bash\n$ npm install timer-machine --save\n```\n\n## Basic Usage\n\n```js\nvar Timer = require('timer-machine')\nvar myTimer = new Timer()\n\nmyTimer.start()\nmyTimer.stop()\nmyTimer.time() // -> time in ms\n```\n\n## Named Timers\n\nTimer Machine can maintain references to named timers. When the static method\n`get('name')` is called, it constructs a new instance if the name did not\nalready exist, and returns the instance of `Timer`. This makes it easy to share a\ntimer across multiple modules.\n\n```js\nTimer.get('my').start()\nTimer.get('my').time()\n```\n\nAlternatively, use it on the require if you only need a single named instance.\n\n```js\nvar myTimer = require('timer-machine').get('my')\n```\n\nTimer Machine allows for deleting named timers by calling the `destroy('name')`\nstatic method.\n\n```js\nTimer.destroy('my')\n```\n\n## Timer Controls\n\n### `start()`\n\nBy default, a new `Timer` object is stopped, unless the first argument of the\nconstructor is `true`, and is started by calling the `start()` method. The\n`start()` method returns a `Boolean` indicating whether or not the timer was\nstarted.\n\n```js\nvar timer1 = new Timer()\ntimer1.start() // -> true - the timer started\n\nvar timer2 = new Timer(true)\ntimer2.start() // -> false - the timer is already started\n```\n\n### `stop()`\n\nTo stop or pause a timer, call the `stop()` method. Similar to the `start()`\nmethod, `stop()` returns a `Boolean` indicating whether or not the timer was\nstopped.\n\n```js\nvar timer = new Timer()\ntimer.stop() // -> false - the timer is already stopped\ntimer.start()\ntimer.stop() // -> true - the timer stopped\n```\n\nA stopped `Timer` can be started again. The timer will only track the total\nlength of time the timer has been started.\n\n```js\nvar timer = new Timer()\ntimer.start()\ntimer.stop()\ntimer.start()\n```\n\n### `toggle()`\n\nThe `toggle()` method will call `start()` if the `Timer` is stopped or `stop()`\nif the timer is started.\n\n```js\nvar timer = new Tiemr()\ntimer.isStarted() // -> false\ntimer.toggle()\ntimer.isStarted() // -> true\ntimer.toggle()\ntimer.isStarted() // -> false\n```\n\n## Time\n\n### `time()`\n\nTo get the length of time that a timer has run, the `time()` method can be used\nto a `Number` of the current time in milliseconds.\n\n```js\nvar timer = new Timer()\ntimer.start()\nsetTimeout(function () {\n  timer.time() // -> ~100\n}, 100)\n```\n\n### `emitTime()`\n\nThe `emitTime()` method is the same as the `time()` method, except it emits a\n`'time'` event with the current time in milliseconds. See [Events](#Events)\nbelow.\n\n### `valueOf()`\n\nOn `Timer` objects, `valueOf()` is an alias for `time()` and is used internally\nby JavaScript when a timer object is converted to a primitive value. This is\nuseful for, among other things, adding and subtracting timers.\n\n```js\n//...\ntimer1.time() // -> 50\ntimer2.time() // -> 30\ntimer1 + timer2 // -> 80\ntimer1 - timer2 // -> 20\ntimer + 0 // -> 50\n```\n\n### `toString()`\n\nTo string is used by JavaScript to convert an object in to a string. The `Timer`\n`toString()` method returns the `time()` prepended with \"ms\".\n\n```js\nconsole.log(\"Current time: \" + timer1) // -> \"Current time: 50ms\"\n```\n\n### `timeFromStart()`\n\nWhile the `time()` returns the total number of milliseconds for the `Timer`,\n`timeFromStart()` returns only the time since the most recent `start()`.\n\n```js\nvar timer = new Timer()\ntimer.start()\ntimer.timeFromStart() === timer.time() // -> true\n//...\ntimer.stop()\ntimer.start()\ntimer.timeFromStart() === timer.time() // -> false\n```\n\n## Timer State\n\n### `isStarted()`\n\nA `Timer` object has an `isStarted()` method. It returns a `true` if the timer\nis started and `false` if it is stopped.\n\n```js\nvar timer = new Timer\ntimer.isStarted() // -> false\ntimer.start()\ntimer.isStarted() // -> true\n```\n\n### `isStopped()`\n\nA `Timer` object has an `isStopped()` method, which is the inverse of the\n`isStarted()` method.\n\n```js\nvar timer = new Timer\ntimer.isStopped() // -> true\ntimer.start()\ntimer.isStopped() // -> false\n```\n\n## Events\n\nA `Timer` object inherits from [`EventEmitter`][1] allowing event listeners to\nadded an removed. A `Timer` emits three events.\n\n### Event: `'start'`\n\nThe `'start'` event is emitted every time a `Timer` is started, whether it be\nby the `start()` method or `toggle()` method.\n\n```js\ntimer.on('start', function () {\n  console.log('The timer started')\n})\n```\n\n### Event: `'stop'`\n\nThe `'stop'` event is emitted every time a `Timer` is stopped, whether it be\nby the `stop()` method or `toggle()` method.\n\n```js\ntimer.on('stop', function () {\n  console.log('The timer stopped')\n})\n```\n\n### Event `'time'`\n\nThe `'time'` event is only emitted when the `emitTIme()` method is called. The\nevent handler callback receives the current time in milliseconds as the first\nargument.\n\n```js\nvar timer = new Timer()\ntimer.on('time', function (time) {\n  console.log('Current time: ' + time + 'ms')\n})\ntimer.start()\nsetInterval(timer.emitTime.bind(timer), 1000)\n```\n\n## Development\n\nPull requests are welcome.\n\n### Get the code\n\n```bash\n$ git clone git@github.com:brentburgoyne/timer-machine.git\n```\n\n### Install the dependencies\n\n```bash\n$ npm install\n```\n\n### Run the tests\n\n```bash\n$ npm test\n```\n\n## License\n\nCopyright (c) 2014 Brent Burgoyne.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n[1]: http://nodejs.org/api/events.html#events_class_events_eventemitter\n","maintainers":[{"name":"brentburgoyne","email":"brent47@gmail.com"}],"time":{"modified":"2022-06-27T06:49:39.610Z","created":"2014-07-20T13:23:00.601Z","0.0.1":"2014-07-20T13:23:00.601Z","0.1.0":"2014-07-21T12:46:52.446Z","1.0.0":"2014-07-27T05:51:32.588Z","1.0.1":"2014-07-27T06:04:56.823Z","1.1.0":"2016-07-24T12:35:35.259Z"},"homepage":"https://github.com/brentburgoyne/timer-machine","keywords":["timer","time","pause","stopwatch"],"repository":{"type":"git","url":"git://github.com/brentburgoyne/timer-machine.git"},"author":{"name":"Brent Burgoyne"},"bugs":{"url":"https://github.com/brentburgoyne/timer-machine/issues"},"license":"MIT","readmeFilename":"README.md","users":{"mkwr":true,"poolpeggy":true}}