util: add util/types alias module

Refs: https://github.com/nodejs/node/pull/31553
Refs: https://github.com/nodejs/node/pull/32953
Refs: https://github.com/nodejs/node/pull/33950
Refs: https://github.com/nodejs/node/pull/34001
Refs: https://github.com/nodejs/node/pull/34002

PR-URL: https://github.com/nodejs/node/pull/34055
Refs: https://github.com/nodejs/node/pull/34962
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
ExE Boss 2020-06-27 15:40:00 +02:00 committed by Antoine du Hamel
parent 6b6bbfe7d0
commit c2ceb15fd5
5 changed files with 22 additions and 0 deletions

View File

@ -1290,6 +1290,10 @@ The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
## `util.types` ## `util.types`
<!-- YAML <!-- YAML
added: v10.0.0 added: v10.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/34055
description: Exposed as `require('util/types')`.
--> -->
`util.types` provides type checks for different kinds of built-in objects. `util.types` provides type checks for different kinds of built-in objects.
@ -1301,6 +1305,8 @@ The result generally does not make any guarantees about what kinds of
properties or behavior a value exposes in JavaScript. They are primarily properties or behavior a value exposes in JavaScript. They are primarily
useful for addon developers who prefer to do type checking in JavaScript. useful for addon developers who prefer to do type checking in JavaScript.
The API is accessible via `require('util').types` or `require('util/types')`.
### `util.types.isAnyArrayBuffer(value)` ### `util.types.isAnyArrayBuffer(value)`
<!-- YAML <!-- YAML
added: v10.0.0 added: v10.0.0

3
lib/util/types.js Normal file
View File

@ -0,0 +1,3 @@
'use strict';
module.exports = require('internal/util/types');

View File

@ -99,6 +99,7 @@
'lib/tty.js', 'lib/tty.js',
'lib/url.js', 'lib/url.js',
'lib/util.js', 'lib/util.js',
'lib/util/types.js',
'lib/v8.js', 'lib/v8.js',
'lib/vm.js', 'lib/vm.js',
'lib/wasi.js', 'lib/wasi.js',

View File

@ -0,0 +1,6 @@
import '../common/index.mjs';
import assert from 'assert';
import { types } from 'util';
import utilTypes from 'util/types';
assert.strictEqual(types, utilTypes);

View File

@ -0,0 +1,6 @@
'use strict';
require('../common');
const assert = require('assert');
assert.strictEqual(require('util/types'), require('util').types);