-
-
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.
- Loading branch information
1 parent
8a86ee6
commit 59517d7
Showing
8 changed files
with
140 additions
and
158 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,88 +1,74 @@ | ||
declare class InvalidNameErrorClass extends Error {} | ||
export class InvalidNameError extends Error {} | ||
|
||
declare namespace npmName { | ||
interface Options { | ||
/** | ||
Registry URL to check name availability against. | ||
Default: User's configured npm registry URL. | ||
*/ | ||
readonly registryUrl: string; | ||
} | ||
} | ||
|
||
declare const npmName: { | ||
export interface Options { | ||
/** | ||
Check whether a package/organization name is available (not registered) on npm. | ||
Registry URL to check name availability against. | ||
An organization name should start with `@` and should not be a scoped package. | ||
@param name - Name to check. | ||
@returns Whether the given name is available. | ||
@example | ||
``` | ||
import npmName = require('npm-name'); | ||
Default: User's configured npm registry URL. | ||
*/ | ||
readonly registryUrl: string; | ||
} | ||
|
||
(async () => { | ||
// Check a package name | ||
console.log(await npmName('chalk')); | ||
//=> false | ||
/** | ||
Check whether a package/organization name is available (not registered) on npm. | ||
An organization name should start with `@` and should not be a scoped package. | ||
// Check an organization name | ||
console.log(await npmName('@ava')); | ||
//=> false | ||
@param name - Name to check. | ||
@returns Whether the given name is available. | ||
console.log(await npmName('@abc123')); | ||
//=> true | ||
@example | ||
``` | ||
import npmName from 'npm-name'; | ||
// Check a package name | ||
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, options?: npmName.Options): Promise<boolean>; | ||
// Check an organization name | ||
console.log(await npmName('@ava')); | ||
//=> false | ||
/** | ||
Check whether multiple package/organization names are available (not registered) on npm. | ||
console.log(await npmName('@abc123')); | ||
//=> true | ||
An organization name should start with `@` and should not be a scoped package. | ||
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 | ||
} | ||
``` | ||
*/ | ||
export default function npmName(name: string, options?: Options): Promise<boolean>; | ||
|
||
@param names - Multiple names to check. | ||
@returns A `Map` of name and status. | ||
/** | ||
Check whether multiple package/organization names are available (not registered) on npm. | ||
@example | ||
``` | ||
import npmName = require('npm-name'); | ||
An organization name should start with `@` and should not be a scoped package. | ||
(async () => { | ||
const result = await npmName.many(['chalk', '@sindresorhus/is', 'abc123']); | ||
@param names - Multiple names to check. | ||
@returns A `Map` of name and status. | ||
console.log(result.get('chalk')); | ||
//=> false | ||
@example | ||
``` | ||
import {npmNameMany} from 'npm-name'; | ||
console.log(result.get('@sindresorhus/is')); | ||
//=> false | ||
const result = await npmNameMany(['chalk', '@sindresorhus/is', 'abc123']); | ||
console.log(result.get('abc123')); | ||
//=> true | ||
})(); | ||
``` | ||
*/ | ||
many<NameType extends string>( | ||
names: NameType[], | ||
options?: npmName.Options | ||
): Promise<Map<NameType, boolean>>; | ||
console.log(result.get('chalk')); | ||
//=> false | ||
InvalidNameError: typeof InvalidNameErrorClass; | ||
}; | ||
console.log(result.get('@sindresorhus/is')); | ||
//=> false | ||
export = npmName; | ||
console.log(result.get('abc123')); | ||
//=> true | ||
``` | ||
*/ | ||
export function npmNameMany<NameType extends string>( | ||
names: readonly NameType[], | ||
options?: Options | ||
): Promise<Map<NameType, boolean>>; |
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,16 +1,15 @@ | ||
import {expectType} from 'tsd'; | ||
import npmName = require('.'); | ||
import {InvalidNameError} from '.'; | ||
import npmName, {npmNameMany, InvalidNameError} from './index.js'; | ||
|
||
expectType<Promise<boolean>>(npmName('chalk')); | ||
expectType<Promise<boolean>>(npmName('got', { | ||
registryUrl: 'https://registry.yarnpkg.com/' | ||
})); | ||
|
||
const manyResult = npmName.many(['chalk', '@sindresorhus/is', 'abc123']); | ||
const manyResult = npmNameMany(['chalk', '@sindresorhus/is', 'abc123']); | ||
expectType<Promise<Map<'chalk' | '@sindresorhus/is' | 'abc123', boolean>>>( | ||
manyResult | ||
); | ||
expectType<boolean | undefined>((await manyResult).get('chalk')); | ||
|
||
new InvalidNameError('foo') instanceof InvalidNameError; | ||
expectType<InvalidNameError>(new InvalidNameError('foo')); |
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
Oops, something went wrong.