Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6085280

Browse filesBrowse files
aduh95BethGriggs
authored andcommitted
lib: avoid creating a throw away object in validateObject
PR-URL: #39807 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 9a67296 commit 6085280
Copy full SHA for 6085280

File tree

Expand file treeCollapse file tree

1 file changed

+14
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/validators.js‎

Copy file name to clipboardExpand all lines: lib/internal/validators.js
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,21 @@ function validateBoolean(value, name) {
140140
throw new ERR_INVALID_ARG_TYPE(name, 'boolean', value);
141141
}
142142

143+
/**
144+
* @param {unknown} value
145+
* @param {string} name
146+
* @param {{
147+
* allowArray?: boolean,
148+
* allowFunction?: boolean,
149+
* nullable?: boolean
150+
* }} [options]
151+
*/
143152
const validateObject = hideStackFrames(
144-
(value, name, {
145-
nullable = false,
146-
allowArray = false,
147-
allowFunction = false,
148-
} = {}) => {
153+
(value, name, options) => {
154+
const useDefaultOptions = options == null;
155+
const allowArray = useDefaultOptions ? false : options.allowArray;
156+
const allowFunction = useDefaultOptions ? false : options.allowFunction;
157+
const nullable = useDefaultOptions ? false : options.nullable;
149158
if ((!nullable && value === null) ||
150159
(!allowArray && ArrayIsArray(value)) ||
151160
(typeof value !== 'object' && (

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.