-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
31 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import isFunction from './isFunction' | ||
|
||
let isInNode: boolean | undefined | ||
|
||
/** | ||
* 检查是否在 Node 环境中。 | ||
* | ||
* @param [callback] 在 Node 环境中执行的回调 | ||
* @returns 是(true)或否(false) | ||
*/ | ||
export default function inNode(callback?: () => void): boolean { | ||
if (isInNode === undefined) { | ||
isInNode = typeof process !== 'undefined' && | ||
process.versions != null && | ||
process.versions.node != null | ||
} | ||
if (isInNode && isFunction(callback)) { | ||
callback() | ||
} | ||
return isInNode | ||
} |
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
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