summaryrefslogtreecommitdiff
path: root/std/node/util.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/node/util.ts')
-rw-r--r--std/node/util.ts18
1 files changed, 17 insertions, 1 deletions
diff --git a/std/node/util.ts b/std/node/util.ts
index 27aa5a12b..076a5b830 100644
--- a/std/node/util.ts
+++ b/std/node/util.ts
@@ -1,10 +1,16 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
export { promisify } from "./_util/_util_promisify.ts";
export { callbackify } from "./_util/_util_callbackify.ts";
+import { codes, errorMap } from "./_errors.ts";
import * as types from "./_util/_util_types.ts";
-
export { types };
+const NumberIsSafeInteger = Number.isSafeInteger;
+const {
+ ERR_OUT_OF_RANGE,
+ ERR_INVALID_ARG_TYPE,
+} = codes;
+
const DEFAULT_INSPECT_OPTIONS = {
showHidden: false,
depth: 2,
@@ -90,6 +96,16 @@ export function isPrimitive(value: unknown): boolean {
);
}
+export function getSystemErrorName(code: number): string | undefined {
+ if (typeof code !== "number") {
+ throw new ERR_INVALID_ARG_TYPE("err", "number", code);
+ }
+ if (code >= 0 || !NumberIsSafeInteger(code)) {
+ throw new ERR_OUT_OF_RANGE("err", "a negative integer", code);
+ }
+ return errorMap.get(code)?.[0];
+}
+
import { _TextDecoder, _TextEncoder } from "./_utils.ts";
/** The global TextDecoder */