1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

feat(std/node): Add util.deprecate (#8407)

This commit is contained in:
Steven Guerrero 2020-11-16 18:20:46 -05:00 committed by GitHub
parent 636af2850c
commit 06cf6df954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View file

@ -123,6 +123,22 @@ export function getSystemErrorName(code: number): string | undefined {
return errorMap.get(code)?.[0];
}
/**
* https://nodejs.org/api/util.html#util_util_deprecate_fn_msg_code
* @param _code This implementation of deprecate won't apply the deprecation code
*/
export function deprecate<A extends Array<unknown>, B>(
this: unknown,
callback: (...args: A) => B,
msg: string,
_code?: string,
) {
return function (this: unknown, ...args: A) {
console.warn(msg);
return callback.apply(this, args);
};
}
import { _TextDecoder, _TextEncoder } from "./_utils.ts";
/** The global TextDecoder */

View file

@ -220,3 +220,28 @@ Deno.test({
}
},
});
Deno.test("[util] deprecate", () => {
const warn = console.warn.bind(null);
let output;
console.warn = function (str: string) {
output = str;
warn(output);
};
const message = "x is deprecated";
const expected = 12;
let result;
const x = util.deprecate(() => {
result = expected;
}, message);
x();
assertEquals(expected, result);
assertEquals(output, message);
console.warn = warn;
});