Gathering detailed insights and metrics for func-loc
Gathering detailed insights and metrics for func-loc
Gathering detailed insights and metrics for func-loc
Gathering detailed insights and metrics for func-loc
npm install func-loc
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
117 Stars
82 Commits
4 Forks
5 Watching
14 Branches
3 Contributors
Updated on 26 Nov 2024
TypeScript (57.93%)
JavaScript (40.67%)
Shell (1.4%)
Cumulative downloads
Total Downloads
Last day
-10.5%
607
Compared to previous day
Last week
-4.7%
3,076
Compared to previous week
Last month
15.4%
14,633
Compared to previous month
Last year
-12.2%
148,616
Compared to previous year
A simple tool that help you to retrieve the function location from its reference.
1$ npm i func-loc
1const { locate } = require('func-loc'); 2 3const fn = () => { 4 console.log('Hello there'); 5}; 6 7(async () => { 8 const result = await locate(fn); 9 console.log(result); 10 // Will result: { source: 'file://__BASE_FOLDER__/func-loc/this-file.js', line: 3, column: 12 } 11})();
locate(fn: Function)
: Will retrieve the location of a given function, and will cache it so that the second call will be faster.The result of the call will be an object that contains these attributes:
source
: The source file.line
: The line where the function was defined.column
: The exact column where the function was declared.Internally, this function will open an inspector session. So it is always a good idea to call the disconnect
method when you are done.
disconnect()
: will disconnect
the inspector session, cleans the cache and delete temporary created objects from the global object.This library can also locate the original code using source-map:
Lets say that you have a typescript file containing:
1// File: `module.ts` 2export function inner() { 3 const fn3 = () => {}; 4 return fn3; 5}
Transpiling this file using typescript compiler will generate a source map file like:
1{ 2 "origin": { 3 "path": "/BASE_FOLDER/module.js", 4 "column": 24, 5 "line": 5, 6 "source": "file:///BASE_FOLDER/module.js" 7 }, 8 "line": 3, 9 "column": 14, 10 "path": "/BASE_FOLDER/module.ts", 11 "source": "file:///BASE_FOLDER/module.ts" 12}
And a javascript file containing:
1"use strict"; 2exports.__esModule = true; 3// File: `module.ts` 4function inner() { 5 var fn3 = function () { }; 6 return fn3; 7} 8exports.inner = inner; 9//# sourceMappingURL=module.js.map
If you execute the following code
1const { locate } = require('func-loc'); 2const { inner } = require('../__tests__/assets/module'); 3 4(async () => { 5 const loc = await locate(inner(), { sourceMap: true }); 6 console.log(loc); 7})();
It will output the line of the inner function f3 of the file module.ts
:
1{ 2 "origin": { 3 "path": "/BASE_FOLDER/module.js", 4 "column": 24, 5 "line": 5, 6 "source": "file:///BASE_FOLDER/module.js" 7 }, 8 "line": 3, 9 "column": 14, 10 "path": "/BASE_FOLDER/module.ts", 11 "source": "file:///BASE_FOLDER/module.ts" 12}
MIT © Mohamed IDRISSI
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More