-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor TypeScript definition to CommonJS compatible export (#12)
- Loading branch information
1 parent
4126f4c
commit a87b412
Showing
4 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
export interface Options { | ||
/** | ||
* A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag). | ||
*/ | ||
readonly version?: string; | ||
declare namespace latestVersion { | ||
interface Options { | ||
/** | ||
A semver range or [dist-tag](https://docs.npmjs.com/cli/dist-tag). | ||
*/ | ||
readonly version?: string; | ||
} | ||
} | ||
|
||
/** | ||
* Get the latest version of an npm package. | ||
*/ | ||
export default function latestVersion( | ||
packageName: string, | ||
options?: Options | ||
): Promise<string>; | ||
declare const latestVersion: { | ||
/** | ||
Get the latest version of an npm package. | ||
@example | ||
``` | ||
import latestVersion = require('latest-version'); | ||
(async () => { | ||
console.log(await latestVersion('ava')); | ||
//=> '0.18.0' | ||
console.log(await latestVersion('@sindresorhus/df')); | ||
//=> '1.0.1' | ||
// Also works with semver ranges and dist-tags | ||
console.log(await latestVersion('npm', {version: 'latest-5'})); | ||
//=> '5.5.1' | ||
})(); | ||
``` | ||
*/ | ||
(packageName: string, options?: latestVersion.Options): Promise<string>; | ||
|
||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function latestVersion( | ||
// packageName: string, | ||
// options?: latestVersion.Options | ||
// ): Promise<string>; | ||
// export = latestVersion; | ||
default: typeof latestVersion; | ||
}; | ||
|
||
export = latestVersion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {expectType} from 'tsd-check'; | ||
import latestVersion from '.'; | ||
import {expectType} from 'tsd'; | ||
import latestVersion = require('.'); | ||
|
||
expectType<Promise<string>>(latestVersion('ava')); | ||
expectType<Promise<string>>(latestVersion('npm', {version: 'latest-5'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters