0.4.9 • Published 7 years ago

npm-package-env v0.4.9

Weekly downloads
35
License
MIT
Repository
github
Last release
7 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

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.1

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago