@ace-util/core
Version:
Utils.
57 lines • 1.78 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.print = exports.assert = exports.warn = exports.hasSymbol = void 0;
/**
* check Symbol support
* @returns true/false
*/
exports.hasSymbol = typeof Symbol === 'function' && Symbol.for;
/**
* warn if condition is not pass
* @param condition condition
* @param format format
* @param args args
*/
function warn(condition, format) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
if (format === undefined) {
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
}
if (!condition) {
var argIndex_1 = 0;
var message = '[warn]: ' +
format.replace(/%s/g, function () {
return args[argIndex_1++];
});
if (typeof console !== 'undefined') {
// eslint-disable-next-line no-console
console.error(message);
}
}
}
exports.warn = warn;
/**
* throw error if condition is not pass
* @param condition condition
* @param err error message or error object
*/
function assert(condition, err) {
if (!condition) {
throw typeof err === 'string' ? new Error("error: ".concat(err)) : err;
}
}
exports.assert = assert;
/**
* print a colorful message in console
* @param title title
* @param content content
*/
function print(title, content) {
// eslint-disable-next-line no-console
console.log("%c".concat(title, "%c").concat(content), 'background: #00d1b2; padding: 5px; color: #fff; border-radius: 5px 0 0 5px', 'background: #555; padding: 5px; color: #fff; border-radius: 0 5px 5px 0');
}
exports.print = print;
//# sourceMappingURL=tools.js.map
;