index.js 284 B

123456789101112131415161718
  1. 'use strict';
  2. const callsites = require('callsites');
  3. module.exports = () => {
  4. const c = callsites();
  5. let caller;
  6. for (let i = 0; i < c.length; i++) {
  7. const hasReceiver = c[i].getTypeName() !== null;
  8. if (hasReceiver) {
  9. caller = i;
  10. break;
  11. }
  12. }
  13. return c[caller];
  14. };