All Projects â†’ midrissi â†’ Func Loc

midrissi / Func Loc

Licence: mit
A simple tool that helps you to retrieve the function location from its reference.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Func Loc

React Hook Mighty Mouse
🐭 React hook that tracks mouse events on selected element - zero dependencies
Stars: ✭ 75 (-24.24%)
Mutual labels:  location
Location
Smartphone navigation positionning, fusion GPS and IMU sensors.
Stars: ✭ 87 (-12.12%)
Mutual labels:  location
Shellfuncs
Python API to execute shell functions as they would be Python functions
Stars: ✭ 96 (-3.03%)
Mutual labels:  function
Unix Text Commands
Unix Text Processing Command Reference
Stars: ✭ 78 (-21.21%)
Mutual labels:  reference
Kotlin Reference Chinese
Kotlin 官方文档(参考部分)中文版
Stars: ✭ 85 (-14.14%)
Mutual labels:  reference
Leaflet Gps
Simple leaflet control plugin for tracking gps position
Stars: ✭ 90 (-9.09%)
Mutual labels:  location
Dodo
React Native location sdk based on amap.
Stars: ✭ 72 (-27.27%)
Mutual labels:  location
Uinspector
A UI inspector to traverse a view hierarchy on Android
Stars: ✭ 97 (-2.02%)
Mutual labels:  inspector
Geo Location
Web component element for the Geolocation API
Stars: ✭ 86 (-13.13%)
Mutual labels:  location
Python Cheatsheet
Basic Cheat Sheet for Python (PDF, Markdown and Jupyter Notebook)
Stars: ✭ 1,334 (+1247.47%)
Mutual labels:  reference
Locationhelper
Android library project that helps you to track user location and manage the updates.
Stars: ✭ 79 (-20.2%)
Mutual labels:  location
Wazuh Documentation
Wazuh - Project documentation
Stars: ✭ 82 (-17.17%)
Mutual labels:  reference
Phpgeo
Simple Yet Powerful Geo Library for PHP
Stars: ✭ 1,306 (+1219.19%)
Mutual labels:  location
P5.geolocation
a geolocation and geofencing library for p5.js
Stars: ✭ 75 (-24.24%)
Mutual labels:  location
Whereareyou
Real time location tracker using Android App & Firebase with Mapbox
Stars: ✭ 96 (-3.03%)
Mutual labels:  location
Checklist Tools Website
🍿 The perfect Checklist Website for meticulous developers.
Stars: ✭ 73 (-26.26%)
Mutual labels:  reference
Amr Tutorial
Abstract Meaning Representation (AMR) tutorial slides
Stars: ✭ 89 (-10.1%)
Mutual labels:  reference
Locokit
Location, motion, and activity recording framework for iOS
Stars: ✭ 1,353 (+1266.67%)
Mutual labels:  location
Reference En
Editable source for the Arduino Reference
Stars: ✭ 97 (-2.02%)
Mutual labels:  reference
Library
A collection of various articles and books I've are worth revisiting.
Stars: ✭ 93 (-6.06%)
Mutual labels:  reference

func-loc

Coveralls Build Status Codacy Badge David David node npm npm GitHub issues GitHub top language GitHub contributors npm version vulnerabilities PRs Welcome MIT License

A simple tool that help you to retrieve the function location from its reference.

How to install

$ npm i func-loc

How to use

const { locate } = require('func-loc');

const fn = () => {
  console.log('Hello there');
};

(async () => {
  const result = await locate(fn);
  console.log(result);
  // Will result: { source: 'file://__BASE_FOLDER__/func-loc/this-file.js', line: 3, column: 12 }
})();

APIs

  1. 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.

  1. disconnect() : will disconnect the inspector session, cleans the cache and delete temporary created objects from the global object.

Using Source Maps

This library can also locate the original code using source-map:

Lets say that you have a typescript file containing:

// File: `module.ts`
export function inner() {
  const fn3 = () => {};
  return fn3;
}

Transpiling this file using typescript compiler will generate a source map file like:

{
  "origin": {
    "path": "/BASE_FOLDER/module.js",
    "column": 24,
    "line": 5,
    "source": "file:///BASE_FOLDER/module.js"
  },
  "line": 3,
  "column": 14,
  "path": "/BASE_FOLDER/module.ts",
  "source": "file:///BASE_FOLDER/module.ts"
}

And a javascript file containing:

"use strict";
exports.__esModule = true;
// File: `module.ts`
function inner() {
    var fn3 = function () { };
    return fn3;
}
exports.inner = inner;
//# sourceMappingURL=module.js.map

If you execute the following code

const { locate } = require('func-loc');
const { inner } = require('../__tests__/assets/module');

(async () => {
  const loc = await locate(inner(), { sourceMap: true });
  console.log(loc);
})();

It will output the line of the inner function f3 of the file module.ts:

{
  "origin": {
    "path": "/BASE_FOLDER/module.js",
    "column": 24,
    "line": 5,
    "source": "file:///BASE_FOLDER/module.js"
  },
  "line": 3,
  "column": 14,
  "path": "/BASE_FOLDER/module.ts",
  "source": "file:///BASE_FOLDER/module.ts"
}

License

MIT Š Mohamed IDRISSI

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].