Skip to content

Commit

Permalink
Add browser support (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
Richienb and sindresorhus committed Jun 26, 2022
1 parent d85de23 commit dc45287
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions browser.js
@@ -0,0 +1,10 @@
export default function timeSpan() {
const start = performance.now();

const end = () => performance.now() - start;
end.rounded = () => Math.round(end());
end.seconds = () => end() / 1000;
end.nanoseconds = () => end() * 1000000;

return end;
}
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -11,7 +11,11 @@
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"exports": {
"types": "./index.d.ts",
"node": "./index.js",
"default": "./browser.js"
},
"engines": {
"node": ">=12"
},
Expand All @@ -20,6 +24,7 @@
},
"files": [
"index.js",
"browser.js",
"index.d.ts"
],
"keywords": [
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -2,6 +2,8 @@

> Simplified high resolution timing
Uses [`process.hrtime`](https://nodejs.org/api/process.html#processhrtimebigint) in Node.js and [`performance.now`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) in browsers ([accurate to 5 microseconds](https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp)).

## Install

```
Expand Down

0 comments on commit dc45287

Please sign in to comment.