-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.d.ts
88 lines (66 loc) · 1.84 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
declare class InvalidNameErrorClass 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: {
/**
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 - Name to check.
@returns Whether the given name is available.
@example
```
import npmName = require('npm-name');
(async () => {
// 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
}
})();
```
*/
(name: string, options?: npmName.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 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[],
options?: npmName.Options
): Promise<Map<NameType, boolean>>;
InvalidNameError: typeof InvalidNameErrorClass;
};
export = npmName;