Skip to content

Commit

Permalink
Merge aff7724 into 7e224b9
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlup committed Nov 9, 2020
2 parents 7e224b9 + aff7724 commit 1aeef12
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 2 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [Usage](#usage)
- [API](#api)
* [hrtime2ns(time)](#hrtime2nstime)
* [hrtime2us(time)](#hrtime2ustime)
* [hrtime2ms(time)](#hrtime2mstime)
* [hrtime2s(time)](#hrtime2stime)

Expand All @@ -30,19 +31,22 @@ $ npm i @dnlup/hrtime-utils
```js
const {
hrtime2ns,
hrtime2us,
hrtime2ms,
hrtime2
} = require('@dnlup/hrtime-utils')
const time = process.hrtime()
hrtime2ns(time) // time in nanoseconds
hrtime2us(time) // time in microseconds
hrtime2ms(time) // time in milliseconds
hrtime2s(time) // time in seconds
const delta = process.hrtime(time)
hrtime2ns(delta) // delta in nanoseconds
hrtime2us(delta) // delta in microseconds
hrtime2ms(delta) // delta in milliseconds
hrtime2s(delta) // delta in seconds
```
Expand All @@ -57,6 +61,14 @@ hrtime2s(delta) // delta in seconds

This function converts `time` to nanoseconds.

### hrtime2us(time)

* `time` `<integer[]`> The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call

* Returns `<number>`

This function converts `time` to microseconds.

### hrtime2ms(time)

* `time` `<integer[]`> The return value of a [`process.hrtime()`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_process_hrtime_time) call
Expand Down
5 changes: 5 additions & 0 deletions husky.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
hooks: {
'pre-commit': 'npm test'
}
}
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ exports.hrtime2ns = function (time) {
return time[0] * 1e9 + time[1]
}

exports.hrtime2us = function (time) {
return time[0] * 1e6 + time[1] / 1e3
}

exports.hrtime2ms = function (time) {
return time[0] * 1e3 + time[1] / 1e6
}
Expand Down
228 changes: 227 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"lint": "standard | snazzy",
"test": "npm run lint && tap test.js --100",
"test": "npm run lint && tap test.js",
"test:ci": "npm run test -- --cov --coverage-report=lcovonly",
"doc": "markdown-toc -i README.md",
"prerelease": "npm cit",
Expand Down Expand Up @@ -35,6 +35,7 @@
"homepage": "https://github.com/dnlup/hrtime-utils#readme",
"devDependencies": {
"atomic-sleep": "^1.0.0",
"husky": "^4.3.0",
"markdown-toc": "^1.2.0",
"snazzy": "^9.0.0",
"standard": "^16.0.0",
Expand Down
Loading

0 comments on commit 1aeef12

Please sign in to comment.