Blame view

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