@common.js/time-span 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @common.js/time-span
2
+
3
+ The [time-span](https://www.npmjs.com/package/time-span) package exported as CommonJS modules.
4
+
5
+ Exported from [time-span@5.1.0](https://www.npmjs.com/package/time-span/v/5.1.0) using https://github.com/etienne-martin/common.js.
package/browser.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return timeSpan;
9
+ }
10
+ });
11
+ function timeSpan() {
12
+ var start = performance.now();
13
+ var end = function() {
14
+ return performance.now() - start;
15
+ };
16
+ end.rounded = function() {
17
+ return Math.round(end());
18
+ };
19
+ end.seconds = function() {
20
+ return end() / 1000;
21
+ };
22
+ end.nanoseconds = function() {
23
+ return end() * 1000000;
24
+ };
25
+ return end;
26
+ }
package/index.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ export interface TimeEndFunction {
2
+ /**
3
+ @returns Elapsed milliseconds.
4
+ */
5
+ (): number;
6
+
7
+ /**
8
+ @returns Elapsed milliseconds rounded.
9
+ */
10
+ rounded(): number;
11
+
12
+ /**
13
+ @returns Elapsed seconds.
14
+ */
15
+ seconds(): number;
16
+
17
+ /**
18
+ @returns Elapsed nanoseconds.
19
+ */
20
+ nanoseconds(): bigint;
21
+ }
22
+
23
+ /**
24
+ Simplified high resolution timing.
25
+
26
+ @returns A function that returns the time difference.
27
+
28
+ @example
29
+ ```
30
+ import timeSpan from 'time-span';
31
+
32
+ const end = timeSpan();
33
+
34
+ timeConsumingFn();
35
+
36
+ console.log(end());
37
+ //=> 1745.3186
38
+
39
+ console.log(end.rounded());
40
+ //=> 1745
41
+
42
+ console.log(end.seconds());
43
+ //=> 1.7453186
44
+ ```
45
+ */
46
+ export default function timeSpan(): TimeEndFunction;
package/index.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return timeSpan;
9
+ }
10
+ });
11
+ var _convertHrtime = /*#__PURE__*/ _interopRequireDefault(require("convert-hrtime"));
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ function timeSpan() {
18
+ var start = process.hrtime.bigint();
19
+ var end = function(type) {
20
+ return (0, _convertHrtime.default)(process.hrtime.bigint() - start)[type];
21
+ };
22
+ var returnValue = function() {
23
+ return end("milliseconds");
24
+ };
25
+ returnValue.rounded = function() {
26
+ return Math.round(end("milliseconds"));
27
+ };
28
+ returnValue.seconds = function() {
29
+ return end("seconds");
30
+ };
31
+ returnValue.nanoseconds = function() {
32
+ return end("nanoseconds");
33
+ };
34
+ return returnValue;
35
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@common.js/time-span",
3
+ "version": "5.1.0",
4
+ "description": "Simplified high resolution timing",
5
+ "license": "MIT",
6
+ "repository": "etienne-martin/common.js",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "type": "commonjs",
9
+ "engines": {
10
+ "node": ">=12"
11
+ },
12
+ "scripts": {
13
+ "test": "xo && ava && tsd"
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "browser.js",
18
+ "index.d.ts"
19
+ ],
20
+ "dependencies": {
21
+ "@common.js/convert-hrtime": "^5.0.0"
22
+ },
23
+ "devDependencies": {
24
+ "ava": "^3.15.0",
25
+ "delay": "^5.0.0",
26
+ "in-range": "^3.0.0",
27
+ "tsd": "^0.14.0",
28
+ "xo": "^0.38.2"
29
+ },
30
+ "homepage": "https://github.com/etienne-martin/common.js#readme",
31
+ "types": "./index.d.ts",
32
+ "main": "./index.js",
33
+ "browser": "./browser.js"
34
+ }
package/readme.md ADDED
@@ -0,0 +1,52 @@
1
+ # time-span
2
+
3
+ > Simplified high resolution timing
4
+
5
+ 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)).
6
+
7
+ ## Install
8
+
9
+ ```
10
+ $ npm install time-span
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ import timeSpan from 'time-span';
17
+
18
+ const end = timeSpan();
19
+
20
+ timeConsumingFn();
21
+
22
+ console.log(end());
23
+ //=> 1745.3186
24
+
25
+ console.log(end.rounded());
26
+ //=> 1745
27
+
28
+ console.log(end.seconds());
29
+ //=> 1.7453186
30
+ ```
31
+
32
+ ## API
33
+
34
+ ### `const end = timeSpan()`
35
+
36
+ Returns a function, that when called, returns the time difference.
37
+
38
+ #### end()
39
+
40
+ Elapsed milliseconds.
41
+
42
+ #### end.rounded()
43
+
44
+ Elapsed milliseconds rounded.
45
+
46
+ #### end.seconds()
47
+
48
+ Elapsed seconds.
49
+
50
+ #### end.nanoseconds()
51
+
52
+ Elapsed nanoseconds.