summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/internal/validators.mjs
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2023-11-29 15:42:58 +0900
committerGitHub <noreply@github.com>2023-11-29 15:42:58 +0900
commite332fa4a83d36605771844745738c001f276b390 (patch)
tree9d21beacdcad06bb49cc31539ed3d8374e27506f /ext/node/polyfills/internal/validators.mjs
parent75ec650f080ac66e98d8b848118dc2349ca70aa8 (diff)
fix(ext/node): add util.parseArgs (#21342)
Diffstat (limited to 'ext/node/polyfills/internal/validators.mjs')
-rw-r--r--ext/node/polyfills/internal/validators.mjs18
1 files changed, 18 insertions, 0 deletions
diff --git a/ext/node/polyfills/internal/validators.mjs b/ext/node/polyfills/internal/validators.mjs
index 285603d06..b5b539088 100644
--- a/ext/node/polyfills/internal/validators.mjs
+++ b/ext/node/polyfills/internal/validators.mjs
@@ -9,6 +9,12 @@ import { hideStackFrames } from "ext:deno_node/internal/hide_stack_frames.ts";
import { isArrayBufferView } from "ext:deno_node/internal/util/types.ts";
import { normalizeEncoding } from "ext:deno_node/internal/normalize_encoding.mjs";
+const primordials = globalThis.__bootstrap.primordials;
+const {
+ ArrayPrototypeIncludes,
+ ArrayPrototypeJoin,
+} = primordials;
+
/**
* @param {number} value
* @returns {boolean}
@@ -282,6 +288,16 @@ const validateArray = hideStackFrames(
},
);
+function validateUnion(value, name, union) {
+ if (!ArrayPrototypeIncludes(union, value)) {
+ throw new ERR_INVALID_ARG_TYPE(
+ name,
+ `('${ArrayPrototypeJoin(union, "|")}')`,
+ value,
+ );
+ }
+}
+
export default {
isInt32,
isUint32,
@@ -299,6 +315,7 @@ export default {
validatePort,
validateString,
validateUint32,
+ validateUnion,
};
export {
isInt32,
@@ -317,4 +334,5 @@ export {
validatePort,
validateString,
validateUint32,
+ validateUnion,
};