pareto-core-dev 0.12.6 → 0.12.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ export type Source_Location = {
2
+ readonly 'document resource identifier': string;
3
+ readonly 'line': number;
4
+ readonly 'column': number;
5
+ };
6
+ /**
7
+ * provides the source location (filepath and line number) of the source code file where this function is called,
8
+ * or if the depth is bigger than 0, the source location of the function at that stack depth
9
+ * @param depth
10
+ * @returns
11
+ */
12
+ export default function get_location_info(depth: number): Source_Location;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = get_location_info;
4
+ /**
5
+ * provides the source location (filepath and line number) of the source code file where this function is called,
6
+ * or if the depth is bigger than 0, the source location of the function at that stack depth
7
+ * @param depth
8
+ * @returns
9
+ */
10
+ function get_location_info(depth) {
11
+ //we create an error, not to be thrown but to be disected for its stack
12
+ const e = new Error(); //don't move this statement to another function, it will change the depth of its stack
13
+ function get_line(e, depth) {
14
+ if (e.stack === undefined) {
15
+ throw new Error(`NO STACK INFO`);
16
+ }
17
+ const line = e.stack.split("\n")[depth + 2]; //get the right line from the stack (the first two lines are "Error" and this function call)
18
+ const regex = /\((.*)\)$/; //matches the content inside parentheses at the end of a line (the file path with line and column)
19
+ const match = regex.exec(line);
20
+ if (match !== null) {
21
+ //we have a match
22
+ return match[1];
23
+ }
24
+ const begin = " at /";
25
+ if (line.startsWith(begin)) {
26
+ return line.substring(begin.length - 1);
27
+ }
28
+ throw new Error(`COULD NOT PARSE STACK LINE: ${line}`);
29
+ }
30
+ const line = get_line(e, depth);
31
+ const split = line.split(":");
32
+ if (split.length !== 3) {
33
+ throw new Error(`UNEXPECTED LOCATION FORMAT (CHECK THE DEPTH PARAMETER): ${line} (Expected 'file:line:column')`);
34
+ }
35
+ return {
36
+ 'document resource identifier': split[0],
37
+ 'line': Number(split[1]),
38
+ 'column': Number(split[2]),
39
+ };
40
+ }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.implement_me = implement_me;
4
- const get_location_info_1 = require("pareto-core/dist/__internals/get_location_info");
7
+ const get_location_info_1 = __importDefault(require("../get_location_info"));
5
8
  /**
6
9
  * use this function as a placeholder when you want to compile but have not fully developed all functionality yet.
7
10
  *
@@ -10,6 +13,6 @@ const get_location_info_1 = require("pareto-core/dist/__internals/get_location_i
10
13
  * @param message the string to be printed to stderr
11
14
  */
12
15
  function implement_me(marker) {
13
- const location = (0, get_location_info_1.$$)(1);
16
+ const location = (0, get_location_info_1.default)(1);
14
17
  throw new Error(`IMPLEMENT ME ${marker ? `: '${marker}'` : ''}@ ${location['document resource identifier']}:${location.line}:${location.column}`);
15
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pareto-core-dev",
3
- "version": "0.12.6",
3
+ "version": "0.12.7",
4
4
  "license": "ISC",
5
5
  "description": "a pareto package that contains functions that are useful during development",
6
6
  "author": "Corno",
@@ -24,6 +24,6 @@
24
24
  "url": "git+https://github.com/corno/pareto-core-dev.git"
25
25
  },
26
26
  "dependencies": {
27
- "pareto-core": "^0.1.25"
27
+ "pareto-core": "^0.1.30"
28
28
  }
29
29
  }