Skip to content

Commit

Permalink
Refactor TypeScript definition to CommonJS compatible export (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
BendingBender authored and sindresorhus committed Apr 4, 2019
1 parent 595ce71 commit e2ac983
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 11 deletions.
39 changes: 33 additions & 6 deletions index.d.ts
@@ -1,6 +1,33 @@
/**
* Get the set npm registry URL.
*
* @param scope - Retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry.
*/
export default function registryUrl(scope?: string): string;
declare const registryUrl: {
/**
Get the set npm registry URL.
@param scope - Retrieve the registry URL associated with an [npm scope](https://docs.npmjs.com/misc/scope). If the provided scope is not in the user's `.npmrc` file, then `registry-url` will check for the existence of `registry`, or if that's not set, fallback to the default npm registry.
@example
```
import registryUrl = require('registry-url');
// # .npmrc
// registry = 'https://custom-registry.com/'
console.log(registryUrl());
//=> 'https://custom-registry.com/'
// # .npmrc
// @myco:registry = 'https://custom-registry.com/'
console.log(registryUrl('@myco'));
//=> 'https://custom-registry.com/'
```
*/
(scope?: string): string;

// TODO: Remove this for the next major release, refactor the whole definition to:
// declare function registryUrl(scope?: string): string;
// export = registryUrl;
default: typeof registryUrl;
};

export = registryUrl;
1 change: 1 addition & 0 deletions index.js
Expand Up @@ -8,4 +8,5 @@ const registryUrl = scope => {
};

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

expectType<string>(registryUrl());
expectType<string>(registryUrl('@myco'));
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -13,7 +13,7 @@
"node": ">=8"
},
"scripts": {
"test": "xo && ava && tsd-check"
"test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand All @@ -33,9 +33,9 @@
"rc": "^1.2.8"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^1.4.1",
"import-fresh": "^3.0.0",
"tsd-check": "^0.3.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"ava": {
Expand Down

0 comments on commit e2ac983

Please sign in to comment.