generated from JS-DevTools/template-node-typescript
-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathnormalize-options.ts
47 lines (44 loc) · 1.21 KB
/
normalize-options.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
import { URL } from "url";
import { Access, Debug, Options } from "./options";
/**
* Normalized and sanitized options
* @internal
*/
export interface NormalizedOptions {
token: string;
registry: URL;
package: string;
tag: string;
access?: Access;
dryRun: boolean;
checkVersion: boolean;
greaterVersionOnly: boolean;
quiet: boolean;
debug: Debug;
}
/**
* Normalizes and sanitizes options, and fills-in any default values.
* @internal
*/
export function normalizeOptions(options: Options): NormalizedOptions {
let registryURL =
typeof options.registry === "string"
? new URL(options.registry)
: options.registry;
return {
token: options.token || "",
registry: registryURL || new URL("https://registry.npmjs.org/"),
package: options.package || "package.json",
tag: options.tag || "latest",
access: options.access,
dryRun: options.dryRun || false,
checkVersion:
options.checkVersion === undefined ? true : Boolean(options.checkVersion),
greaterVersionOnly:
options.greaterVersionOnly === undefined
? false
: Boolean(options.greaterVersionOnly),
quiet: options.quiet || false,
debug: options.debug || (() => undefined),
};
}