index.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*!
  2. * depd
  3. * Copyright(c) 2015 Douglas Christopher Wilson
  4. * MIT Licensed
  5. */
  6. 'use strict'
  7. /**
  8. * Module exports.
  9. * @public
  10. */
  11. module.exports = depd
  12. /**
  13. * Create deprecate for namespace in caller.
  14. */
  15. function depd (namespace) {
  16. if (!namespace) {
  17. throw new TypeError('argument namespace is required')
  18. }
  19. function deprecate (message) {
  20. // no-op in browser
  21. }
  22. deprecate._file = undefined
  23. deprecate._ignored = true
  24. deprecate._namespace = namespace
  25. deprecate._traced = false
  26. deprecate._warned = Object.create(null)
  27. deprecate.function = wrapfunction
  28. deprecate.property = wrapproperty
  29. return deprecate
  30. }
  31. /**
  32. * Return a wrapped function in a deprecation message.
  33. *
  34. * This is a no-op version of the wrapper, which does nothing but call
  35. * validation.
  36. */
  37. function wrapfunction (fn, message) {
  38. if (typeof fn !== 'function') {
  39. throw new TypeError('argument fn must be a function')
  40. }
  41. return fn
  42. }
  43. /**
  44. * Wrap property in a deprecation message.
  45. *
  46. * This is a no-op version of the wrapper, which does nothing but call
  47. * validation.
  48. */
  49. function wrapproperty (obj, prop, message) {
  50. if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
  51. throw new TypeError('argument obj must be object')
  52. }
  53. var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
  54. if (!descriptor) {
  55. throw new TypeError('must call property on owner object')
  56. }
  57. if (!descriptor.configurable) {
  58. throw new TypeError('property must be configurable')
  59. }
  60. }