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