-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.d.ts
74 lines (56 loc) · 1.64 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
export class InvalidNameError extends Error {}
export type Options = {
/**
The registry URL to check name availability against.
Default: User's configured npm registry URL.
*/
readonly registryUrl: string;
};
/**
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.
@param name - The name to check.
@returns Whether the given name is available.
@example
```
import npmName from 'npm-name';
// Check a package name
console.log(await npmName('chalk'));
//=> false
// Check an organization name
console.log(await npmName('@ava'));
//=> false
console.log(await npmName('@abc123'));
//=> true
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>;
/**
Check whether multiple package/organization names are available (not registered) on npm.
An organization name should start with `@` and should not be a scoped package.
@param names - Multiple names to check.
@returns A `Map` of name and status.
@example
```
import {npmNameMany} from 'npm-name';
const result = await npmNameMany(['chalk', '@sindresorhus/is', 'abc123']);
console.log(result.get('chalk'));
//=> false
console.log(result.get('@sindresorhus/is'));
//=> false
console.log(result.get('abc123'));
//=> true
```
*/
export function npmNameMany<NameType extends string>(
names: readonly NameType[],
options?: Options
): Promise<Map<NameType, boolean>>;