{"name":"durations","description":"Duration tracking and formattng for node.js","keywords":["Stopwatch","Monitoring","Performance","Duration"],"version":"1.0.1","author":{"name":"Joel Edwards","url":"https://github.com/joeledwards"},"contributors":[{"name":"Joel Edwards","email":"joeledwards@gmail.com","url":"https://github.com/joeledwards"}],"repository":{"type":"git","url":"https://github.com/joeledwards/node-durations.git"},"licenses":[{"type":"MIT","url":"https://github.com/joeledwards/node-durations/blob/master/LICENSE"}],"main":"./lib/index","directories":{"lib":"./lib"},"dependencies":{"q":">=1.2 <2"},"devDependencies":{"coffee-script":"~1.7.1","mocha":"~1.20.1","timeunit":"~1.1.1"},"scripts":{"prepublish":"cake build","build":"cake build","test":"cake test"},"engines":{"node":">=0.8.1"},"gitHead":"df7fc03da71b0bc3be0740da63d80e73e8a88b3c","bugs":{"url":"https://github.com/joeledwards/node-durations/issues"},"homepage":"https://github.com/joeledwards/node-durations","_id":"durations@1.0.1","_shasum":"77e122a2fbb7b6faa6aa3816a790338c426ca8d5","_from":".","_npmVersion":"2.7.5","_nodeVersion":"0.10.38","_npmUser":{"name":"buzuli","email":"joeledwards@gmail.com"},"maintainers":[{"name":"buzuli","email":"joeledwards@gmail.com"}],"dist":{"shasum":"77e122a2fbb7b6faa6aa3816a790338c426ca8d5","tarball":"http://registry-npm.ywwl.com/durations/download/durations-1.0.1.tgz","integrity":"sha512-bIDOw+WWz6C5VCjILi//z1q2cvjUni/VoIFN4QyDvjr6phjWRtR0vYRQVc8CckeUb7ltnrJ1u35ycbaCFaG/vw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFOvcPvwRoRj3izhqe/myFSgZt9Cp7/zTm9jEpwa6p3aAiEAoz6EgxfadZdiG9tfUx8psOjhWwxBak/K/dnUNJUTjXQ="}],"size":5017,"noattachment":false,"key":"/durations/-/durations-1.0.1.tgz"},"readme":"# durations\n\n[![Build Status][travis-image]][travis-url]\n[![NPM version][npm-image]][npm-url]\n\n## Compatibilty\n\nBoth Node.js and browsers are supported by `durations`. When using Node.js, the nanosecond-granulatiry `process.hrtime()` function is used. The best substitution is selected when in the browser such that consistency is maintained even if time granularity cannot be.\n\n## Installation\n\n```shell\nnpm install --save durations\n```\n\n## Methods\n\nThe following functions are exported:\n* `duration(nanoseconds)` - constructs a new Duration\n* `nanos(nanoseconds)` - constructs a new Duration\n* `micros(microseconds)` - constructs a new Duration\n* `millis(milliseconds)` - constructs a new Duration\n* `seconds(seconds)` - constructs a new Duration\n* `stopwatch()` - constructs a new Stopwatch (stopped)\n* `time(function)` - times a function synchronously\n* `timeAsync(function(callback))` - times a function asynchronously\n* `timePromised(function())` - times a promise-returning function\n\n## Duration\n\nRepresents a duration with nanosecond granularity, and provides methods\nfor converting to other granularities, and formatting the duration.\n\n### Methods\n* `format()` - human readable string representing the duration\n* `nanos()` - duration as nanoseconds\n* `micros()` - duration as microseconds\n* `millis()` - duration as milliseconds\n* `seconds()` - duration as seconds\n* `minutes()` - duration as minutes\n* `hours()` - duration as hours\n* `days()` - duration as days\n\n```javascript\nconst {duration} = require('durations')\n\nconst nanoseconds = 987654321\nconsole.log(\"Duration is\", duration(nanoseconds).format())\n\n// Or, since toString() is an alias to format()\nconsole.log(`Duration is ${duration(nanoseconds)}`)\n```\n\n## Stopwatch\n\nA nanosecond granularity (on Node.js) stopwatch with chainable control methods,\nand built-in formatting.\n\n### Stopwatch Methods\n* `start()` - start and return the stopwatch (no-op if already running)\n* `stop()` - stop and return the stopwatch (no-op if not running)\n* `reset()` - reset to zero elapsed time and return the stopwatch (implies stop)\n* `duration()` - fetch the elapsed time as a Duration\n* `isRunning()` -  is the stopwatch running (`true`/`false`)\n\n```javascript\nconst {stopwatch} = require('durations')\nconst watch = stopwatch()\n\n// Pauses the stopwatch. Returns the stopwatch.\nwatch.stop()\n\n// Starts the stopwatch from where it was last stopped. Returns the stopwatch.\nwatch.start()\n\n// Reset the stopwatch (duration is set back to zero). Returns the stopwatch.\nwatch.reset()\n\nconsole.log(`${watch.duration().seconds()} seconds have elapsed`)\n// OR\nconsole.log(`${watch} have elapsed`)\n```\n\n## Timer\n\nTimes the execution of a function, and returns the duration.\n\n```javascript\nconst {time: timeSync, timeAsync} = require('durations')\n\n// Synchronous work\nconst someFunction = () => {\n  let count = 0\n\n  while (count < 1000000) {\n    count++\n  }\n\n  console.log(`Count is: ${count}`)\n}\n\nconsole.log(`Took ${timeSync(someFunction)} to do something`)\n\n// Asynchronous work\nconst someOtherFunction = next => {\n  someFunction()\n  next()\n}\n\ntimeAsync(someOtherFunction, duration => {\n  console.log(`Took ${duration} to do something else.`)\n})\n\n// Promised work\nconst somePromisedOp = () => {\n  return new Promise((resolve) => {\n    someFunction()\n    resolve()\n  })\n}\n\ntimePromised(somePromisedOp)\n.then(duration => {\n  console.log(`Took ${duration} to keep promise.`)\n})\n```\n\n[travis-url]: https://travis-ci.org/joeledwards/node-durations\n[travis-image]: https://img.shields.io/travis/joeledwards/node-durations/master.svg\n[npm-url]: https://www.npmjs.com/package/durations\n[npm-image]: https://img.shields.io/npm/v/durations.svg\n","publish_time":1429808223582,"_cnpm_publish_time":1429808223582,"dist-tags":{"latest":"3.4.2"}}