npm-config-info
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

NPM CONFIG INFO

Build Status Coverage Status codecov npm npm

Get the config information stored by npm. This include the stored user details and folder information of the npm structure. Refer to change Logs for latest changes on the current version.

Install

    npm install npm-config-info

Usage

const configInfo = require("npm-config-info").getConfigSync();
 
let config = configInfo.config;
let user = configInfo.author.name;
let email = configInfo.author.email;
let npmFolder = configInfo.folders.prefix;

The code could also run asynchronously:

let configInfo;
 
require("npm-config-info")
    .getConfig()
    .then(conf => {
        configInfo = conf;
    });

Global Store

Please note that the global values could also be obtained by calling getGlobal() from the returned object.

We will attempt to figure out where the npmrc file resides.

A string variable of where the global npmrc file could be found could also be provided in getGlobal e.g.:

const { configInfo, globState } = require("npm-config-info");
 
let config = configInfo.getConfigSync();
let globalAuthor;
 
configInfo.getGlobal("/custom/destination/to/npmrc");
 
if (configInfo.globalState === globState.Initialized) {
    globalAuthor = configInfo.global.author;
}
 
// OR
if (
    configInfo.globalState !== globState.NotFound &&
    configInfo.globalState !== globState.NotInitialized
) {
    globalAuthor = configInfo.global.author;
}

The global variables can also be created by the constructor:

PLEASE NOTE: although the state could be found on the global object (for now and if global has not been initialized or found). The correct state checking should happen through globalState property

const configInfo = require("npm-conif-info").getConfigSync(true);
console.loe(configInfo.globalExist);

NPMRC

Please have a look at npm of how the data is usually resolved.

Contributions

Contributions are welcome. This was a quick project as I required an easy way to access the stored author creditials from javascript.

Change Log

  • Fixed Readme spelling errors.
  • Added a globalState variable to ConfigInfo (we should have done so from the start). For the moment global will still be an object or the value of globalState if no object could be found. String value on global property is preserved for now, but should not be used. For checking use globalState variable. State on "global" will be removed in future.
  • Added an "enum" globaState to both index.js and ConfInfo.js.

0.1.1

  • Fixing intelisense (d.ts) file for the enum globState.

Package Sidebar

Install

npm i npm-config-info

Weekly Downloads

3

Version

0.1.1

License

Apache-2.0

Unpacked Size

25.8 kB

Total Files

5

Last publish

Collaborators

  • daclan008