forked from JS-DevTools/npm-publish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize-options.ts
38 lines (35 loc) · 1.03 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
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;
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),
quiet: options.quiet || false,
debug: options.debug || (() => undefined),
};
}