make_warning.js 711 B

12345678910111213141516171819202122
  1. var util = require('util')
  2. var messages = require('./warning_messages.json')
  3. module.exports = function () {
  4. var args = Array.prototype.slice.call(arguments, 0)
  5. var warningName = args.shift()
  6. if (warningName === 'typo') {
  7. return makeTypoWarning.apply(null, args)
  8. } else {
  9. var msgTemplate = messages[warningName] ? messages[warningName] : warningName + ": '%s'"
  10. args.unshift(msgTemplate)
  11. return util.format.apply(null, args)
  12. }
  13. }
  14. function makeTypoWarning (providedName, probableName, field) {
  15. if (field) {
  16. providedName = field + "['" + providedName + "']"
  17. probableName = field + "['" + probableName + "']"
  18. }
  19. return util.format(messages.typo, providedName, probableName)
  20. }