Comparing version 3.1.1 to 4.0.0
@@ -1,40 +0,31 @@ | ||
/// <reference types="node" /> | ||
export interface Options { | ||
/** | ||
Use a custom environment variables object. | ||
declare namespace pathKey { | ||
interface Options { | ||
/** | ||
Use a custom environment variables object. Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env). | ||
*/ | ||
readonly env?: {[key: string]: string | undefined}; | ||
Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env). | ||
*/ | ||
readonly env?: Record<string, string | undefined>; | ||
/** | ||
Get the PATH key for a specific platform. Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform). | ||
*/ | ||
readonly platform?: NodeJS.Platform; | ||
} | ||
} | ||
declare const pathKey: { | ||
/** | ||
Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform. | ||
Get the PATH key for a specific platform. | ||
@example | ||
``` | ||
import pathKey = require('path-key'); | ||
Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform). | ||
*/ | ||
readonly platform?: NodeJS.Platform; | ||
} | ||
const key = pathKey(); | ||
//=> 'PATH' | ||
/** | ||
Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform. | ||
const PATH = process.env[key]; | ||
//=> '/usr/local/bin:/usr/bin:/bin' | ||
``` | ||
*/ | ||
(options?: pathKey.Options): string; | ||
@example | ||
``` | ||
import pathKey from 'path-key'; | ||
// TODO: Remove this for the next major release, refactor the whole definition to: | ||
// declare function pathKey(options?: pathKey.Options): string; | ||
// export = pathKey; | ||
default: typeof pathKey; | ||
}; | ||
const key = pathKey(); | ||
//=> 'PATH' | ||
export = pathKey; | ||
const PATH = process.env[key]; | ||
//=> '/usr/local/bin:/usr/bin:/bin' | ||
``` | ||
*/ | ||
export default function pathKey(options?: Options): string; |
18
index.js
@@ -1,7 +0,7 @@ | ||
'use strict'; | ||
export default function pathKey(options = {}) { | ||
const { | ||
env = process.env, | ||
platform = process.platform | ||
} = options; | ||
const pathKey = (options = {}) => { | ||
const environment = options.env || process.env; | ||
const platform = options.platform || process.platform; | ||
if (platform !== 'win32') { | ||
@@ -11,7 +11,3 @@ return 'PATH'; | ||
return Object.keys(environment).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path'; | ||
}; | ||
module.exports = pathKey; | ||
// TODO: Remove this for the next major release | ||
module.exports.default = pathKey; | ||
return Object.keys(env).reverse().find(key => key.toUpperCase() === 'PATH') || 'Path'; | ||
} |
{ | ||
"name": "path-key", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "Get the PATH environment variable key cross-platform", | ||
"license": "MIT", | ||
"repository": "sindresorhus/path-key", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=12" | ||
}, | ||
@@ -28,3 +31,2 @@ "scripts": { | ||
"variable", | ||
"var", | ||
"get", | ||
@@ -35,7 +37,7 @@ "cross-platform", | ||
"devDependencies": { | ||
"@types/node": "^11.13.0", | ||
"ava": "^1.4.1", | ||
"tsd": "^0.7.2", | ||
"xo": "^0.24.0" | ||
"@types/node": "^14.14.37", | ||
"ava": "^3.15.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
} | ||
} |
@@ -1,8 +0,7 @@ | ||
# path-key [![Build Status](https://travis-ci.org/sindresorhus/path-key.svg?branch=master)](https://travis-ci.org/sindresorhus/path-key) | ||
# path-key | ||
> Get the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable key cross-platform | ||
It's usually `PATH`, but on Windows it can be any casing like `Path`... | ||
It's usually `PATH` but on Windows it can be any casing like `Path`... | ||
## Install | ||
@@ -14,7 +13,6 @@ | ||
## Usage | ||
```js | ||
const pathKey = require('path-key'); | ||
import pathKey from 'path-key'; | ||
@@ -28,3 +26,2 @@ const key = pathKey(); | ||
## API | ||
@@ -40,3 +37,3 @@ | ||
Type: `object`<br> | ||
Type: `object`\ | ||
Default: [`process.env`](https://nodejs.org/api/process.html#process_process_env) | ||
@@ -48,3 +45,3 @@ | ||
Type: `string`<br> | ||
Type: `string`\ | ||
Default: [`process.platform`](https://nodejs.org/api/process.html#process_process_platform) | ||
@@ -54,3 +51,2 @@ | ||
--- | ||
@@ -57,0 +53,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
4069
34
58