diff --git a/benchmark/es/spread-assign.js b/benchmark/es/spread-assign.js index f0dcd56bb606b1..211979c710baf3 100644 --- a/benchmark/es/spread-assign.js +++ b/benchmark/es/spread-assign.js @@ -1,10 +1,9 @@ 'use strict'; const common = require('../common.js'); -const util = require('util'); const bench = common.createBenchmark(main, { - method: ['spread', 'assign', '_extend'], + method: ['spread', 'assign'], count: [5, 10, 20], n: [1e6], }); @@ -18,12 +17,6 @@ function main({ n, context, count, rest, method }) { let obj; switch (method) { - case '_extend': - bench.start(); - for (let i = 0; i < n; i++) - obj = util._extend({}, src); - bench.end(n); - break; case 'assign': bench.start(); for (let i = 0; i < n; i++) diff --git a/benchmark/misc/util-extend-vs-object-assign.js b/benchmark/misc/util-extend-vs-object-assign.js deleted file mode 100644 index e2ac0a5417e489..00000000000000 --- a/benchmark/misc/util-extend-vs-object-assign.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -const common = require('../common.js'); -const util = require('util'); - -const bench = common.createBenchmark(main, { - type: ['extend', 'assign'], - n: [10e4], -}); - -function main({ n, type }) { - let fn; - if (type === 'extend') { - fn = util._extend; - } else if (type === 'assign') { - fn = Object.assign; - } - - // Force-optimize the method to test so that the benchmark doesn't - // get disrupted by the optimizer kicking in halfway through. - for (let i = 0; i < type.length * 10; i += 1) - fn({}, process.env); - - const obj = new Proxy({}, { set: function(a, b, c) { return true; } }); - - bench.start(); - for (let j = 0; j < n; j += 1) - fn(obj, process.env); - bench.end(n); -} diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index ecdd453bae7031..f22e790ef461e5 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -996,6 +996,9 @@ instead. -Type: Runtime +Type: End-of-Life -The [`util.isBoolean()`][] API is deprecated. Please use +The `util.isBoolean()` API has been removed. Please use `typeof arg === 'boolean'` instead. ### DEP0046: `util.isBuffer()` -Type: Runtime +Type: End-of-Life -The [`util.isBuffer()`][] API is deprecated. Please use +The `util.isBuffer()` API has been removed. Please use [`Buffer.isBuffer()`][] instead. ### DEP0047: `util.isDate()` -Type: Runtime +Type: End-of-Life -The [`util.isDate()`][] API is deprecated. Please use +The `util.isDate()` API has been removed. Please use `arg instanceof Date` instead. ### DEP0048: `util.isError()` -Type: Runtime +Type: End-of-Life -The [`util.isError()`][] API is deprecated. Please use +The `util.isError()` API has been removed. Please use `Object.prototype.toString(arg) === '[object Error]' || arg instanceof Error` instead. @@ -1093,6 +1105,9 @@ instead. -Type: Runtime +Type: End-of-Life -The [`util.isFunction()`][] API is deprecated. Please use +The `util.isFunction()` API has been removed. Please use `typeof arg === 'function'` instead. ### DEP0050: `util.isNull()` -Type: Runtime +Type: End-of-Life -The [`util.isNull()`][] API is deprecated. Please use +The `util.isNull()` API has been removed. Please use `arg === null` instead. ### DEP0051: `util.isNullOrUndefined()` -Type: Runtime +Type: End-of-Life -The [`util.isNullOrUndefined()`][] API is deprecated. Please use +The `util.isNullOrUndefined()` API has been removed. Please use `arg === null || arg === undefined` instead. ### DEP0052: `util.isNumber()` -Type: Runtime +Type: End-of-Life -The [`util.isNumber()`][] API is deprecated. Please use +The `util.isNumber()` API has been removed. Please use `typeof arg === 'number'` instead. ### DEP0053: `util.isObject()` -Type: Runtime +Type: End-of-Life -The [`util.isObject()`][] API is deprecated. Please use +The `util.isObject()` API has been removed. Please use `arg && typeof arg === 'object'` instead. ### DEP0054: `util.isPrimitive()` -Type: Runtime +Type: End-of-Life -The [`util.isPrimitive()`][] API is deprecated. Please use +The `util.isPrimitive()` API has been removed. Please use `arg === null || (typeof arg !=='object' && typeof arg !== 'function')` instead. @@ -1238,6 +1268,9 @@ instead. -Type: Runtime +Type: End-of-Life -The [`util.isRegExp()`][] API is deprecated. Please use +The `util.isRegExp()` API has been removed. Please use `arg instanceof RegExp` instead. ### DEP0056: `util.isString()` -Type: Runtime +Type: End-of-Life -The [`util.isString()`][] API is deprecated. Please use +The `util.isString()` API has been removed. Please use `typeof arg === 'string'` instead. ### DEP0057: `util.isSymbol()` -Type: Runtime +Type: End-of-Life -The [`util.isSymbol()`][] API is deprecated. Please use +The `util.isSymbol()` API has been removed. Please use `typeof arg === 'symbol'` instead. ### DEP0058: `util.isUndefined()` -Type: Runtime +Type: End-of-Life -The [`util.isUndefined()`][] API is deprecated. Please use +The `util.isUndefined()` API has been removed. Please use `arg === undefined` instead. ### DEP0059: `util.log()` -Type: Runtime +Type: End-of-Life -The [`util.log()`][] API has been deprecated because it's an unmaintained +The `util.log()` API has been removed because it's an unmaintained legacy API that was exposed to user land by accident. Instead, consider the following alternatives based on your specific needs: @@ -1363,6 +1408,9 @@ requirements and complexity of your application. -Type: Runtime +Type: End-of-Life -The [`util._extend()`][] API is deprecated because it's an unmaintained +The `util._extend()` API has been removed because it's an unmaintained legacy API that was exposed to user land by accident. Please use `target = Object.assign(target, source)` instead. @@ -3764,26 +3812,10 @@ is deprecated to better align with recommendations per [NIST SP 800-38D][]. [`url.format()`]: url.md#urlformaturlobject [`url.parse()`]: url.md#urlparseurlstring-parsequerystring-slashesdenotehost [`url.resolve()`]: url.md#urlresolvefrom-to -[`util._extend()`]: util.md#util_extendtarget-source [`util.getSystemErrorName()`]: util.md#utilgetsystemerrornameerr [`util.inspect()`]: util.md#utilinspectobject-options [`util.inspect.custom`]: util.md#utilinspectcustom [`util.isArray()`]: util.md#utilisarrayobject -[`util.isBoolean()`]: util.md#utilisbooleanobject -[`util.isBuffer()`]: util.md#utilisbufferobject -[`util.isDate()`]: util.md#utilisdateobject -[`util.isError()`]: util.md#utiliserrorobject -[`util.isFunction()`]: util.md#utilisfunctionobject -[`util.isNull()`]: util.md#utilisnullobject -[`util.isNullOrUndefined()`]: util.md#utilisnullorundefinedobject -[`util.isNumber()`]: util.md#utilisnumberobject -[`util.isObject()`]: util.md#utilisobjectobject -[`util.isPrimitive()`]: util.md#utilisprimitiveobject -[`util.isRegExp()`]: util.md#utilisregexpobject -[`util.isString()`]: util.md#utilisstringobject -[`util.isSymbol()`]: util.md#utilissymbolobject -[`util.isUndefined()`]: util.md#utilisundefinedobject -[`util.log()`]: util.md#utillogstring [`util.promisify`]: util.md#utilpromisifyoriginal [`util.toUSVString()`]: util.md#utiltousvstringstring [`util.types`]: util.md#utiltypes diff --git a/doc/api/util.md b/doc/api/util.md index 477e91f2680770..776b54a5a2f51d 100644 --- a/doc/api/util.md +++ b/doc/api/util.md @@ -2923,24 +2923,6 @@ util.types.isWeakSet(new WeakSet()); // Returns true The following APIs are deprecated and should no longer be used. Existing applications and modules should be updated to find alternative approaches. -### `util._extend(target, source)` - - - -> Stability: 0 - Deprecated: Use [`Object.assign()`][] instead. - -* `target` {Object} -* `source` {Object} - -The `util._extend()` method was never intended to be used outside of internal -Node.js modules. The community found and used it anyway. - -It is deprecated and should not be used in new code. JavaScript comes with very -similar built-in functionality through [`Object.assign()`][]. - ### `util.isArray(object)` - -> Stability: 0 - Deprecated: Use `typeof value === 'boolean'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isBoolean(1); -// Returns: false -util.isBoolean(0); -// Returns: false -util.isBoolean(false); -// Returns: true -``` - -### `util.isBuffer(object)` - - - -> Stability: 0 - Deprecated: Use [`Buffer.isBuffer()`][] instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Buffer`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isBuffer({ length: 0 }); -// Returns: false -util.isBuffer([]); -// Returns: false -util.isBuffer(Buffer.from('hello world')); -// Returns: true -``` - -### `util.isDate(object)` - - - -> Stability: 0 - Deprecated: Use [`util.types.isDate()`][] instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Date`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isDate(new Date()); -// Returns: true -util.isDate(Date()); -// false (without 'new' returns a String) -util.isDate({}); -// Returns: false -``` - -### `util.isError(object)` - - - -> Stability: 0 - Deprecated: Use [`util.types.isNativeError()`][] instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is an [`Error`][]. Otherwise, returns -`false`. - -```js -const util = require('node:util'); - -util.isError(new Error()); -// Returns: true -util.isError(new TypeError()); -// Returns: true -util.isError({ name: 'Error', message: 'an error occurred' }); -// Returns: false -``` - -This method relies on `Object.prototype.toString()` behavior. It is -possible to obtain an incorrect result when the `object` argument manipulates -`@@toStringTag`. - -```js -const util = require('node:util'); -const obj = { name: 'Error', message: 'an error occurred' }; - -util.isError(obj); -// Returns: false -obj[Symbol.toStringTag] = 'Error'; -util.isError(obj); -// Returns: true -``` - -### `util.isFunction(object)` - - - -> Stability: 0 - Deprecated: Use `typeof value === 'function'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Function`. Otherwise, returns -`false`. - -```js -const util = require('node:util'); - -function Foo() {} -const Bar = () => {}; - -util.isFunction({}); -// Returns: false -util.isFunction(Foo); -// Returns: true -util.isFunction(Bar); -// Returns: true -``` - -### `util.isNull(object)` - - - -> Stability: 0 - Deprecated: Use `value === null` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is strictly `null`. Otherwise, returns -`false`. - -```js -const util = require('node:util'); - -util.isNull(0); -// Returns: false -util.isNull(undefined); -// Returns: false -util.isNull(null); -// Returns: true -``` - -### `util.isNullOrUndefined(object)` - - - -> Stability: 0 - Deprecated: Use -> `value === undefined || value === null` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is `null` or `undefined`. Otherwise, -returns `false`. - -```js -const util = require('node:util'); - -util.isNullOrUndefined(0); -// Returns: false -util.isNullOrUndefined(undefined); -// Returns: true -util.isNullOrUndefined(null); -// Returns: true -``` - -### `util.isNumber(object)` - - - -> Stability: 0 - Deprecated: Use `typeof value === 'number'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isNumber(false); -// Returns: false -util.isNumber(Infinity); -// Returns: true -util.isNumber(0); -// Returns: true -util.isNumber(NaN); -// Returns: true -``` - -### `util.isObject(object)` - - - -> Stability: 0 - Deprecated: -> Use `value !== null && typeof value === 'object'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is strictly an `Object` **and** not a -`Function` (even though functions are objects in JavaScript). -Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isObject(5); -// Returns: false -util.isObject(null); -// Returns: false -util.isObject({}); -// Returns: true -util.isObject(() => {}); -// Returns: false -``` - -### `util.isPrimitive(object)` - - - -> Stability: 0 - Deprecated: Use -> `(typeof value !== 'object' && typeof value !== 'function') || value === null` -> instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a primitive type. Otherwise, returns -`false`. - -```js -const util = require('node:util'); - -util.isPrimitive(5); -// Returns: true -util.isPrimitive('foo'); -// Returns: true -util.isPrimitive(false); -// Returns: true -util.isPrimitive(null); -// Returns: true -util.isPrimitive(undefined); -// Returns: true -util.isPrimitive({}); -// Returns: false -util.isPrimitive(() => {}); -// Returns: false -util.isPrimitive(/^$/); -// Returns: false -util.isPrimitive(new Date()); -// Returns: false -``` - -### `util.isRegExp(object)` - - - -> Stability: 0 - Deprecated - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `RegExp`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isRegExp(/some regexp/); -// Returns: true -util.isRegExp(new RegExp('another regexp')); -// Returns: true -util.isRegExp({}); -// Returns: false -``` - -### `util.isString(object)` - - - -> Stability: 0 - Deprecated: Use `typeof value === 'string'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `string`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isString(''); -// Returns: true -util.isString('foo'); -// Returns: true -util.isString(String('foo')); -// Returns: true -util.isString(5); -// Returns: false -``` - -### `util.isSymbol(object)` - - - -> Stability: 0 - Deprecated: Use `typeof value === 'symbol'` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is a `Symbol`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -util.isSymbol(5); -// Returns: false -util.isSymbol('foo'); -// Returns: false -util.isSymbol(Symbol('foo')); -// Returns: true -``` - -### `util.isUndefined(object)` - - - -> Stability: 0 - Deprecated: Use `value === undefined` instead. - -* `object` {any} -* Returns: {boolean} - -Returns `true` if the given `object` is `undefined`. Otherwise, returns `false`. - -```js -const util = require('node:util'); - -const foo = undefined; -util.isUndefined(5); -// Returns: false -util.isUndefined(foo); -// Returns: true -util.isUndefined(null); -// Returns: false -``` - -### `util.log(string)` - - - -> Stability: 0 - Deprecated: Use a third party module instead. - -* `string` {string} - -The `util.log()` method prints the given `string` to `stdout` with an included -timestamp. - -```js -const util = require('node:util'); - -util.log('Timestamped message.'); -``` - [Common System Errors]: errors.md#common-system-errors [Custom inspection functions on objects]: #custom-inspection-functions-on-objects [Custom promisified functions]: #custom-promisified-functions @@ -3398,10 +2962,8 @@ util.log('Timestamped message.'); [`Array.isArray()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray [`ArrayBuffer.isView()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView [`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer -[`Buffer.isBuffer()`]: buffer.md#static-method-bufferisbufferobj [`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView [`Date`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date -[`Error`]: errors.md#class-error [`Float32Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array [`Float64Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array [`Int16Array`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array @@ -3410,7 +2972,6 @@ util.log('Timestamped message.'); [`JSON.stringify()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify [`MIMEparams`]: #class-utilmimeparams [`Map`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map -[`Object.assign()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign [`Object.freeze()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze [`Promise`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise [`Proxy`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy @@ -3435,8 +2996,6 @@ util.log('Timestamped message.'); [`util.promisify()`]: #utilpromisifyoriginal [`util.types.isAnyArrayBuffer()`]: #utiltypesisanyarraybuffervalue [`util.types.isArrayBuffer()`]: #utiltypesisarraybuffervalue -[`util.types.isDate()`]: #utiltypesisdatevalue -[`util.types.isNativeError()`]: #utiltypesisnativeerrorvalue [`util.types.isSharedArrayBuffer()`]: #utiltypesissharedarraybuffervalue [async function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function [built-in `Error` type]: https://tc39.es/ecma262/#sec-error-objects diff --git a/lib/util.js b/lib/util.js index 11d69e6fa0f460..2c63152eb8bd2b 100644 --- a/lib/util.js +++ b/lib/util.js @@ -23,14 +23,7 @@ const { ArrayIsArray, - ArrayPrototypeJoin, ArrayPrototypePop, - Date, - DatePrototypeGetDate, - DatePrototypeGetHours, - DatePrototypeGetMinutes, - DatePrototypeGetMonth, - DatePrototypeGetSeconds, Error, ErrorCaptureStackTrace, FunctionPrototypeBind, @@ -39,11 +32,9 @@ const { ObjectDefineProperty, ObjectGetOwnPropertyDescriptors, ObjectKeys, - ObjectPrototypeToString, ObjectSetPrototypeOf, ObjectValues, ReflectApply, - StringPrototypePadStart, StringPrototypeToWellFormed, } = primordials; @@ -70,7 +61,6 @@ const { validateString, validateOneOf, } = require('internal/validators'); -const { isBuffer } = require('buffer').Buffer; const types = require('internal/util/types'); const binding = internalBinding('util'); @@ -91,113 +81,6 @@ function lazyAbortController() { let internalDeepEqual; -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is boolean} - */ -function isBoolean(arg) { - return typeof arg === 'boolean'; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is null} - */ -function isNull(arg) { - return arg === null; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is (null | undefined)} - */ -function isNullOrUndefined(arg) { - return arg === null || arg === undefined; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is number} - */ -function isNumber(arg) { - return typeof arg === 'number'; -} - -/** - * @param {any} arg - * @returns {arg is string} - */ -function isString(arg) { - return typeof arg === 'string'; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is symbol} - */ -function isSymbol(arg) { - return typeof arg === 'symbol'; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is undefined} - */ -function isUndefined(arg) { - return arg === undefined; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {a is NonNullable} - */ -function isObject(arg) { - return arg !== null && typeof arg === 'object'; -} - -/** - * @deprecated since v4.0.0 - * @param {any} e - * @returns {arg is Error} - */ -function isError(e) { - return ObjectPrototypeToString(e) === '[object Error]' || e instanceof Error; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is Function} - */ -function isFunction(arg) { - return typeof arg === 'function'; -} - -/** - * @deprecated since v4.0.0 - * @param {any} arg - * @returns {arg is (boolean | null | number | string | symbol | undefined)} - */ -function isPrimitive(arg) { - return arg === null || - (typeof arg !== 'object' && typeof arg !== 'function'); -} - -/** - * @param {number} n - * @returns {string} - */ -function pad(n) { - return StringPrototypePadStart(n.toString(), 2, '0'); -} - /** * @param {string} code * @returns {string} @@ -235,35 +118,6 @@ function styleText(format, text) { return `${escapeStyleCode(formatCodes[0])}${text}${escapeStyleCode(formatCodes[1])}`; } -const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', - 'Oct', 'Nov', 'Dec']; - -/** - * @returns {string} 26 Feb 16:19:34 - */ -function timestamp() { - const d = new Date(); - const t = ArrayPrototypeJoin([ - pad(DatePrototypeGetHours(d)), - pad(DatePrototypeGetMinutes(d)), - pad(DatePrototypeGetSeconds(d)), - ], ':'); - return `${DatePrototypeGetDate(d)} ${months[DatePrototypeGetMonth(d)]} ${t}`; -} - -let console; -/** - * Log is just a thin wrapper to console.log that prepends a timestamp - * @deprecated since v6.0.0 - * @type {(...args: any[]) => void} - */ -function log(...args) { - if (!console) { - console = require('internal/console/global'); - } - console.log('%s - %s', timestamp(), format(...args)); -} - /** * Inherit the prototype methods from one constructor into another. * @@ -299,26 +153,6 @@ function inherits(ctor, superCtor) { ObjectSetPrototypeOf(ctor.prototype, superCtor.prototype); } -/** - * @deprecated since v6.0.0 - * @template T - * @template S - * @param {T} target - * @param {S} source - * @returns {S extends null ? T : (T & S)} - */ -function _extend(target, source) { - // Don't do anything if source isn't an object - if (source === null || typeof source !== 'object') return target; - - const keys = ObjectKeys(source); - let i = keys.length; - while (i--) { - target[keys[i]] = source[keys[i]]; - } - return target; -} - const callbackifyOnRejected = (reason, cb) => { // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M). // Because `null` is a special error value in callbacks which means "no error @@ -425,9 +259,6 @@ function parseEnv(content) { module.exports = { _errnoException, _exceptionWithHostPort, - _extend: deprecate(_extend, - 'The `util._extend` API is deprecated. Please use Object.assign() instead.', - 'DEP0060'), callbackify, debug: debuglog, debuglog, @@ -442,12 +273,6 @@ module.exports = { isArray: deprecate(ArrayIsArray, 'The `util.isArray` API is deprecated. Please use `Array.isArray()` instead.', 'DEP0044'), - isBoolean: deprecate(isBoolean, - 'The `util.isBoolean` API is deprecated. Please use `typeof arg === "boolean"` instead.', - 'DEP0045'), - isBuffer: deprecate(isBuffer, - 'The `util.isBuffer` API is deprecated. Please use `Buffer.isBuffer()` instead.', - 'DEP0046'), isDeepStrictEqual(a, b) { if (internalDeepEqual === undefined) { internalDeepEqual = require('internal/util/comparisons') @@ -455,52 +280,6 @@ module.exports = { } return internalDeepEqual(a, b); }, - isNull: deprecate(isNull, - 'The `util.isNull` API is deprecated. Please use `arg === null` instead.', - 'DEP0050'), - isNullOrUndefined: deprecate(isNullOrUndefined, - 'The `util.isNullOrUndefined` API is deprecated. ' + - 'Please use `arg === null || arg === undefined` instead.', - 'DEP0051'), - isNumber: deprecate(isNumber, - 'The `util.isNumber` API is deprecated. Please use `typeof arg === "number"` instead.', - 'DEP0052'), - isString: deprecate(isString, - 'The `util.isString` API is deprecated. Please use `typeof arg === "string"` instead.', - 'DEP0056'), - isSymbol: deprecate(isSymbol, - 'The `util.isSymbol` API is deprecated. Please use `arg === "symbol"` instead.', - 'DEP0057'), - isUndefined: deprecate(isUndefined, - 'The `util.isUndefined` API is deprecated. Please use `arg === undefined` instead.', - 'DEP0058'), - isRegExp: deprecate(types.isRegExp, - 'The `util.isRegExp` API is deprecated. Please use `arg instanceof RegExp` instead.', - 'DEP0055'), - isObject: deprecate(isObject, - 'The `util.isObject` API is deprecated. ' + - 'Please use `arg !== null && typeof arg === "object"` instead.', - 'DEP0053'), - isDate: deprecate(types.isDate, - 'The `util.isDate` API is deprecated. Please use `arg instanceof Date` instead.', - 'DEP0047'), - isError: deprecate(isError, - 'The `util.isError` API is deprecated. ' + - 'Please use `ObjectPrototypeToString(e) === "[object Error]" ' + - '|| e instanceof Error` instead.', - 'DEP0048'), - isFunction: deprecate(isFunction, - 'The `util.isFunction` API is deprecated. Please use `typeof arg === "function"` instead.', - 'DEP0049'), - isPrimitive: deprecate(isPrimitive, - 'The `util.isPrimitive` API is deprecated. ' + - 'Please use `arg === null || ' + - '(typeof arg !== "object" && typeof arg !== "function")` instead.', - 'DEP0054'), - log: deprecate(log, - 'The `util.log API is deprecated. ' + - 'Please use console.log() with a custom formatter or a third-party logger instead.', - 'DEP0059'), promisify, stripVTControlCharacters, toUSVString(input) { diff --git a/test/fixtures/tls-connect.js b/test/fixtures/tls-connect.js index 51c0b328e97e27..107bdf87bd4a8d 100644 --- a/test/fixtures/tls-connect.js +++ b/test/fixtures/tls-connect.js @@ -57,7 +57,7 @@ exports.connect = function connect(options, callback) { }).listen(0, function() { server.server = this; - const optClient = util._extend({ + const optClient = Object.assign({ port: this.address().port, }, options.client); diff --git a/test/parallel/test-fs-write-file-buffer.js b/test/parallel/test-fs-write-file-buffer.js index ec6c60e1a46971..23dc48081a7bf0 100644 --- a/test/parallel/test-fs-write-file-buffer.js +++ b/test/parallel/test-fs-write-file-buffer.js @@ -21,7 +21,6 @@ 'use strict'; require('../common'); -const util = require('util'); const fs = require('fs'); let data = [ @@ -50,5 +49,3 @@ tmpdir.refresh(); const buf = Buffer.from(data, 'base64'); fs.writeFileSync(tmpdir.resolve('test.jpg'), buf); - -util.log('Done!'); diff --git a/test/parallel/test-util-log.js b/test/parallel/test-util-log.js deleted file mode 100644 index 838828e50f32b0..00000000000000 --- a/test/parallel/test-util-log.js +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -const common = require('../common'); -const { - hijackStdout, - hijackStderr, - restoreStdout, - restoreStderr, -} = require('../common/hijackstdio'); -const assert = require('assert'); -const util = require('util'); - -assert.ok(process.stdout.writable); -assert.ok(process.stderr.writable); - -const strings = []; -hijackStdout(function(data) { - strings.push(data); -}); -hijackStderr(common.mustNotCall('stderr.write must not be called')); - -const tests = [ - { input: 'foo', output: 'foo' }, - { input: undefined, output: 'undefined' }, - { input: null, output: 'null' }, - { input: false, output: 'false' }, - { input: 42, output: '42' }, - { input: function() {}, output: '[Function: input]' }, - { input: parseInt('not a number', 10), output: 'NaN' }, - { input: { answer: 42 }, output: '{ answer: 42 }' }, - { input: [1, 2, 3], output: '[ 1, 2, 3 ]' }, -]; - -// test util.log() -const re = /[0-9]{1,2} [A-Z][a-z]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} - (.+)$/; -for (const test of tests) { - util.log(test.input); - const result = strings.shift().trim(); - const match = re.exec(result); - assert.ok(match); - assert.strictEqual(match[1], test.output); -} - -assert.strictEqual(process.stdout.writeTimes, tests.length); - -restoreStdout(); -restoreStderr(); diff --git a/test/parallel/test-util.js b/test/parallel/test-util.js index 9a8b885647a31e..e544a2c07c6d88 100644 --- a/test/parallel/test-util.js +++ b/test/parallel/test-util.js @@ -40,114 +40,6 @@ assert.strictEqual(util.isArray(/regexp/), false); assert.strictEqual(util.isArray(new Error()), false); assert.strictEqual(util.isArray({ __proto__: Array.prototype }), false); -// isRegExp -assert.strictEqual(util.isRegExp(/regexp/), true); -assert.strictEqual(util.isRegExp(RegExp(), 'foo'), true); -assert.strictEqual(util.isRegExp(new RegExp()), true); -assert.strictEqual(util.isRegExp(context('RegExp')()), true); -assert.strictEqual(util.isRegExp({}), false); -assert.strictEqual(util.isRegExp([]), false); -assert.strictEqual(util.isRegExp(new Date()), false); -assert.strictEqual(util.isRegExp({ __proto__: RegExp.prototype }), false); - -// isDate -assert.strictEqual(util.isDate(new Date()), true); -assert.strictEqual(util.isDate(new Date(0), 'foo'), true); -assert.strictEqual(util.isDate(new (context('Date'))()), true); -assert.strictEqual(util.isDate(Date()), false); -assert.strictEqual(util.isDate({}), false); -assert.strictEqual(util.isDate([]), false); -assert.strictEqual(util.isDate(new Error()), false); -assert.strictEqual(util.isDate({ __proto__: Date.prototype }), false); - -// isError -assert.strictEqual(util.isError(new Error()), true); -assert.strictEqual(util.isError(new TypeError()), true); -assert.strictEqual(util.isError(new SyntaxError()), true); -assert.strictEqual(util.isError(new (context('Error'))()), true); -assert.strictEqual(util.isError(new (context('TypeError'))()), true); -assert.strictEqual(util.isError(new (context('SyntaxError'))()), true); -assert.strictEqual(util.isError({}), false); -assert.strictEqual(util.isError({ name: 'Error', message: '' }), false); -assert.strictEqual(util.isError([]), false); -assert.strictEqual(util.isError({ __proto__: Error.prototype }), true); - -// isObject -assert.strictEqual(util.isObject({}), true); -assert.strictEqual(util.isObject([]), true); -assert.strictEqual(util.isObject(new Number(3)), true); -assert.strictEqual(util.isObject(Number(4)), false); -assert.strictEqual(util.isObject(1), false); - -// isPrimitive -assert.strictEqual(util.isPrimitive({}), false); -assert.strictEqual(util.isPrimitive(new Error()), false); -assert.strictEqual(util.isPrimitive(new Date()), false); -assert.strictEqual(util.isPrimitive([]), false); -assert.strictEqual(util.isPrimitive(/regexp/), false); -assert.strictEqual(util.isPrimitive(function() {}), false); -assert.strictEqual(util.isPrimitive(new Number(1)), false); -assert.strictEqual(util.isPrimitive(new String('bla')), false); -assert.strictEqual(util.isPrimitive(new Boolean(true)), false); -assert.strictEqual(util.isPrimitive(1), true); -assert.strictEqual(util.isPrimitive('bla'), true); -assert.strictEqual(util.isPrimitive(true), true); -assert.strictEqual(util.isPrimitive(undefined), true); -assert.strictEqual(util.isPrimitive(null), true); -assert.strictEqual(util.isPrimitive(Infinity), true); -assert.strictEqual(util.isPrimitive(NaN), true); -assert.strictEqual(util.isPrimitive(Symbol('symbol')), true); - -// isBuffer -assert.strictEqual(util.isBuffer('foo'), false); -assert.strictEqual(util.isBuffer(Buffer.from('foo')), true); - -// _extend -assert.deepStrictEqual(util._extend({ a: 1 }), { a: 1 }); -assert.deepStrictEqual(util._extend({ a: 1 }, []), { a: 1 }); -assert.deepStrictEqual(util._extend({ a: 1 }, null), { a: 1 }); -assert.deepStrictEqual(util._extend({ a: 1 }, true), { a: 1 }); -assert.deepStrictEqual(util._extend({ a: 1 }, false), { a: 1 }); -assert.deepStrictEqual(util._extend({ a: 1 }, { b: 2 }), { a: 1, b: 2 }); -assert.deepStrictEqual(util._extend({ a: 1, b: 2 }, { b: 3 }), { a: 1, b: 3 }); - -// deprecated -assert.strictEqual(util.isBoolean(true), true); -assert.strictEqual(util.isBoolean(false), true); -assert.strictEqual(util.isBoolean('string'), false); - -assert.strictEqual(util.isNull(null), true); -assert.strictEqual(util.isNull(undefined), false); -assert.strictEqual(util.isNull(), false); -assert.strictEqual(util.isNull('string'), false); - -assert.strictEqual(util.isUndefined(undefined), true); -assert.strictEqual(util.isUndefined(), true); -assert.strictEqual(util.isUndefined(null), false); -assert.strictEqual(util.isUndefined('string'), false); - -assert.strictEqual(util.isNullOrUndefined(null), true); -assert.strictEqual(util.isNullOrUndefined(undefined), true); -assert.strictEqual(util.isNullOrUndefined(), true); -assert.strictEqual(util.isNullOrUndefined('string'), false); - -assert.strictEqual(util.isNumber(42), true); -assert.strictEqual(util.isNumber(), false); -assert.strictEqual(util.isNumber('string'), false); - -assert.strictEqual(util.isString('string'), true); -assert.strictEqual(util.isString(), false); -assert.strictEqual(util.isString(42), false); - -assert.strictEqual(util.isSymbol(Symbol()), true); -assert.strictEqual(util.isSymbol(), false); -assert.strictEqual(util.isSymbol('string'), false); - -assert.strictEqual(util.isFunction(() => {}), true); -assert.strictEqual(util.isFunction(function() {}), true); -assert.strictEqual(util.isFunction(), false); -assert.strictEqual(util.isFunction('string'), false); - assert.strictEqual(util.toUSVString('string\ud801'), 'string\ufffd'); {