source: frontend/node_modules/@sinonjs/commons/lib/deprecated.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/* eslint-disable no-console, prefer-template */
2"use strict";
3
4/**
5 * Returns a function that will invoke the supplied function and print a
6 * deprecation warning to the console each time it is called.
7 *
8 * @param {Function} func
9 * @param {string} msg
10 * @returns {Function}
11 */
12exports.wrap = function (func, msg) {
13 var wrapped = function () {
14 exports.printWarning(msg);
15 return func.apply(this, arguments);
16 };
17 if (func.prototype) {
18 wrapped.prototype = func.prototype;
19 }
20 return wrapped;
21};
22
23/**
24 * Returns a string which can be supplied to `wrap()` to notify the user that a
25 * particular part of the sinon API has been deprecated.
26 *
27 * @param {string} packageName
28 * @param {string} funcName
29 * @returns {string}
30 */
31exports.defaultMsg = function (packageName, funcName) {
32 return (
33 packageName +
34 "." +
35 funcName +
36 " is deprecated and will be removed from the public API in a future version of " +
37 packageName +
38 "."
39 );
40};
41
42/**
43 * Prints a warning on the console, when it exists
44 *
45 * @param {string} msg
46 * @returns {undefined}
47 */
48exports.printWarning = function (msg) {
49 /* istanbul ignore next */
50 if (typeof process === "object" && process.emitWarning) {
51 // Emit Warnings in Node
52 process.emitWarning(msg);
53 } else if (console.info) {
54 console.info(msg);
55 } else {
56 console.log(msg);
57 }
58};
Note: See TracBrowser for help on using the repository browser.