twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

index.js (1421B)


      1 /*!
      2  * depd
      3  * Copyright(c) 2014-2015 Douglas Christopher Wilson
      4  * MIT Licensed
      5  */
      6 
      7 'use strict'
      8 
      9 /**
     10  * Module dependencies.
     11  * @private
     12  */
     13 
     14 var EventEmitter = require('events').EventEmitter
     15 
     16 /**
     17  * Module exports.
     18  * @public
     19  */
     20 
     21 lazyProperty(module.exports, 'callSiteToString', function callSiteToString () {
     22   var limit = Error.stackTraceLimit
     23   var obj = {}
     24   var prep = Error.prepareStackTrace
     25 
     26   function prepareObjectStackTrace (obj, stack) {
     27     return stack
     28   }
     29 
     30   Error.prepareStackTrace = prepareObjectStackTrace
     31   Error.stackTraceLimit = 2
     32 
     33   // capture the stack
     34   Error.captureStackTrace(obj)
     35 
     36   // slice the stack
     37   var stack = obj.stack.slice()
     38 
     39   Error.prepareStackTrace = prep
     40   Error.stackTraceLimit = limit
     41 
     42   return stack[0].toString ? toString : require('./callsite-tostring')
     43 })
     44 
     45 lazyProperty(module.exports, 'eventListenerCount', function eventListenerCount () {
     46   return EventEmitter.listenerCount || require('./event-listener-count')
     47 })
     48 
     49 /**
     50  * Define a lazy property.
     51  */
     52 
     53 function lazyProperty (obj, prop, getter) {
     54   function get () {
     55     var val = getter()
     56 
     57     Object.defineProperty(obj, prop, {
     58       configurable: true,
     59       enumerable: true,
     60       value: val
     61     })
     62 
     63     return val
     64   }
     65 
     66   Object.defineProperty(obj, prop, {
     67     configurable: true,
     68     enumerable: true,
     69     get: get
     70   })
     71 }
     72 
     73 /**
     74  * Call toString() on the obj
     75  */
     76 
     77 function toString (obj) {
     78   return obj.toString()
     79 }