Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/workerd/index.ts>deprecate

A JavaScript extension package for building strong and modern applications.
Latest
function deprecate
Re-export
import { deprecate } from "https://deno.land/x/ayonli_jsext@v0.9.72/workerd/index.ts";

Marks a function as deprecated and returns a wrapped function.

When the wrapped function is called, a deprecation warning will be emitted to the stdout.

NOTE: The original function must have a name.

NOTE: This function is experimental and the warning may point to the wrong file source in some environments.

Examples

Example 1

import deprecate from "@ayonli/jsext/deprecate";

const sum = deprecate(function sum(a: number, b: number) {
    return a + b;
}, "use `a + b` instead");
console.log(sum(1, 2));
// output:
// DeprecationWarning: sum() is deprecated, use `a + b` instead (at <anonymous>:4:13)
// 3

Type Parameters

T
Fn extends (this: T, ...args: any[]) => any

Parameters

fn: Fn

Extra tip for the user to migrate.

optional
tip: string

If set, the warning will only be emitted once.

optional
once: boolean

Emits a deprecation warning for the target, usually a parameter, an option, or the function's name, etc.

Examples

Example 1

import deprecate from "@ayonli/jsext/deprecate";

function pow(a: number, b: number) {
    deprecate("pow()", pow, "use `a ** b` instead");
    return a ** b;
}

console.log(pow(2, 3));
// output:
// DeprecationWarning: pow() is deprecated, use `a ** b` instead (at <anonymous>:5:13)
// 3

Parameters

target: string

Usually set to the current function, used to locate the call-site.

forFn: Function

Extra tip for the user to migrate.

optional
tip: string

If set, the warning will only be emitted once.

optional
once: boolean