Skip to content

Commit

Permalink
os: add os.devnull()
Browse files Browse the repository at this point in the history
Returns the platform-specific file path of the null device.
  • Loading branch information
lpinca committed May 6, 2021
1 parent ad1961d commit 7d4759b
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
12 changes: 12 additions & 0 deletions doc/api/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ The properties included on each object include:
`nice` values are POSIX-only. On Windows, the `nice` values of all processors
are always 0.

## `os.devnull()`
<!-- YAML
added: REPLACEME
-->

* Returns: {string}

Returns the platform-specific file path of the null device:

* `\\.\nul` on Windows
* `/dev/null` on POSIX

## `os.endianness()`
<!-- YAML
added: v0.9.4
Expand Down
12 changes: 0 additions & 12 deletions doc/api/path.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,6 @@ process.env.PATH.split(path.delimiter);
// Returns ['C:\\Windows\\system32', 'C:\\Windows', 'C:\\Program Files\\node\\']
```

## `path.devnull`
<!-- YAML
added: REPLACEME
-->

* {string}

Provides the platform-specific file path of the null device:

* `\\.\nul` on Windows
* `/dev/null` on POSIX

## `path.dirname(path)`
<!-- YAML
added: v0.1.16
Expand Down
9 changes: 9 additions & 0 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,18 @@ function userInfo(options) {
return user;
}

/**
* @returns {string}
*/
function devnull() {
return isWindows ? '\\\\.\\nul' : '/dev/null';
}
devnull[SymbolToPrimitive] = () => devnull();

module.exports = {
arch,
cpus,
devnull,
endianness,
freemem: getFreeMem,
getPriority,
Expand Down
2 changes: 0 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ const win32 = {
return ret;
},

devnull: '\\\\.\\nul',
sep: '\\',
delimiter: ';',
win32: null,
Expand Down Expand Up @@ -1532,7 +1531,6 @@ const posix = {
return ret;
},

devnull: '/dev/null',
sep: '/',
delimiter: ':',
win32: null,
Expand Down
10 changes: 10 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,13 @@ if (!common.isIBMi) {

is.number(+os.freemem, 'freemem');
is.number(os.freemem(), 'freemem');

const devnull = os.devnull();

if (common.isWindows) {
assert.strictEqual(devnull, '\\\\.\\nul');
} else {
assert.strictEqual(devnull, '/dev/null');
}

assert.strictEqual(`${os.devnull}`, devnull);
6 changes: 0 additions & 6 deletions test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ assert.strictEqual(path.win32.delimiter, ';');
// posix
assert.strictEqual(path.posix.delimiter, ':');

// path.devnull tests
// windows
assert.strictEqual(path.win32.devnull, '\\\\.\\nul');
// posix
assert.strictEqual(path.posix.devnull, '/dev/null');

if (common.isWindows)
assert.strictEqual(path, path.win32);
else
Expand Down

0 comments on commit 7d4759b

Please sign in to comment.