You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.5 KiB

4 years ago
  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. }