Package Exports
- npm-package-env
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (npm-package-env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
npm-package-env
conveniently get
npm_package_
variables using property accessors
installation
npm i npm-package-env -S
examples
all examples assume my-npm-script.js
is run via npm run
, i.e. the
package.json
has something like this:
"scripts": {
"start": "my-npm-script"
}
getting a string
this also demonstrates using both dot and bracket notation for property access.
my-npm-script.js
const npmEnv = require('npm-package-env')._in('npm_package_config');
npmEnv['dev-server'].port._as('string'); // -> '7777'
package.json
"config": {
"dev-server": {
"port": 7777
}
}
getting an array
my-npm-script.js
const npmEnv = require('npm-package-env')._in('npm_package');
npmEnv.keywords._as('array'); // -> ['foo', 'bar', 'wat']
npmEnv.keywords._as('array')[1]; // -> 'bar'
package.json
"keywords": [
"foo", "bar", "wat"
]
getting an object by keys
my-npm-script.js
const npmEnv = require('npm-package-env')._in('npm_package');
npmEnv.dependencies._as('object', ['auto-exports']); // -> {'auto-exports': '14.1.3'}
package.json
"dependencies": {
"auto-exports": "14.1.3",
"npm-package-env": "^2.0.21"
}