diff --git a/lib/fs.js b/lib/fs.js index 46209a3f4d58c0..cf3c885b31cdf8 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -74,7 +74,6 @@ const { codes: { ERR_FS_FILE_TOO_LARGE, ERR_INVALID_ARG_VALUE, - ERR_INVALID_ARG_TYPE, ERR_FEATURE_UNAVAILABLE_ON_PLATFORM, }, AbortError, @@ -136,6 +135,7 @@ const { validateEncoding, validateFunction, validateInteger, + validateString, } = require('internal/validators'); const watchers = require('internal/fs/watchers'); @@ -2712,9 +2712,8 @@ realpath.native = (path, options, callback) => { function mkdtemp(prefix, options, callback) { callback = makeCallback(typeof options === 'function' ? options : callback); options = getOptions(options, {}); - if (!prefix || typeof prefix !== 'string') { - throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix); - } + + validateString(prefix, 'prefix'); nullCheck(prefix, 'prefix'); warnOnNonPortableTemplate(prefix); const req = new FSReqCallback(); @@ -2730,9 +2729,8 @@ function mkdtemp(prefix, options, callback) { */ function mkdtempSync(prefix, options) { options = getOptions(options, {}); - if (!prefix || typeof prefix !== 'string') { - throw new ERR_INVALID_ARG_TYPE('prefix', 'string', prefix); - } + + validateString(prefix, 'prefix'); nullCheck(prefix, 'prefix'); warnOnNonPortableTemplate(prefix); const path = `${prefix}XXXXXX`;