UNPKG

@enact/core

Version:

Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.

101 lines (97 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deprecate = exports["default"] = void 0; /** * Provides the `deprecate` method * * @module core/internal/deprecate * @private */ // Utility method to format deprecate message var formatMsg = function formatMsg(_ref) { var message = _ref.message, name = _ref.name, until = _ref.until, replacedBy = _ref.replacedBy, since = _ref.since; var msg = 'DEPRECATED:'; if (name) { msg += " ".concat(name); } if (since) { msg += " since ".concat(since); } if (until) { if (name || since) { msg += '.'; } msg += " Will be removed in ".concat(until); } if (replacedBy) { if (name || since || until) { msg += '.'; } msg += " Replaced by ".concat(replacedBy); } if (name || since || until || replacedBy) { msg += '.'; } if (message) { msg += " ".concat(message, "."); } return msg; }; // Utility method for console warning var warn = function warn(msg) { if (typeof console !== 'undefined') { console.warn(msg); // eslint-disable-line no-console } }; /** * Marks a function, component or property (via `propTypes`) as deprecated. Deprecated items will * log a message on first invocation. Can also be used 'stand-alone' to issue a deprecation warning. * In stand-alone mode it currently will log every time. In production mode, the deprecation * warning disappears. * * @function * @param {*} thing - The thing to be wrapped, or the deprecation config in stand-alone * @param {Object?} config - The deprecation config * @param {String?} config.name - An optional name for the deprecated item * @param {String?} config.message - An optional message to display * @param {String?} config.since - The version where deprecation started (optional) * @param {String?} config.until - The version where the functionality will be removed (optional) * @param {String?} config.replacedBy - An optional alternative * @param {Boolean?} config.alwaysWarn - If `true`, a warning will be issued for every access * @returns {*} Either a wrapped version of `thing` or an unwrapped version of `thing` in * production or stand-alone mode * @memberof core/internal/deprecate * @private */ var deprecate = exports.deprecate = function deprecate(thing, config) { if (process.env.NODE_ENV !== "production") { if (!config) { // If no config, config only invocation, just log message var msg = formatMsg(thing); warn(msg); return thing; } else { var displayed, _msg; return function () { if (!displayed || config.alwaysWarn) { if (!_msg) { _msg = formatMsg(config); } warn(_msg); displayed = true; } return thing.apply(void 0, arguments); }; } } else { /* istanbul ignore next */ return thing; } }; var _default = exports["default"] = deprecate;