Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a utility method for creating deprecation warnings.
Arrange for this to contain the logic for showing once. Do a little
extra work to make sure the warning is coloured on the console.
  • Loading branch information
alexjeffburke committed Jan 5, 2020
commit 248f6f5c77d2be14be791f931a83737bd900a319
24 changes: 24 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const canSetPrototype =
Object.setPrototypeOf || { __proto__: [] } instanceof Array;
const greedyIntervalPacker = require('greedy-interval-packer');
const magicpen = require('magicpen');

const setPrototypeOf =
Object.setPrototypeOf ||
Expand Down Expand Up @@ -375,5 +376,28 @@ const utils = (module.exports = {
} else if (typeof process === 'object' && process.env) {
return process.env[varName];
}
},

createDeprecationWarning(message) {
let deprecationWarningDisplayed = false;

return () => {
if (deprecationWarningDisplayed) {
return;
}

deprecationWarningDisplayed = true;

let format = magicpen.defaultFormat;
if (format === 'html') {
// override given this will be output in the browser console
format = 'text';
}
console.warn(
magicpen()
.text(message, 'bgYellow', 'black')
.toString(format)
);
};
}
});