pax_global_header00006660000000000000000000000064126016422000014503gustar00rootroot0000000000000052 comment=96474d00dd1090b99c0d71c8a9e1f74c24436011 caller-1.0.1/000077500000000000000000000000001260164220000127445ustar00rootroot00000000000000caller-1.0.1/.gitignore000066400000000000000000000000311260164220000147260ustar00rootroot00000000000000.idea node_modules *.log caller-1.0.1/.travis.yml000066400000000000000000000000631260164220000150540ustar00rootroot00000000000000language: node_js node_js: - "0.11" - "0.10" caller-1.0.1/LICENSE000066400000000000000000000020601260164220000137470ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.caller-1.0.1/README.md000066400000000000000000000016201260164220000142220ustar00rootroot00000000000000#### caller Figure out your caller (thanks to @substack). ##### Initialization Time Caller ```javascript // foo.js var bar = require('bar'); ``` ```javascript // bar.js var caller = require('caller'); console.log(caller()); // `/path/to/foo.js` ``` ##### Runtime Caller ```javascript // foo.js var bar = require('bar'); bar.doWork(); ``` ```javascript // bar.js var caller = require('caller'); exports.doWork = function () { console.log(caller()); // `/path/to/foo.js` }; ``` ### Depth Caller also accepts a `depth` argument for tracing back further (defaults to `1`). ```javascript // foo.js var bar = require('bar'); bar.doWork(); ``` ```javascript // bar.js var baz = require('baz'); exports.doWork = function () { baz.doWork(); }; ``` ```javascript // baz.js var caller = require('caller'); exports.doWork = function () { console.log(caller(2)); // `/path/to/foo.js` }; ``` caller-1.0.1/index.js000066400000000000000000000015061260164220000144130ustar00rootroot00000000000000'use strict'; /** * Module wrapper of @substack's `caller.js` * @original: https://github.com/substack/node-resolve/blob/master/lib/caller.js * @blessings: https://twitter.com/eriktoth/statuses/413719312273125377 * @see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi */ module.exports = function (depth) { var pst, stack, file, frame; pst = Error.prepareStackTrace; Error.prepareStackTrace = function (_, stack) { Error.prepareStackTrace = pst; return stack; }; stack = (new Error()).stack; depth = !depth || isNaN(depth) ? 1 : (depth > stack.length - 2 ? stack.length - 2 : depth); stack = stack.slice(depth + 1); do { frame = stack.shift(); file = frame && frame.getFileName(); } while (stack.length && file === 'module.js'); return file; }; caller-1.0.1/package.json000066400000000000000000000011071260164220000152310ustar00rootroot00000000000000{ "name": "caller", "version": "1.0.1", "description": "@substack's caller.js as a module", "main": "index.js", "files": [ "index.js" ], "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/totherik/caller.git" }, "keywords": [ "caller", "file", "require" ], "author": "Erik Toth ", "license": "MIT", "devDependencies": { "tape": "~2.3.2" }, "readmeFilename": "README.md", "gitHead": "15bef0805246629cc89fb71ded29e674009ffc45", "dependencies": {} } caller-1.0.1/test/000077500000000000000000000000001260164220000137235ustar00rootroot00000000000000caller-1.0.1/test/caller.js000066400000000000000000000026521260164220000155300ustar00rootroot00000000000000'use strict'; var test = require('tape'), caller = require('../'); test('caller', function (t) { t.test('determine caller', function (t) { var actual, expected; actual = caller(); expected = require.resolve('tape/lib/test'); t.equal(actual, expected); t.end(); }); t.test('determine caller at runtime', function (t) { var callee, actual, expected; callee = require('./fixtures/callee'); actual = callee(caller); expected = __filename; t.equal(actual, expected); t.end(); }); t.test('determine caller with depth', function (t) { var callee, actual, expected; callee = require('./fixtures/callee'); actual = callee(caller.bind(null, 2)); expected = require.resolve('tape/lib/test'); t.equal(actual, expected); t.end(); }); t.test('determine caller with depth cap', function (t) { var callee, actual, expected; callee = require('./fixtures/callee'); actual = callee(caller.bind(null, 99)); expected = require.resolve('tape/lib/test'); t.equal(actual, expected); t.end(); }); t.test('determine caller at initialization time', function (t) { var actual, expected; actual = require('./fixtures/init'); expected = __filename; t.equal(actual, expected); t.end(); }); }); caller-1.0.1/test/fixtures/000077500000000000000000000000001260164220000155745ustar00rootroot00000000000000caller-1.0.1/test/fixtures/callee.js000066400000000000000000000001131260164220000173520ustar00rootroot00000000000000'use strict'; module.exports = function (caller) { return caller(); };caller-1.0.1/test/fixtures/init.js000066400000000000000000000001411260164220000170710ustar00rootroot00000000000000'use strict'; var caller = require('../../'); console.log(caller()); module.exports = caller();