-
-
Notifications
You must be signed in to change notification settings - Fork 27
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 (#34)
- Loading branch information
1 parent
c551091
commit 7b1a6b8
Showing
4 changed files
with
64 additions
and
21 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,21 +1,62 @@ | ||
declare class InvalidNameErrorClass extends Error {} | ||
|
||
declare const npmName: { | ||
/** | ||
* Check whether a package name is available (not registered) on npm. | ||
* | ||
* @param name - Name to check. | ||
* @returns Whether the given name is available. | ||
*/ | ||
Check whether a package name is available (not registered) on npm. | ||
@param name - Name to check. | ||
@returns Whether the given name is available. | ||
@example | ||
``` | ||
import npmName = require('npm-name'); | ||
(async () => { | ||
console.log(await npmName('chalk')); | ||
//=> false | ||
try { | ||
await npmName('_ABC'); | ||
} catch (error) { | ||
console.log(error.message); | ||
// Invalid package name: _ABC | ||
// - name cannot start with an underscore | ||
// - name can no longer contain capital letters | ||
} | ||
})(); | ||
``` | ||
*/ | ||
(name: string): Promise<boolean>; | ||
|
||
/** | ||
* Check whether multiple package names are available (not registered) on npm. | ||
* | ||
* @param names - Multiple names to check. | ||
* @returns A `Map` of name and status. | ||
*/ | ||
many<NameType extends string>(names: NameType[]): Promise<Map<NameType, boolean>>; | ||
}; | ||
Check whether multiple package names are available (not registered) on npm. | ||
export default npmName; | ||
@param names - Multiple names to check. | ||
@returns A `Map` of name and status. | ||
@example | ||
``` | ||
import npmName = require('npm-name'); | ||
(async () => { | ||
const result = await npmName.many(['chalk', '@sindresorhus/is', 'abc123']); | ||
console.log(result.get('chalk')); | ||
//=> false | ||
console.log(result.get('@sindresorhus/is')); | ||
//=> false | ||
console.log(result.get('abc123')); | ||
//=> true | ||
})(); | ||
``` | ||
*/ | ||
many<NameType extends string>( | ||
names: NameType[] | ||
): Promise<Map<NameType, boolean>>; | ||
|
||
InvalidNameError: typeof InvalidNameErrorClass; | ||
|
||
// TODO: remove this in the next major version | ||
default: typeof npmName; | ||
}; | ||
|
||
export class InvalidNameError extends Error {} | ||
export = npmName; |
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
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