0.4.9 • Published 8 years ago

npm-package-env v0.4.9

Weekly downloads
35
License
MIT
Repository
github
Last release
8 years ago

npm-package-env

conveniently use npm_package_ variables using property accessors

NPM

installation

npm i npm-package-env -S

overview

provides easy access to per-package config settings (or package variables) via a virtual object.

API

.<property> / [<'property-name'>] (property accessors)

get

retrieves the current value or walks deeper into the npm_package_ tree. equivalent to stating the full variable path in process.env.npm_package_<var_path>.

Returns: {String|I} the current value, if exists, or a chainable object, bound to the new namespace.

set

sets a new value in the specified namespace, coerced to a string. equivalent to assigning a variable value to process.env.npm_package_<var_path>.

examples

all examples assume npm-script.js is run via npm run, i.e. the package.json has something like this:

"scripts": {
    "start": "npm-script"
}

getting / setting a value

npm-script.js
const npmEnv = require('npm-package-env');
npmEnv.config['dev-server'].port; // -> '7777'
npmEnv.config['dev-server'].port = 9999;
npmEnv.config['dev-server'].port; // -> '9999'
package.json
"config": {
    "dev-server": {
        "port": 7777
    }
}

getting / setting a value inside an array

npm-script.js
const npmEnv = require('npm-package-env');
npmEnv.keywords[1]; // -> 'bar'
npmEnv.keywords[1] = 'wow';
npmEnv.keywords[1]; // -> 'wow'
package.json
"keywords": [
    "foo", "bar", "wat"
]

getting / setting a value inside an object

npm-script.js
const npmEnv = require('npm-package-env');
npmEnv.dependencies['auto-exports']; // -> '14.1.3'
npmEnv.dependencies['auto-exports'] = '~2.0.1';
npmEnv.dependencies['auto-exports']; // -> '~2.0.1'
package.json
"dependencies": {
    "auto-exports": "14.1.3",
    "npm-package-env": "^2.0.21"
}
0.4.9

8 years ago

0.4.7

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.1

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago