0.1.1 • Published 3 years ago

@mscs/deprecation v0.1.1

Weekly downloads
65
License
MIT
Repository
-
Last release
3 years ago

Deprecation

A function to trigger deprecations.

Install

Just run yarn install @mscs/deprecation

Usage

There a several usages:

Trigger with custom message:

import { deprecate } from "@mscs/deprecation"; 

function deprecatedMethod(){
    deprecate("deprecatedMethod is deprecated. Use something else instead.");
}

Trigger with the conventional message:

import { deprecate } from "@mscs/deprecation"; 

function deprecatedMethod(){
    deprecate(3, 4, 6);
}

You can change behaviour by set the triggerHandler method.

import { deprecate, defaultDeprecationTriggerHandler } from "@mscs/deprecation"; 

deprecate.triggerHandler = (message: string, error: Error) => {
    // Perform the default behaviour.
    defaultDeprecationTriggerHandler(message, error)
    
    // Send deprecation to an endpoint
    fetch("https://my-server.tld/api/deprecation", {
        method: 'POST',
        body: JSON.stringify({ message, error }),
    })
    .catch(console.error);
}

function deprecatedMethod(){
    deprecate(3, 4, 6);
}