{"_id":"@dbpiper/timer","_rev":"2-b9236e359c910de0173c90decdd83da0","name":"@dbpiper/timer","dist-tags":{"latest":"1.0.0-beta.2"},"versions":{"1.0.0-beta.1":{"author":{"name":"David Piper","email":"david.piper@mailfence.com"},"bugs":{"url":"https://github.com/dbpiper/module-starter-kit/issues"},"dependencies":{"@types/lodash":"^4.14.123","lodash":"^4.17.11","moment":"^2.24.0"},"description":"Simple module to time your code JavaScript or TypeScript code, to see how long it took to run.","devDependencies":{"@babel/cli":"^7.4.3","@babel/core":"^7.4.3","@babel/plugin-proposal-class-properties":"^7.4.0","@babel/preset-env":"^7.4.3","@babel/preset-typescript":"^7.3.3","@babel/register":"^7.4.0","@commitlint/cli":"^7.5.2","@commitlint/config-conventional":"^7.5.0","@types/gulp":"^4.0.6","@types/jest":"^24.0.11","babel-eslint":"^10.0.1","commitlint":"^7.5.2","eslint":"^5.16.0","gulp":"^4.0.0","husky":"^1.3.1","jest":"^24.7.0","terminal-spawn":"^2.0.3","ts-jest":"^24.0.1","tslint":"^5.15.0","tslint-config-euclid":"^1.1.1","tslint-config-prettier":"^1.18.0","typescript":"^3.4.1","typescript-tslint-plugin":"^0.3.1"},"directories":{"example":"example"},"homepage":"https://github.com/dbpiper/module-starter-kit#readme","husky":{"hooks":{"commit-msg":"npx commitlint -E HUSKY_GIT_PARAMS","pre-commit":"npm run verify","pre-push":"npm run verify"}},"keywords":["starter-kit","modules","npm","bootstrap"],"license":"MIT","main":"lib/timer.js","name":"@dbpiper/timer","repository":{"type":"git","url":"git+https://github.com/dbpiper/module-starter-kit.git"},"scripts":{"build":"npx gulp build","lint":"npx gulp lint","prepublishOnly":"npm run build","test":"npx gulp test","verify":"npx gulp verify","verifyCi":"npx gulp verifyCi"},"version":"1.0.0-beta.1","gitHead":"5d97dbfb3a9adf1e317b2e2efc3cbcf159156c13","_id":"@dbpiper/timer@1.0.0-beta.1","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"dbpiper","email":"david.piper@mailfence.com"},"dist":{"integrity":"sha512-dEZ++Gvtvt2UyjqXlYnbvtvPKbtazObtOehdKhfM1By7z+6Gl6X7rEzf2mQpf0CdvxDjx5e75c2tAQBjQPcKbg==","shasum":"0bcd131033df5fa21b2a910e7f8bfd23dd677996","tarball":"https://registry.npmjs.org/@dbpiper/timer/-/timer-1.0.0-beta.1.tgz","fileCount":7,"unpackedSize":13894,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcpksQCRA9TVsSAnZWagAAR/8QAI7CyCESBC9NxlN6ITmy\nOzBVjIqvQuYSrvr3ld95pC6VDUP2dG7T2TGVqxnCE1PVAQ6ESmLVOSOAIkWF\nn367zzdC7CBTSDnbPXohw3+oYfNkD9NoVAmxs+vbMdrcVlVGHp2ZYlJxXrtK\nSGawUXplJa75NF/V960CH0x8Df6KGHQFSfXwHV7RuOv3Vk7TjkHOPl4Um083\nB3VlM/ajMJPmF9m8yCbZG9rsCQOd+1BsxMmT2388S4WMvLB25XElud5Z4Tx3\nz/LfQTiMpnATYxHf+HPmYsTfXBvJIH1MSg6XZ+PFBWWSCkjGOI35WNpnyTVf\nQ3QHJlNLXkxCMof/7makAczqAanGFP/EbLNeqeW7KnObSeCSvc13BykvaCej\nTPekJl0q0OSv+eO/oWp7uzddQczXjINcIsnE4PI7hdEIJRTZJC3QQ+Lt2GNC\n7/zZ+VIx5nXBPR/LZXFvG3BvRPD9rx8xMFc+mLkX7O2PIHJppktewl8wN7Rs\niwHgoyeTPTIt/4GY7yLfOM+I9xHsJVv61WIRGlpMhx+zMfoq9JCp76T3Lz9M\noVB6MZTetSlm8zk+WxJlVo9Mup2sCe+qSHxu+McwE+Lgjo4KkDd4UI297I6d\n2t9vgZFiIN+5tsuHcz+X3xfAxiDwk7OULirNXIZbfpI6ViSWjGBeusar5PlJ\n9YsY\r\n=RTOM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChUktJU32tPXc9rgZp+MWZ3F5j6EmS0Z7FdTghdWnwwAIgT/jNtUTRsB2lYpXdz64W4QBpC3B6+NGMBourKEZV8u0="}]},"maintainers":[{"name":"dbpiper","email":"david.piper@mailfence.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/timer_1.0.0-beta.1_1554402063030_0.4045177840103069"},"_hasShrinkwrap":false},"1.0.0-beta.2":{"author":{"name":"David Piper","email":"david.piper@mailfence.com"},"bugs":{"url":"https://github.com/dbpiper/timer/issues"},"dependencies":{"@types/lodash":"^4.14.123","lodash":"^4.17.11","moment":"^2.24.0"},"description":"Simple module to time your code JavaScript or TypeScript code, to see how long it took to run.","devDependencies":{"@babel/cli":"^7.4.3","@babel/core":"^7.4.3","@babel/plugin-proposal-class-properties":"^7.4.0","@babel/preset-env":"^7.4.3","@babel/preset-typescript":"^7.3.3","@babel/register":"^7.4.0","@commitlint/cli":"^7.5.2","@commitlint/config-conventional":"^7.5.0","@types/gulp":"^4.0.6","@types/jest":"^24.0.11","babel-eslint":"^10.0.1","commitlint":"^7.5.2","eslint":"^5.16.0","gulp":"^4.0.0","husky":"^1.3.1","jest":"^24.7.0","terminal-spawn":"^2.0.3","ts-jest":"^24.0.1","tslint":"^5.15.0","tslint-config-euclid":"^1.1.1","tslint-config-prettier":"^1.18.0","typescript":"^3.4.1","typescript-tslint-plugin":"^0.3.1"},"directories":{"example":"example"},"homepage":"https://github.com/dbpiper/timer#readme","husky":{"hooks":{"commit-msg":"npx commitlint -E HUSKY_GIT_PARAMS","pre-commit":"npm run verify","pre-push":"npm run verify"}},"keywords":["timer","code","timing-code","performance","speed","measurement","time"],"license":"MIT","main":"lib/timer.js","name":"@dbpiper/timer","repository":{"type":"git","url":"git+https://github.com/dbpiper/timer.git"},"scripts":{"build":"npx gulp build","lint":"npx gulp lint","prepublishOnly":"npm run build","test":"npx gulp test","verify":"npx gulp verify","verifyCi":"npx gulp verifyCi"},"version":"1.0.0-beta.2","gitHead":"f4c04f4244aeddc06aa238da94a739abff7cb23e","_id":"@dbpiper/timer@1.0.0-beta.2","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"dbpiper","email":"david.piper@mailfence.com"},"dist":{"integrity":"sha512-K4pnT5wpSZ8qKpA9sb23EiAigcA0lfRoXCEdXplD9nmPyNhE5zjbRcWf9+1QY6UbCUgRc6ks/0Yj8t0+9f9nMw==","shasum":"eea3db9d60ec84692f46635328e213c69b16ccfb","tarball":"https://registry.npmjs.org/@dbpiper/timer/-/timer-1.0.0-beta.2.tgz","fileCount":7,"unpackedSize":18784,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcpndZCRA9TVsSAnZWagAAmsQP/1N4t05ou6Dant3HymZB\n/SpEuOLaJyx30gB7NH1nybfQHVvVh5gmhqqZgij4aT/X5YuDMo9ZjQV9kvVe\ne5ZgrVVs8hSu1P/j/u7TubGxiS2ieH8MCEoKrWIJjqBO2ep1RdsmOzT5vufn\nQHWTdih6cxn9Nz1yDHySzGJDMf8x+SMdpzEst7hLtfmIDF5N2aBiIqRotSap\neZhiOKcxHHAeTRsMRLyzkwk2fMg503uXLLgmtzckMfFXrCgLXWzkUJj6sHkP\nQecKndbabajrKKtkD02fWj5MPyyp7V8RBWZ1r0yZZx8LY3LSWiQNTcYClhP3\n7caNHukf5hjvEUlRoj3/scyxJvTCHZP+dc0LcNML+PYVxqZASeia6aXOfJWH\nu+HTGi+z1TiSuXr6CvUe32XfAmxXvlnPS2zvpqCcZLdR8T0WugJD9Sv8WDla\n9nibrkiaf0Yq9xSAVGp49SUnO2vkuNZuGB/XdGRjI2xXksFd2rPNM+MJl009\nO3mgufU8rSzD3XBcraHHx9+w9QtMeDH6ZLc7BKzHgexQhNKcz2zfJqYxquym\nalJVGjrqldf7aSf5ptuYnZOqiQvchb1anl/XCzJ8oPjgWWaTCyFgemez/9mq\nyGm8II3QNkOkEcn/1ldT266S0HVjk+wfH5FCIllzNQaa/odqxwE95OkfyK3v\nlBWW\r\n=4ECc\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFE1ql9CoZbB0IdQeuP56r3UN8Qwsu26XMY20HbFUI4xAiEAvR+iUCmWhMgnhRmKTf0Pk3EuGZ13B5jx1Rhjuk1169U="}]},"maintainers":[{"name":"dbpiper","email":"david.piper@mailfence.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/timer_1.0.0-beta.2_1554413400573_0.13328242134689527"},"_hasShrinkwrap":false}},"time":{"created":"2019-04-04T18:21:02.784Z","1.0.0-beta.1":"2019-04-04T18:21:03.268Z","modified":"2022-04-05T03:18:20.741Z","1.0.0-beta.2":"2019-04-04T21:30:00.815Z"},"maintainers":[{"name":"dbpiper","email":"david.piper@mailfence.com"}],"description":"Simple module to time your code JavaScript or TypeScript code, to see how long it took to run.","homepage":"https://github.com/dbpiper/timer#readme","keywords":["timer","code","timing-code","performance","speed","measurement","time"],"repository":{"type":"git","url":"git+https://github.com/dbpiper/timer.git"},"author":{"name":"David Piper","email":"david.piper@mailfence.com"},"bugs":{"url":"https://github.com/dbpiper/timer/issues"},"license":"MIT","readme":"# @dbpiper/timer\n\n[![Build Status](https://travis-ci.com/dbpiper/timer.svg?branch=master)](https://travis-ci.com/dbpiper/timer)\n[![npm version](http://img.shields.io/npm/v/@dbpiper/timer.svg?style=flat)](https://npmjs.org/package/@dbpiper/timer 'View this project on npm')\n[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)\n\nSimple module to time your code JavaScript or TypeScript code, to see how long\nit took to run.\n\n## Installation Instructions\n\n```sh\nnpm install @dbpiper/timer\n```\n\n## Usage Instructions\n\n```ts\nimport Timer, { FormattedDuration } from '@dbpiper/timer';\n\n// this starts the timer running\nconst timer = new Timer();\n\n// you may also start the timer like this\n// if you wanted to create the timer instance first and then do some\n// setup before starting the timer for instance\ntimer.start();\n\n// do some stuff here\n\n// formattedDuration has the amount of time that passed between\n// the creation and stop times\nconst formattedDuration = timer.stop();\n\n// you can simply convert the result formattedDuration to a string either\n// implicitly or explicitly\n// for example:\nconsole.log(formattedDuration);\n```\n\n## API\n\n### Timer\n\nThe actual instance object that is used to access and use the timer.\nThe timer will be started automatically when an instance is created.\n\n### timer.start()\n\nAn alternative, more explicit, way to start the timer. This is automatically\ncalled by the constructor, however if you want to do some tasks after creating\nthe Timer instance, but before starting the measurement then this can be used.\n\n### timer.stop()\n\nreturn type: `FormattedDuration`\n\nThis stops the timer, and returns the amount of time that passed as a\nFormattedDuration instance object.\n\n---\n\n### FormattedDuration\n\nThe duration that passed, it is meant for easy displaying in scripts as the\nmain purpose of the module is to measure how much time a script took to run.\nThus, you would start the timer right before running it and then stop it when\ndone, printing the result to the screen or a log file or a message to an\nexternal service.\n\n### formattedDuration.hours\n\nreturn type: `number`\n\nThe amount of hours in the duration, note that since the largest unit supported\nis hours everything larger will be here. So for example 2 days would be here\nas 48 hours, since there is no \"days\" unit. The reason for this being the\nlargest unit supported is the fact that this module is intended to be used for\ntiming code.\n\nIf your code is running for days or weeks, this probably isn't the right module\nto use, rather it is intended to be used for modules that run on the order\nof minutes or maybe a few hours.\n\n### formattedDuration.minutes\n\nreturn type: `number`\n\nThe amount of minutes in the duration.\n\n### formattedDuration.seconds\n\nreturn type: `number`\n\nThe amount of seconds in the duration.\n\n### formattedDuration.milliseconds\n\nreturn type: `number`\n\nThe smallest unit that _@dbpiper/timer_ supports.\n\n### formattedDuration.toString()\n\nConverts the duration to a human-readable string, it is usually used\nimplicitly like this:\n\n```ts\nconsole.log(formattedDuration);\n// or this\n\nconst durationString = `${formattedDuration}`;\n```\n\nIt will print each of the usual units described above, starting from\nthe largest one that is non-zero. Each unit will be joined with a comma and\nspace, except for the last one which will have \"and\" instead.\n\nFor example:\n\n`30 hours, 31 minutes and 26.4 seconds`\n\n#### No Milliseconds in output\n\nYou can observe from this example that there are no milliseconds in the\nstring! This is because I feel that adding them would not help to serve\nthe purpose of this module, which is to measure the amount of time that\ncode took to run and report it to a log or script.\n\nThis alterative _with milliseconds_:\n\n`30 hours, 31 minutes, 26 seconds and 400 milliseconds`\n\nIs about 40% longer, and contributes almost no useful information. People\nstill look at something like: `400 milliseconds` and say \"hmm that's about\nhalf a second\". In other words, leaving the milliseconds out and making them\npart of the seconds is not only shorter in your log, its actually easier for\nyou to read!\n\n#### Some Milliseconds in output\n\nYou might be thinking, \"I noticed earlier that I can access the milliseconds\nexplicitly with formattedDuration.milliseconds, why would you put that in there\nif it isn't used?\". The answer to this question is simple: it **is** used, but\nonly if the duration is exceptionally short. Specifically, if it is less than\na second.\n\nFor example a duration of 0.4 seconds or 400 milliseconds would **not** be\nprinted as `0.4 seconds`. This has the reverse [problem from above](#no-milliseconds-in-output).\nThat is, it is _too_ terse making it harder to read and understand. It is much\neasier to understand `400 milliseconds` rather than `0.4 seconds`, simply because\nwhen you get to such a short time-frame it makes more sense to think in terms of\nexplicit milliseconds.\n\nThis is likely not going to come up too often, unless you are timing very short\nsegments of code. However, just note that in these cases you **will** get\nmilliseconds. In other words, you have them when you need them!\n\n## License\n\n[MIT](https://github.com/dbpiper/timer/blob/master/LICENSE) Copyright\n© [David Piper](https://github.com/dbpiper)\n","readmeFilename":"README.md"}