NPM.Token (NPM v0.6.0)

Copy Markdown View Source

Manages npm authentication tokens.

Handles reading, validating, and masking auth tokens used for private registry access.

Summary

Functions

Returns the auth header value for the given token.

Checks if a valid auth token is configured.

Masks a token for safe display.

Reads token from an .npmrc file content.

Reads the auth token from environment or .npmrc.

Validates token format.

Functions

auth_header(token)

@spec auth_header(String.t()) :: String.t()

Returns the auth header value for the given token.

configured?()

@spec configured?() :: boolean()

Checks if a valid auth token is configured.

mask(token)

@spec mask(String.t()) :: String.t()

Masks a token for safe display.

Shows only the first and last 4 characters.

parse_npmrc(content)

@spec parse_npmrc(String.t()) :: String.t() | nil

Reads token from an .npmrc file content.

read()

@spec read() :: String.t() | nil

Reads the auth token from environment or .npmrc.

valid_format?(token)

@spec valid_format?(String.t()) :: boolean()

Validates token format.

npm tokens are typically UUIDs or base64-encoded strings.