{"id":22129464,"url":"https://github.com/midrissi/func-loc","last_synced_at":"2025-09-11T00:33:45.486Z","repository":{"id":34295393,"uuid":"175309226","full_name":"midrissi/func-loc","owner":"midrissi","description":"A simple tool that helps you to retrieve the function location from its reference.","archived":false,"fork":false,"pushed_at":"2024-12-15T13:34:42.000Z","size":2286,"stargazers_count":117,"open_issues_count":11,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-09T17:03:28.529Z","etag":null,"topics":["function","inspector","javascript","location","nodejs","reference"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/midrissi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-12T23:02:06.000Z","updated_at":"2025-03-25T01:56:08.000Z","dependencies_parsed_at":"2024-12-31T16:46:55.087Z","dependency_job_id":null,"html_url":"https://github.com/midrissi/func-loc","commit_stats":{"total_commits":73,"total_committers":4,"mean_commits":18.25,"dds":"0.12328767123287676","last_synced_commit":"f41303e7349340fbbb54c6e8e4728fcfd7c4e8b1"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midrissi%2Ffunc-loc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midrissi%2Ffunc-loc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midrissi%2Ffunc-loc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/midrissi%2Ffunc-loc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/midrissi","download_url":"https://codeload.github.com/midrissi/func-loc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582902,"owners_count":22095518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["function","inspector","javascript","location","nodejs","reference"],"created_at":"2024-12-01T17:59:58.837Z","updated_at":"2025-05-16T18:04:00.708Z","avatar_url":"https://github.com/midrissi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# func-loc\n\n[![Coveralls][coverage-badge]][coverage]\n[![Build Status][travis-badge]][travis]\n[![Codacy Badge][codacy-badge]][codacy]\n![David](https://img.shields.io/david/midrissi/func-loc)\n![David](https://img.shields.io/david/dev/midrissi/func-loc)\n![node](https://img.shields.io/node/v/func-loc)\n![npm](https://img.shields.io/npm/dm/func-loc)\n![npm](https://img.shields.io/npm/v/func-loc)\n![GitHub issues](https://img.shields.io/github/issues/midrissi/func-loc)\n![GitHub top language](https://img.shields.io/github/languages/top/midrissi/func-loc)\n![GitHub contributors](https://img.shields.io/github/contributors/midrissi/func-loc)\n[![npm version][npm-badge]][npm]\n[![vulnerabilities][vulnerabilities-badge]][vulnerabilities]\n[![PRs Welcome][prs-badge]][prs]\n[![MIT License][license-badge]][license]\n\nA simple tool that help you to retrieve the function location from its reference.\n\n## How to install\n\n```bash\n$ npm i func-loc\n```\n\n## How to use\n\n```javascript\nconst { locate } = require('func-loc');\n\nconst fn = () =\u003e {\n  console.log('Hello there');\n};\n\n(async () =\u003e {\n  const result = await locate(fn);\n  console.log(result);\n  // Will result: { source: 'file://__BASE_FOLDER__/func-loc/this-file.js', line: 3, column: 12 }\n})();\n```\n\n## APIs\n\n1.  `locate(fn: Function)`: Will retrieve the location of a given function, and will cache it so that the second call will be faster.\n\nThe result of the call will be an object that contains these attributes:\n\n-   `source`: The source file.\n-   `line`: The line where the function was defined.\n-   `column`: The exact column where the function was declared.\n\nInternally, this function will open an [inspector](https://nodejs.org/api/inspector.html) session. So it is always a good idea to call the `disconnect` method when you are done.\n\n2.  `disconnect()` : will [`disconnect`](https://nodejs.org/api/inspector.html#inspector_session_disconnect) the [inspector](https://nodejs.org/api/inspector.html) [session](https://nodejs.org/api/inspector.html#inspector_class_inspector_session), cleans the cache and delete temporary created objects from the global object. \n\n## Using Source Maps\n\nThis library can also locate the original code using [source-map](https://developer.mozilla.org/en-US/docs/Tools/Debugger/How_to/Use_a_source_map):\n\nLets say that you have a typescript file containing:\n\n```typescript\n// File: `module.ts`\nexport function inner() {\n  const fn3 = () =\u003e {};\n  return fn3;\n}\n```\n\nTranspiling this file using [typescript compiler](https://www.typescriptlang.org/) will generate a source map file like:\n\n```json\n{\n  \"origin\": {\n    \"path\": \"/BASE_FOLDER/module.js\",\n    \"column\": 24,\n    \"line\": 5,\n    \"source\": \"file:///BASE_FOLDER/module.js\"\n  },\n  \"line\": 3,\n  \"column\": 14,\n  \"path\": \"/BASE_FOLDER/module.ts\",\n  \"source\": \"file:///BASE_FOLDER/module.ts\"\n}\n```\n\nAnd a javascript file containing:\n\n```javascript\n\"use strict\";\nexports.__esModule = true;\n// File: `module.ts`\nfunction inner() {\n    var fn3 = function () { };\n    return fn3;\n}\nexports.inner = inner;\n//# sourceMappingURL=module.js.map\n```\n\nIf you execute the following code\n\n```javascript\nconst { locate } = require('func-loc');\nconst { inner } = require('../__tests__/assets/module');\n\n(async () =\u003e {\n  const loc = await locate(inner(), { sourceMap: true });\n  console.log(loc);\n})();\n```\n\nIt will output the line of the inner function f3 of the file `module.ts`:\n\n```json\n{\n  \"origin\": {\n    \"path\": \"/BASE_FOLDER/module.js\",\n    \"column\": 24,\n    \"line\": 5,\n    \"source\": \"file:///BASE_FOLDER/module.js\"\n  },\n  \"line\": 3,\n  \"column\": 14,\n  \"path\": \"/BASE_FOLDER/module.ts\",\n  \"source\": \"file:///BASE_FOLDER/module.ts\"\n}\n```\n\n## License\n\nMIT © Mohamed IDRISSI\n\n[coverage-badge]: https://coveralls.io/repos/github/midrissi/func-loc/badge.svg?branch=master\u0026service=github\n[coverage]: https://coveralls.io/github/midrissi/func-loc?branch=master\n[travis-badge]: https://travis-ci.org/midrissi/func-loc.svg?branch=master\n[travis]: https://travis-ci.org/midrissi/func-loc\n[codacy-badge]: https://api.codacy.com/project/badge/Grade/fd744ba304a244629886dfb19c85af40\n[codacy]: https://www.codacy.com/app/midrissi/func-loc?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=midrissi/func-loc\u0026amp;utm_campaign=Badge_Grade\n[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg\n[prs]: http://makeapullrequest.com\n[npm-badge]: https://badge.fury.io/js/func-loc.svg\n[npm]: https://www.npmjs.com/package/func-loc\n[vulnerabilities-badge]: https://snyk.io/test/github/midrissi/func-loc/badge.svg?targetFile=package.json\n[vulnerabilities]: https://snyk.io/test/github/midrissi/func-loc?targetFile=package.json\n[license-badge]: https://img.shields.io/badge/license-MIT-blue.svg\n[license]: https://github.com/midrissi/func-loc/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidrissi%2Ffunc-loc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmidrissi%2Ffunc-loc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmidrissi%2Ffunc-loc/lists"}