Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add isDeepStrictEqual and isArray to node:util #2879

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/node/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { default as internalTypes } from 'node-internal:internal_types';
import { default as utilImpl } from 'node-internal:util';
import { isDeepStrictEqual as _isDeepStrictEqual } from 'node-internal:internal_comparisons';

import {
validateFunction,
Expand Down Expand Up @@ -252,6 +253,14 @@ export function getCallSite(frames: number = 10) {
return utilImpl.getCallSite(frames);
}

export function isDeepStrictEqual(a: unknown, b: unknown): boolean {
return _isDeepStrictEqual(a, b);
}

export function isArray(a: unknown): boolean {
return Array.isArray(a);
}

export default {
types,
callbackify,
Expand Down Expand Up @@ -281,18 +290,23 @@ export default {
transferableAbortController,
transferableAbortSignal,
getCallSite,
isDeepStrictEqual,
isArray,
};

// Node.js util APIs we're currently not supporting
//
// The following functions doesn't make sense for Workerd to support in runtime.
// * util._errnoException
// * util._exceptionWithHostPort
// * util.getSystemErrorMap
// * util.getSystemErrorName
// * util.isArray
// * util.parseEnv
// The following functions are removed from Node.js, and only supported using
// a polyfill.
// * util.isBoolean
// * util.isBuffer
// * util.isDate
// * util.isDeepStrictEqual
// * util.isError
// * util.isFunction
// * util.isNull
Expand All @@ -304,3 +318,5 @@ export default {
// * util.isString
// * util.isSymbol
// * util.isUndefined
// TODO:
// * util.styleText
14 changes: 14 additions & 0 deletions src/workerd/api/node/tests/util-nodejs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4354,3 +4354,17 @@ export const getCallSiteTest = {
assert.strictEqual(typeof stack.column, 'number');
},
};

export const isDeepStrictEqual = {
test() {
util.isDeepStrictEqual(1, 1);
util.isDeepStrictEqual(['hello', 'world'], ['hello', 'world']);
},
};

export const isArray = {
test() {
assert.ok(util.isArray([]));
assert.ok(!util.isArray('hello world'));
},
};