{"_id":"timepiece","_rev":"12-b7a1b7daa46dc173fd29d2a429813caf","name":"timepiece","time":{"modified":"2022-06-27T06:49:15.436Z","created":"2013-03-18T16:37:02.161Z","0.0.1":"2013-03-18T16:37:07.471Z","0.0.2":"2013-03-23T18:41:56.902Z","0.0.3":"2013-06-01T00:08:49.224Z","0.0.0":"2015-09-23T07:56:07.361Z","0.4.0":"2015-09-30T06:12:18.613Z"},"maintainers":[{"name":"rafaele","email":"rafael@rafaelespinoza.com"}],"dist-tags":{"latest":"0.4.0"},"description":"countdown timer, stopwatch and metronome","readme":"# timepiece\n\nA set of event emitters, built around `setInterval`. It's for casual use and\nthe API is pretty straight-forward. I would *not* recommend the stopwatch for\nbenchmarking, performance tests, or anything else requiring accuracy finer\nthan to-the-centisecond.\n\nThe base class is `Timepiece`. From that, there are a few subclasses.\n\n* `Metronome`: set the tempo, by beats per minute. Add your event listeners\n  to the 'tick' event.\n* `Countdown`: count down timer, set from a number of seconds.\n* `Stopwatch`: measure elapsed time and save splits.\n  * Because of the non-guarantee of when exactly `setInterval` fires events,\n    don't use this if you need precision to-the-millisecond or finer.\n\nAll classes will these emit these events:\n\n* `'start'`: emitted when the object starts.\n* `'stop'`: emitted when the object stops.\n* `'set'`: emitted when you change some setting on an object. The setting will\n  vary from class to class.\n* `'tick'`: once an object has started, it will emit a 'tick' event at some\n  interval of time. The interval is once per second, unless of course, you are\n  using a `Metronome` at a tempo other than the default.\n\n### Installation\n\n`$ npm install timepiece`\n\n## Usage\n\n### `Metronome`\n\n```javascript\nvar Metronome = require('timepiece').Metronome;\n\n// By default, a metronome object is set to 60 bpm.\nvar metronome = new Metronome();\n// But you could also initialize one at another tempo.\nvar allegro = new Metronome(144);\n\n// It emits a 'tick' event on each beat\nmetronome.on('tick', function logBPM(){\n  console.log(metronome.bpm + ' bpm');\n});\n\n// Start metronome. Emits a 'start' event.\nmetronome.start();\n\n// practice your instrument...\n\n// Change the tempo, immediately. Emits of a 'set' event.\nmetronome.set(108);\n\n// Stop metronome. Emits a 'stop' event.\nmetronome.stop();\n```\n\n### `Countdown`\n\n```javascript\nvar Countdown = require('timepiece').Countdown;\n\n// By default, count down from 60 seconds.\nvar countdown = new Countdown();\n// But you could also count down from any other span, set by number of seconds.\nvar countdownFrom90 = new Countdown(90); // a minute & thirty seconds\n\n// It emits a 'tick' event, once per second.\ncountdown.on('tick', function reportTimeLeft() {\n  console.log(countdown.remaining);\n});\n\n// Start the timer. Emits a 'start' event.\ncountdown.on('start', function stopped() {\n  console.log('starting timer at ' + countdown.from + ' seconds');\n});\ncountdown.start();\n\n// Pause the timer. Emits a 'stop' event\ncountdown.on('stop', function stopped() {\n  console.log('stopped timer with' + countdown.remaining + ' seconds left.');\n});\ncountdown.pause(); // you could also call `#stop` for the same behavior.\n\n// Resume the timer from wherever you left off\ncountdown.resume(); // you could also call `#start`\n\n// Reset the timer to its original count down setting\n// NOTE: this does not start the timer again, you do this manually.\ncountdown.reset();\n\n// Set the timer to count down from another value\n// NOTE: this method checks if the timer is active, before doing anything.\n// If the timer is already active, then nothing happens.\ncountdown.set(30);\n\n// It emits a 'finish' event, when timer runs out.\ncountdown.on('finish', function happy() {\n  console.log('exciting stuff!');\n});\n```\n\n### `Stopwatch`\n\n```javascript\nvar Stopwatch = require('timepiece').Stopwatch;\n\nvar stopwatch = new Stopwatch();\n\n// It emits a 'tick' event, once per second.\nstopwatch.on('tick', function reportElapsedTime() {\n  console.log(stopwatch.elapsed + ' seconds');\n});\n\n// Start the stopwatch. Emits a 'start' event.\nstopwatch.start();\n\n// Split time, save to the `laps` array. Emits of 'split' event.\n// The stopwatch continues running.\nstopwatch.on('split', function showLaps() {\n  console.log(stopwatch.laps);\n});\nstopwatch.split();\n\n// Stop the stopwatch. Emits a 'stop' event.\nstopwatch.stop();\n\n// Reset the timer back to 0 seconds. Does not start it again.\nstopwatch.reset();\n```\n","versions":{"0.0.0":{"name":"timepiece","version":"0.0.0","description":"a clock, countdown timer, interval timer, stopwatch and metronome","main":"index.js","scripts":{"test":"mocha ./spec/**/*.js"},"keywords":["clock","countdown","interval","timer","stopwatch","metronome"],"author":{"name":"Rafael Espinoza","email":"rafael@rafaelespinoza.com","url":"http://www.rafaelespinoza.com"},"license":"ISC","repository":{"type":"git","url":"git+ssh://git@github.com/NerdDiffer/timepiece.git"},"bugs":{"url":"https://github.com/NerdDiffer/timepiece/issues"},"homepage":"https://github.com/NerdDiffer/timepiece#readme","_id":"timepiece@0.0.0","_shasum":"dd63b670d97b6fd736195b38a0a094c3030845ee","_from":".","_npmVersion":"3.3.3","_nodeVersion":"4.1.0","_npmUser":{"name":"rafaele","email":"rafael@rafaelespinoza.com"},"maintainers":[{"name":"rafaele","email":"rafael@rafaelespinoza.com"}],"dist":{"shasum":"dd63b670d97b6fd736195b38a0a094c3030845ee","tarball":"https://registry.npmjs.org/timepiece/-/timepiece-0.0.0.tgz","integrity":"sha512-P8MhWHY0E9655luQe7tJa1VUn8hh5PTtVGUg8uUliM+3T+O6e5IOw5KWMAqhlG0P/Sn1scmMpJHXqQiopcVIWg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCt82IHJhAICYXiGW4p/aKBzxKB160K4HK7vRz9ndaw4AIgHJt9IXngjNm766mlDvXIMhzGjEVdimmMOJxagAI+6kw="}]}},"0.4.0":{"name":"timepiece","version":"0.4.0","description":"countdown timer, stopwatch and metronome","main":"index.js","scripts":{"test":"mocha ./spec/**/*_spec.js"},"keywords":["countdown","interval","timer","stopwatch","metronome"],"author":{"name":"Rafael Espinoza","email":"rafael@rafaelespinoza.com","url":"http://www.rafaelespinoza.com"},"license":"ISC","repository":{"type":"git","url":"git+ssh://git@github.com/NerdDiffer/timepiece.git"},"bugs":{"url":"https://github.com/NerdDiffer/timepiece/issues"},"homepage":"https://github.com/NerdDiffer/timepiece#readme","dependencies":{"inherits":"^2.0.1"},"devDependencies":{"mocha":"^2.3.3"},"gitHead":"975fb28912a8a116d4d32f5896e9de0a3fbb9de3","_id":"timepiece@0.4.0","_shasum":"3a913ed9ecb9f06aa7a7117e94026298937afa65","_from":".","_npmVersion":"3.3.3","_nodeVersion":"4.1.0","_npmUser":{"name":"rafaele","email":"rafael@rafaelespinoza.com"},"maintainers":[{"name":"rafaele","email":"rafael@rafaelespinoza.com"}],"dist":{"shasum":"3a913ed9ecb9f06aa7a7117e94026298937afa65","tarball":"https://registry.npmjs.org/timepiece/-/timepiece-0.4.0.tgz","integrity":"sha512-nnAZEo3Z+vNatlVsj9AXmQsj+ELspNGiTQNirf9uksY0phdgnSBJHOG3OHp4DGE5mQpV0FDk8BTG3nvi8pZPxQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDFuulL0iUVm0HF64H5IexAAsJ4/k4uIqra/MIzPlaq1AiB8mU360psvUd6sIEV4h67NRGJl4hGoixESkqokOgw0ww=="}]}}},"homepage":"https://github.com/NerdDiffer/timepiece#readme","keywords":["countdown","interval","timer","stopwatch","metronome"],"repository":{"type":"git","url":"git+ssh://git@github.com/NerdDiffer/timepiece.git"},"author":{"name":"Rafael Espinoza","email":"rafael@rafaelespinoza.com","url":"http://www.rafaelespinoza.com"},"bugs":{"url":"https://github.com/NerdDiffer/timepiece/issues"},"license":"ISC","readmeFilename":"README.md"}