JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q51432F
  • License MIT

Manipulate $PATH environment variable

Package Exports

  • path-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 (path-env) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

path-env

Manipulate $PATH-like environment variable

Requirements

  • Node.js ≥ 8.9.0

Usage

NOTE:

  • Everything is chainable.

Modifying $PATH and get its value

import {pathString} from 'path-env'

const path = pathString()
  .append(['/append/bin'])
  .prepend(['/prepend/bin'])
  .surround(['/surround/bin'])
  .get.string()

console.log(path)

This will print /surround/bin:/prepend/bin:...:/append/bin:/surround/bin in POSIX systems.

Modifying a $PATH-like and get its value

Modifying $NODE_PATH.

import {pathString} from 'path-env'

const path = pathString('NODE_PATH')
  .append(['/append/node_modules'])
  .prepend(['/prepend/node_modules'])
  .surround(['/surround/node_modules'])
  .get.string()

console.log(path)

This will print /surround/node_modules:/prepend/node_modules:...:/append/node_modules:/surround/node_modules in POSIX systems.

Modifying $PATH-like property of env object

You can also modify $PATH-like value directly from an env-like object.

Signature:

import {pathEnv} from 'path-env'

const env = pathEnv() // equivalent to `const env = pathEnv(process.env, 'PATH')`
  .path.append(['/append/bin'])
  .path.prepend(['/prepend/bin'])
  .path.surround(['/surround/bin'])
  .get.env()

console.log(env)

Result: env will looks exactly like process.env except modified PATH property.

License

MIT © Hoàng Văn Khải