Registry / devops / npm-config-user-agent-parser

npm-config-user-agent-parser

JSON →
library1.0.0jsnpmunverified

This package, `npm-config-user-agent-parser`, provides a utility to parse the `process.env.npm_config_user_agent` string, which is set by both npm and Yarn. It extracts structured information including versions for `npm`, `yarn`, and `node`, as well as the operating system `platform` and processor `arch`. The current stable version is 1.0.0, indicating a mature and stable API, and its release cadence is typically infrequent, focusing on stability given its single, well-defined purpose. Key differentiators include its focused scope on this specific environment variable and its ability to normalize the potentially varied user agent strings into a consistent JSON object, simplifying programmatic access to crucial environment details for tooling and scripts.

npm install npm-config-user-agent-parser
INSTALL
IMPORT
SIG · NPM-CONFIG-USER-AG
N
npm-config-user-agent-parser
devopsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parser
import parser from 'npm-config-user-agent-parser';
import { parser } from 'npm-config-user-agent-parser';
The package exports a single function as its default. Do not use named imports.
parser
const parser = require('npm-config-user-agent-parser');
const { parser } = require('npm-config-user-agent-parser');
For CommonJS, the package's default export is directly assigned to the variable.
CLI usage
npm-config-user-agent-parser 'npm/6.1.0 node/v8.9.4 darwin x64'
The package also provides a command-line interface for direct parsing of a user agent string.

Demonstrates parsing a sample `npm_config_user_agent` string using the Node API and logging the structured output.

import parser from 'npm-config-user-agent-parser'; // Simulate the npm_config_user_agent environment variable // In a real environment, this would be `process.env.npm_config_user_agent` const userAgentString = 'yarn/1.7.0 npm/? node/v8.9.4 darwin x64'; const parsed = parser(userAgentString); console.log('Parsed User Agent:', parsed); // Example of accessing specific properties console.log('Yarn Version:', parsed.yarn ? parsed.yarn.version : 'N/A'); console.log('Node Major Version:', parsed.node ? parsed.node.major : 'N/A'); console.log('Platform:', parsed.platform);
Debug
Known issues
gotchaThe `npm_config_user_agent` environment variable is not always present or consistently formatted in all Node.js execution contexts. It's typically set by `npm` or `yarn` when running scripts.
fix
Always check for the existence of `process.env.npm_config_user_agent` before attempting to parse it, and handle cases where it might be undefined or empty.
affects: >=1.0.0
gotchaThe package returns `null` for properties like `npm` or `yarn` if they are not explicitly found or if their version is indicated as `?` in the user agent string.
fix
Implement null checks (e.g., `parsed.npm && parsed.npm.version`) when accessing potentially absent properties from the parsed object to avoid `TypeError`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: parser is not a function
Attempting to destructure a default export as a named export in an ESM context, or incorrectly importing the CommonJS module.
fix
For ESM, use `import parser from 'npm-config-user-agent-parser';`. For CommonJS, use `const parser = require('npm-config-user-agent-parser');`.
Error: Cannot find module 'npm-config-user-agent-parser'
The package has not been installed or is not resolvable in the current environment.
fix
Run `npm install npm-config-user-agent-parser` or `yarn add npm-config-user-agent-parser` in your project directory.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
npm-config-user-agent-parser — npm install npm-config-user-agent-parser · libregistry