Add isNode, randomIpAddress and isRegularExpression (#1526)
* add isNode() Co-authored-by: Angelos Chalaris <chalarangelo@gmail.com>
This commit is contained in:
committed by
GitHub
parent
6f26dd9e6e
commit
805c6bd36c
21
snippets/isNode.md
Normal file
21
snippets/isNode.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: isNode
|
||||
tags: node,intermediate
|
||||
---
|
||||
|
||||
Determines if the current runtime environment is Node.js.
|
||||
|
||||
- Use the `process` global object that provides information about the current Node.js process.
|
||||
- Check if `process` is defined and `process.versions`, `process.versions.node` are not `null`.
|
||||
|
||||
```js
|
||||
const isNode = () =>
|
||||
typeof process !== 'undefined' &&
|
||||
process.versions !== null &&
|
||||
process.versions.node !== null;
|
||||
```
|
||||
|
||||
```js
|
||||
isNode(); // true (Node)
|
||||
isNode(); // false (browser)
|
||||
```
|
||||
Reference in New Issue
Block a user