Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor TypeScript definition to CommonJS compatible export (#14)
- Loading branch information
1 parent
4b2e926
commit b8634b0
Showing
3 changed files
with
43 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,36 @@ | ||
export interface EnvironmentVariables { | ||
readonly [key: string]: string; | ||
declare namespace shellEnv { | ||
interface EnvironmentVariables { | ||
readonly [key: string]: string; | ||
} | ||
} | ||
|
||
/** | ||
* Get the environment variables defined in your dotfiles. | ||
* | ||
* @param shell - The shell to read environment variables from. Default: User default shell. | ||
* @returns The environment variables. | ||
*/ | ||
export function sync(shell?: string): EnvironmentVariables; | ||
|
||
/** | ||
* Get the environment variables defined in your dotfiles. | ||
* | ||
* @param shell - The shell to read environment variables from. Default: User default shell. | ||
* @returns The environment variables. | ||
*/ | ||
export default function shellEnv(shell?: string): Promise<EnvironmentVariables>; | ||
declare const shellEnv: { | ||
/** | ||
Get the environment variables defined in your dotfiles. | ||
@param shell - The shell to read environment variables from. Default: User default shell. | ||
@returns The environment variables. | ||
@example | ||
``` | ||
import shellEnv = require('shell-env'); | ||
console.log(shellEnv.sync()); | ||
//=> {TERM_PROGRAM: 'Apple_Terminal', SHELL: '/bin/zsh', ...} | ||
console.log(shellEnv.sync('/bin/bash')); | ||
//=> {TERM_PROGRAM: 'iTerm.app', SHELL: '/bin/zsh', ...} | ||
``` | ||
*/ | ||
(shell?: string): Promise<shellEnv.EnvironmentVariables>; | ||
|
||
/** | ||
Get the environment variables defined in your dotfiles. | ||
@param shell - The shell to read environment variables from. Default: User default shell. | ||
@returns The environment variables. | ||
*/ | ||
sync(shell?: string): shellEnv.EnvironmentVariables; | ||
}; | ||
|
||
export = shellEnv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {expectType} from 'tsd-check'; | ||
import shellEnv, {sync, EnvironmentVariables} from '.'; | ||
import {expectType} from 'tsd'; | ||
import shellEnv = require('.'); | ||
import {EnvironmentVariables} from '.'; | ||
|
||
expectType<EnvironmentVariables>(sync()); | ||
expectType<EnvironmentVariables>(await shellEnv()); | ||
expectType<EnvironmentVariables>(shellEnv.sync()); | ||
expectType<Promise<EnvironmentVariables>>(shellEnv()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters