{"name":"durations","description":"Duration tracking and formattng for node.js","keywords":["Stopwatch","Monitoring","Performance","Duration"],"version":"3.3.4","author":{"name":"Joel Edwards","url":"https://github.com/joeledwards"},"contributors":[{"name":"Joel Edwards","email":"joeledwards@gmail.com","url":"https://github.com/joeledwards"}],"license":"MIT","repository":{"type":"git","url":"git+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"},"devDependencies":{"coffee-script":"^1.12.7","mocha":"^2.3.4","timeunit":"^1.1.1"},"scripts":{"prepublish":"cake build","build":"cake build","test":"cake test"},"engines":{"node":">=0.10.0"},"gitHead":"01095100ca0951ff7a6acf2641e8691fadfbd938","bugs":{"url":"https://github.com/joeledwards/node-durations/issues"},"homepage":"https://github.com/joeledwards/node-durations#readme","_id":"durations@3.3.4","_npmVersion":"5.4.2","_nodeVersion":"8.6.0","_npmUser":{"name":"buzuli","email":"joeledwards@gmail.com"},"dist":{"integrity":"sha512-Xq4RYBfqEfSXjy/7LXw4Su7LH2hDizfBi0VcxO4d7PhZyDhRUTFfuG2+U36Dc51N3nIc9XB2cp5rrBekh3XeEg==","shasum":"503216d7d58c92f983d78780aff8fd81bfafaab0","tarball":"http://registry-npm.ywwl.com/durations/download/durations-3.3.4.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIC0wBrpieI9hZLK7wQoywwBjZNu8srBaGzgCDqYX8DklAiEAjVxHVQ37ISm01Jl95/iaErWzY4RKBf8BXnjjA5XFhTs="}],"size":4849,"noattachment":false,"key":"/durations/-/durations-3.3.4.tgz"},"maintainers":[{"name":"buzuli","email":"joeledwards@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/durations-3.3.4.tgz_1516002383791_0.037233821814879775"},"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":1516002383863,"_cnpm_publish_time":1516002383863,"dist-tags":{"latest":"3.4.2"}}