Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 5, 2019
1 parent a2644fd commit e32811a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 28 deletions.
75 changes: 52 additions & 23 deletions index.d.ts
@@ -1,28 +1,57 @@
/**
* @returns Elapsed milliseconds.
*/
export interface TimeEndFunction {
(): number;
declare namespace timeSpan {
interface TimeEndFunction {
/**
@returns Elapsed milliseconds.
*/
(): number;

/**
* @returns Elapsed milliseconds rounded.
*/
rounded(): number;
/**
@returns Elapsed milliseconds rounded.
*/
rounded(): number;

/**
* @returns Elapsed seconds.
*/
seconds(): number;
/**
@returns Elapsed seconds.
*/
seconds(): number;

/**
* @returns Elapsed nanoseconds.
*/
nanoseconds(): number;
/**
@returns Elapsed nanoseconds.
*/
nanoseconds(): number;
}
}

/**
* Simplified high resolution timing.
*
* @returns A function that returns the time difference.
*/
export default function timeSpan(): TimeEndFunction;
declare const timeSpan: {
/**
Simplified high resolution timing.
@returns A function that returns the time difference.
@example
```
import timeSpan = require('time-span');
const end = timeSpan();
timeConsumingFn();
console.log(end());
//=> 1745.3186
console.log(end.rounded());
//=> 1745
console.log(end.seconds());
//=> 1.7453186
```
*/
(): timeSpan.TimeEndFunction;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function timeSpan(): timeSpan.TimeEndFunction;
// export = timeSpan;
default: typeof timeSpan;
};

export = timeSpan;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -14,4 +14,5 @@ const timeSpan = () => {
};

module.exports = timeSpan;
// TODO: Remove this for the next major release
module.exports.default = timeSpan;
4 changes: 2 additions & 2 deletions index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd-check';
import timeSpan from '.';
import {expectType} from 'tsd';
import timeSpan = require('.');

const end = timeSpan();

Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=6"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -41,10 +41,10 @@
"convert-hrtime": "^2.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"delay": "^4.1.0",
"in-range": "^1.0.0",
"tsd-check": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

0 comments on commit e32811a

Please sign in to comment.