{"name":"timer-node","version":"5.0.9","description":"A timestamp-based timer that enables recording elapsed time and formatting the result.","main":"index.js","scripts":{"test":"grunt test"},"repository":{"type":"git","url":"git+https://github.com/eyas-ranjous/timer-node.git"},"keywords":["timer","timer.js","node timer","js timer"],"author":{"name":"Eyas Ranjous","email":"https://github.com/eyas-ranjous"},"license":"MIT","bugs":{"url":"https://github.com/eyas-ranjous/timer-node/issues"},"homepage":"https://github.com/eyas-ranjous/timer-node#readme","devDependencies":{"chai":"^4.2.0","eslint":"^6.7.2","eslint-config-airbnb-base":"^14.0.0","eslint-plugin-import":"^2.19.1","grunt":"^1.0.4","grunt-eslint":"^22.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-mocha-test":"^0.13.3","istanbul":"^0.4.5","mocha":"^6.2.2","sinon":"^9.0.2"},"_id":"timer-node@5.0.9","gitHead":"739c1c030fb05a0f147d54cc514c7665f11b7452","types":"./index.d.ts","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-zXxCE/5/YDi0hY9pygqgRqjRbrFRzigYxOudG0I3syaqAAmX9/w9sxex1bNFCN6c1S66RwPtEIJv65dN+1psew==","shasum":"b5e2781c6ce415a7e35053144265699668076267","tarball":"http://registry-npm.ywwl.com/timer-node/download/timer-node-5.0.9.tgz","fileCount":8,"unpackedSize":15900,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDVWUqVIYKHqZaTHermK5Y49wuPt9M0ZXZ/zmFwUkh6MAiBzyAsLcJ4AUi4+p3GkDL7qmHQKTRi38/OeAOR+mQe8ug=="}],"size":5279,"noattachment":false,"key":"/timer-node/-/timer-node-5.0.9.tgz"},"_npmUser":{"name":"eyas-ranjous","email":"eyas.ranjous@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/timer-node_5.0.9_1737883058881_0.3562399955718887"},"_hasShrinkwrap":false,"readme":"# timer-node\n\n[![npm](https://img.shields.io/npm/v/timer-node.svg)](https://www.npmjs.com/package/timer-node)\n[![npm](https://img.shields.io/npm/dm/timer-node.svg)](https://www.npmjs.com/package/timer-node)\n\nA **lightweight** JavaScript library for measuring elapsed time in Node.js or the browser without using `setInterval` or `setTimeout`. It also has type definitions for TypeScript.\n\n## Installation\n\n```bash\nnpm install timer-node\n```\n\n## API\n### Import\n\n```javascript\n// JS\nconst { Timer } = require('timer-node');\n\n// TS\nimport { Timer, TimerOptions, Time } from 'timer-node';\n```\n\n### Timer Class\n\nA timestamp-based timer that can be started, paused, resumed, and stopped. It calculates durations based on system time.\n\n#### Constructor\n\n```ts\nnew Timer(options?: TimerOptions)\n```\n\n- `options`: An optional configuration object with:\n  - `label?: string` – A label for this timer.\n  - `startTimestamp?: number` – Start time (if you want to initialize from the past).\n  - `endTimestamp?: number` – End time (if already stopped).\n  - `currentStartTimestamp?: number` – Most recent resume time.\n  - `pauseCount?: number` – Number of times paused.\n  - `accumulatedMs?: number` – Accumulated milliseconds from previous runs.\n\n#### Common Methods\n\n- **start()**: Starts (or restarts) the timer.\n- **pause()**: Pauses the timer (if running).\n- **resume()**: Resumes the timer (if paused).\n- **stop()**: Stops the timer.\n- **clear()**: Clears all timer data, resetting it to an unstarted state.\n- **isStarted() / isPaused() / isRunning() / isStopped()**: Check the timer state.\n- **ms()**: Returns the elapsed time in milliseconds.\n- **time()**: Returns an object of time fractions (`d`, `h`, `m`, `s`, `ms`).\n- **pauseMs() / pauseTime()**: Similar to `ms()` / `time()`, but for paused duration.\n- **pauseCount()**: Returns how many times the timer has been paused.\n- **format(template?: string)**: Formats the elapsed time using placeholders (`%label`, `%d`, `%h`, `%m`, `%s`, `%ms`).\n- **serialize()**: Returns a JSON string representing the timer state.\n\n#### Static Methods\n\n- **Timer.deserialize(serializedTimer: string): Timer**\\\n  Re-creates a timer from a serialized string generated by `.serialize()`.\n\n- **Timer.benchmark(fn: () => any): Timer**\\\n  Measures the synchronous execution time of `fn`. Returns a stopped `Timer`.\n\n---\n\n### Time Object\n\nAny method returning an object breakdown of time uses the following shape:\n\n```ts\ninterface Time {\n  d: number;  // days\n  h: number;  // hours\n  m: number;  // minutes\n  s: number;  // seconds\n  ms: number; // milliseconds\n}\n```\n\n## Example\n\n```js\nconst { Timer } = require('timer-node');\n\nconst timer = new Timer({ label: 'demo' });\ntimer.start();\n\n// ... some operations ...\n\ntimer.pause();\nconsole.log('Paused at', timer.ms(), 'ms');\ntimer.resume();\n\n// ... more operations ...\n\ntimer.stop();\nconsole.log('Total elapsed:', timer.time());\n// e.g. { d: 0, h: 0, m: 1, s: 12, ms: 345 }\n```\n\n## License\n\nThis library is licensed under the MIT License. See [LICENSE](https://github.com/eyas-ranjous/timer-node/blob/master/LICENSE) for details.\n\n","publish_time":1737883059034,"maintainers":[{"name":"eyas-ranjous","email":"eyas.ranjous@gmail.com"}],"_cnpm_publish_time":1737883059034,"dist-tags":{"latest":"5.0.9"}}